Skip to content

Commit

Permalink
Add (alias ...), (mode ...) fields to (copy_files ...) stanza
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
  • Loading branch information
nojb committed Jul 15, 2020
1 parent 2a10ee5 commit 881f055
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
32 changes: 25 additions & 7 deletions src/dune/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1720,11 +1720,31 @@ end
module Copy_files = struct
type t =
{ add_line_directive : bool
; alias : Alias.Name.t option
; mode : Rule.Mode.t
; glob : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}

let decode = String_with_vars.decode
let long_form =
let+ alias = field_o "alias" Alias.Name.decode
and+ mode = field "mode" ~default:Rule.Mode.Standard Rule.Mode.decode
and+ glob = field "glob" String_with_vars.decode
and+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
{ add_line_directive = false; alias; mode; glob; syntax_version }

let decode =
peek_exn >>= function
| List _ -> Dune_lang.Syntax.since Stanza.syntax (2, 7) >>> fields long_form
| _ ->
let+ glob = String_with_vars.decode
and+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
{ add_line_directive = false
; alias = None
; mode = Standard
; glob
; syntax_version
}
end

module Documentation = struct
Expand Down Expand Up @@ -1857,13 +1877,11 @@ module Stanzas = struct
, let+ x = Alias_conf.decode in
[ Alias x ] )
; ( "copy_files"
, let+ glob = Copy_files.decode
and+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
[ Copy_files { add_line_directive = false; glob; syntax_version } ] )
, let+ x = Copy_files.decode in
[ Copy_files x ] )
; ( "copy_files#"
, let+ glob = Copy_files.decode
and+ syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax in
[ Copy_files { add_line_directive = true; glob; syntax_version } ] )
, let+ x = Copy_files.decode in
[ Copy_files { x with add_line_directive = true } ] )
; ( "include"
, let+ loc = loc
and+ fn = relative_file in
Expand Down
18 changes: 10 additions & 8 deletions src/dune/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ module Menhir : sig
type Stanza.t += T of t
end

module Copy_files : sig
type t =
{ add_line_directive : bool
; alias : Alias.Name.t option
; mode : Rule.Mode.t
; glob : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}
end

module Rule : sig
type t =
{ targets : String_with_vars.t Targets.t
Expand All @@ -279,14 +289,6 @@ module Alias_conf : sig
}
end

module Copy_files : sig
type t =
{ add_line_directive : bool
; glob : String_with_vars.t
; syntax_version : Dune_lang.Syntax.Version.t
}
end

module Documentation : sig
type t =
{ loc : Loc.t
Expand Down
4 changes: 3 additions & 1 deletion src/dune/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ include Sub_system.Register_end_point (struct
let obj_dir =
Obj_dir.make_exe ~dir:inline_test_dir ~name:inline_test_name
in
let name = sprintf "inline_test_runner_%s" (Lib_name.Local.to_string (snd lib.name)) in
let name =
sprintf "inline_test_runner_%s" (Lib_name.Local.to_string (snd lib.name))
in
let main_module =
let name = Module_name.of_string name in
let src_dir = Path.build inline_test_dir in
Expand Down
28 changes: 18 additions & 10 deletions src/dune/simple_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,24 @@ let copy_files sctx ~dir ~expander ~src_dir (def : Copy_files.t) =
Build_system.eval_pred
(File_selector.create ~dir:(Path.build src_in_build) pred)
in
Path.Set.map files ~f:(fun file_src ->
let basename = Path.basename file_src in
let file_dst = Path.Build.relative dir basename in
SC.add_rule sctx ~loc ~dir
(( if def.add_line_directive then
Build.copy_and_add_line_directive
else
Build.copy )
~src:file_src ~dst:file_dst);
Path.build file_dst)
let targets =
Path.Set.map files ~f:(fun file_src ->
let basename = Path.basename file_src in
let file_dst = Path.Build.relative dir basename in
SC.add_rule sctx ~loc ~dir ~mode:def.mode
(( if def.add_line_directive then
Build.copy_and_add_line_directive
else
Build.copy )
~src:file_src ~dst:file_dst);
Path.build file_dst)
in
Option.iter
~f:(fun alias ->
let alias = Alias.make alias ~dir in
Rules.Produce.Alias.add_deps alias targets)
def.alias;
targets

let alias sctx ?extra_bindings ~dir ~expander (alias_conf : Alias_conf.t) =
let alias = Alias.make ~dir alias_conf.name in
Expand Down

0 comments on commit 881f055

Please sign in to comment.