From 881f0550ee1eb9e70917271a4720b9c105be8068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Wed, 15 Jul 2020 20:59:20 +0200 Subject: [PATCH] Add (alias ...), (mode ...) fields to (copy_files ...) stanza MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- src/dune/dune_file.ml | 32 +++++++++++++++++++++++++------- src/dune/dune_file.mli | 18 ++++++++++-------- src/dune/inline_tests.ml | 4 +++- src/dune/simple_rules.ml | 28 ++++++++++++++++++---------- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/dune/dune_file.ml b/src/dune/dune_file.ml index 46ef8489a574..e6bf872bab20 100644 --- a/src/dune/dune_file.ml +++ b/src/dune/dune_file.ml @@ -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 @@ -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 diff --git a/src/dune/dune_file.mli b/src/dune/dune_file.mli index 40cdd966e700..e5d3cf8c4858 100644 --- a/src/dune/dune_file.mli +++ b/src/dune/dune_file.mli @@ -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 @@ -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 diff --git a/src/dune/inline_tests.ml b/src/dune/inline_tests.ml index ac6609cdb402..850953d657ad 100644 --- a/src/dune/inline_tests.ml +++ b/src/dune/inline_tests.ml @@ -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 diff --git a/src/dune/simple_rules.ml b/src/dune/simple_rules.ml index 79bef24b896c..4b5e9d50bef3 100644 --- a/src/dune/simple_rules.ml +++ b/src/dune/simple_rules.ml @@ -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