2525
2626(* CR-someday amokhov: Add more interesting tags, for example, to allow the user
2727 to specify file patterns like "*.ml" for directory targets. *)
28- module Tag = struct
28+ module Kind = struct
2929 type t =
30- | None
31- | Star
30+ | File
31+ | Directory
3232end
3333
3434module Static = struct
3535 type 'path t =
36- { targets : 'path list
36+ { targets : ( 'path * Kind .t ) list
3737 ; multiplicity : Multiplicity .t
3838 }
3939end
@@ -42,39 +42,44 @@ type 'a t =
4242 | Static of 'a Static .t
4343 | Infer
4444
45- let decode_static =
45+ let decode_target ~allow_directory_targets =
46+ let open Dune_lang.Decoder in
47+ let file =
48+ let + file = String_with_vars. decode in
49+ (file, Kind. File )
50+ in
51+ let dir =
52+ let + dir = sum ~force_parens: true [ (" dir" , String_with_vars. decode) ] in
53+ if not allow_directory_targets then
54+ User_error. raise ~loc: (String_with_vars. loc dir)
55+ [ Pp. text " Directory targets require the 'directory-targets' extension"
56+ ];
57+
58+ (dir, Kind. Directory )
59+ in
60+ file < |> dir
61+
62+ let decode_static ~allow_directory_targets =
4663 let open Dune_lang.Decoder in
4764 let + syntax_version = Dune_lang.Syntax. get_exn Stanza. syntax
48- and + targets = repeat String_with_vars. decode in
65+ and + targets = repeat (decode_target ~allow_directory_targets ) in
4966 if syntax_version < (1 , 3 ) then
50- List. iter targets ~f: (fun target ->
67+ List. iter targets ~f: (fun ( target , ( _ : Kind.t )) ->
5168 if String_with_vars. has_pforms target then
5269 Dune_lang.Syntax.Error. since
5370 (String_with_vars. loc target)
5471 Stanza. syntax (1 , 3 ) ~what: " Using variables in the targets field" );
5572 Static { targets; multiplicity = Multiple }
5673
57- let decode_one_static =
74+ let decode_one_static ~ allow_directory_targets =
5875 let open Dune_lang.Decoder in
5976 let + () = Dune_lang.Syntax. since Stanza. syntax (1 , 11 )
60- and + target = String_with_vars. decode in
77+ and + target = decode_target ~allow_directory_targets in
6178 Static { targets = [ target ]; multiplicity = One }
6279
63- let field =
80+ let field ~ allow_directory_targets =
6481 let open Dune_lang.Decoder in
6582 fields_mutually_exclusive ~default: Infer
66- [ (" targets" , decode_static); (" target" , decode_one_static) ]
67-
68- let has_target_directory = function
69- | Infer -> false
70- | Static { targets; _ } ->
71- List. exists targets ~f: (fun target ->
72- match String_with_vars. last_text_part target with
73- | None -> false
74- | Some part -> Option. is_some (String. drop_suffix ~suffix: " /*" part))
75-
76- let untag = function
77- | Infer -> Infer
78- | Static { targets; multiplicity } ->
79- let targets = List. map targets ~f: fst in
80- Static { targets; multiplicity }
83+ [ (" targets" , decode_static ~allow_directory_targets )
84+ ; (" target" , decode_one_static ~allow_directory_targets )
85+ ]
0 commit comments