From dbe1985cb30ca7c5bf4c3d3f60c2f89dc4ed6432 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 27 Aug 2019 17:40:42 +0700 Subject: [PATCH 1/2] Merge branches that execute same code Signed-off-by: Rudi Grinberg --- src/dune/build_system.ml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/dune/build_system.ml b/src/dune/build_system.ml index 69bd1d60f83..791d8cf4637 100644 --- a/src/dune/build_system.ml +++ b/src/dune/build_system.ml @@ -1659,14 +1659,12 @@ let package_deps pkg files = (* if this file isn't in the build dir, it doesnt belong to any packages and it doesn't have dependencies that do *) acc - | Some fn -> ( + | Some fn -> let pkgs = Fdecl.get t.packages fn in - if Package.Name.Set.is_empty pkgs then - loop_deps fn acc - else if Package.Name.Set.mem pkgs pkg then + if Package.Name.Set.is_empty pkgs || Package.Name.Set.mem pkgs pkg then loop_deps fn acc else - Package.Name.Set.union acc pkgs) + Package.Name.Set.union acc pkgs and loop_deps fn acc = match Path.Build.Table.find t.files fn with | None -> acc From 76491485b74b60bb2cdc0fa1a984b5bbfeca0066 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 27 Aug 2019 18:21:32 +0700 Subject: [PATCH 2/2] Add a --disable-promotion option This option will disable all promotion to the source directory. This allows one to keep the source directory read only. Fix #2568 Signed-off-by: Rudi Grinberg --- CHANGES.md | 4 +++ bin/common.ml | 30 ++++++++++++------- src/dune/build_system.ml | 9 +++--- src/dune/clflags.ml | 8 ++++- src/dune/clflags.mli | 10 +++++-- src/dune/promotion.ml | 7 +++-- test/blackbox-tests/dune.inc | 10 +++++++ .../test-cases/disable-promotion/dune | 3 ++ .../test-cases/disable-promotion/dune-project | 4 +++ .../test-cases/disable-promotion/run.t | 12 ++++++++ 10 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 test/blackbox-tests/test-cases/disable-promotion/dune create mode 100644 test/blackbox-tests/test-cases/disable-promotion/dune-project create mode 100644 test/blackbox-tests/test-cases/disable-promotion/run.t diff --git a/CHANGES.md b/CHANGES.md index 30f0044bf75..71f9cb3e26e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -105,6 +105,10 @@ - Remove git integration from `$ dune upgrade` (#2565, @rgrinberg) +- Add a `--disable-promotion` to disable all modification to the source + directory. There's also a corresponding `DUNE_DISABLE_PROMOTION` environment + variable. (#2588, fix #2568, @rgrinberg) + 1.11.3 (23/08/2019) ------------------- diff --git a/bin/common.ml b/bin/common.ml index 20b695393cf..497b1bacd0c 100644 --- a/bin/common.ml +++ b/bin/common.ml @@ -27,7 +27,7 @@ type t = ; capture_outputs : bool ; x : string option ; diff_command : string option - ; auto_promote : bool + ; promote : Clflags.Promote.t option ; force : bool ; ignore_promoted_rules : bool ; build_dir : string @@ -76,7 +76,7 @@ let set_common_other c ~targets = Clflags.debug_backtraces := c.debug_backtraces; Clflags.capture_outputs := c.capture_outputs; Clflags.diff_command := c.diff_command; - Clflags.auto_promote := c.auto_promote; + Clflags.promote := c.promote; Clflags.force := c.force; Clflags.watch := c.watch; Clflags.no_print_directory := c.no_print_directory; @@ -405,13 +405,23 @@ let term = & opt (some path) None & info [ "workspace" ] ~docs ~docv:"FILE" ~doc ~env:(Arg.env_var ~doc "DUNE_WORKSPACE")) - and+ auto_promote = - Arg.( - value & flag - & info [ "auto-promote" ] ~docs - ~doc: - "Automatically promote files. This is similar to running\n\ - \ $(b,dune promote) after the build.") + and+ promote = + one_of + (let+ auto = + Arg.( + value & flag + & info [ "auto-promote" ] ~docs + ~doc: + "Automatically promote files. This is similar to running\n\ + \ $(b,dune promote) after the build.") + in + Option.some_if auto Clflags.Promote.Automatically) + (let+ disable = + let doc = "Disable all promotion rules" in + let env = Arg.env_var ~doc "DUNE_DISABLE_PROMOTION" in + Arg.(value & flag & info [ "disable-promotion" ] ~docs ~env ~doc) + in + Option.some_if disable Clflags.Promote.Never) and+ force = Arg.( value & flag @@ -516,7 +526,7 @@ let term = ; target_prefix = String.concat ~sep:"" (List.map root.to_cwd ~f:(sprintf "%s/")) ; diff_command - ; auto_promote + ; promote ; force ; ignore_promoted_rules ; only_packages = diff --git a/src/dune/build_system.ml b/src/dune/build_system.ml index 791d8cf4637..3927e595c06 100644 --- a/src/dune/build_system.ml +++ b/src/dune/build_system.ml @@ -1465,12 +1465,11 @@ end = struct Fiber.return () in let+ () = - match mode with - | Standard - |Fallback - |Ignore_source_files -> + match (mode, !Clflags.promote) with + | (Standard | Fallback | Ignore_source_files), _ + |Promote _, Some Never -> Fiber.return () - | Promote { lifetime; into; only } -> + | Promote { lifetime; into; only }, (Some Automatically | None) -> Fiber.sequential_iter targets_as_list ~f:(fun path -> let consider_for_promotion = match only with diff --git a/src/dune/clflags.ml b/src/dune/clflags.ml index 286251b462b..d05dff6db88 100644 --- a/src/dune/clflags.ml +++ b/src/dune/clflags.ml @@ -1,3 +1,9 @@ +module Promote = struct + type t = + | Automatically + | Never +end + let debug_findlib = ref false let debug_dep_path = ref false @@ -10,7 +16,7 @@ let debug_backtraces = ref false let diff_command = ref None -let auto_promote = ref false +let promote = ref None let force = ref false diff --git a/src/dune/clflags.mli b/src/dune/clflags.mli index a8001db5068..d443d5c073a 100644 --- a/src/dune/clflags.mli +++ b/src/dune/clflags.mli @@ -18,8 +18,14 @@ val debug_backtraces : bool ref (** Command to use to diff things *) val diff_command : string option ref -(** Automatically promote files *) -val auto_promote : bool ref +module Promote : sig + type t = + | Automatically + | Never +end + +(** explicit promotion mode is set *) +val promote : Promote.t option ref (** Force re-running actions associated to aliases *) val force : bool ref diff --git a/src/dune/promotion.ml b/src/dune/promotion.ml index d27b07a4405..f6bacb1835e 100644 --- a/src/dune/promotion.ml +++ b/src/dune/promotion.ml @@ -148,9 +148,10 @@ let do_promote db files_to_promote = let finalize () = let db = - if !Clflags.auto_promote then - do_promote !File.db All - else + match !Clflags.promote with + | Some Automatically -> do_promote !File.db All + | Some Never + |None -> !File.db in dump_db db diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 01d38c5458b..68e79e93084 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -231,6 +231,14 @@ test-cases/dir-target-dep (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name disable-promotion) + (deps (package dune) (source_tree test-cases/disable-promotion)) + (action + (chdir + test-cases/disable-promotion + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name double-echo) (deps (package dune) (source_tree test-cases/double-echo)) @@ -1742,6 +1750,7 @@ (alias deps-conf-vars) (alias dialects) (alias dir-target-dep) + (alias disable-promotion) (alias double-echo) (alias dune-build-dir-exec-1101) (alias dune-init) @@ -1946,6 +1955,7 @@ (alias deps-conf-vars) (alias dialects) (alias dir-target-dep) + (alias disable-promotion) (alias double-echo) (alias dune-build-dir-exec-1101) (alias dune-init) diff --git a/test/blackbox-tests/test-cases/disable-promotion/dune b/test/blackbox-tests/test-cases/disable-promotion/dune new file mode 100644 index 00000000000..0c7c1d5bd3d --- /dev/null +++ b/test/blackbox-tests/test-cases/disable-promotion/dune @@ -0,0 +1,3 @@ +(library + (name foo) + (public_name foo)) diff --git a/test/blackbox-tests/test-cases/disable-promotion/dune-project b/test/blackbox-tests/test-cases/disable-promotion/dune-project new file mode 100644 index 00000000000..7f1979c9176 --- /dev/null +++ b/test/blackbox-tests/test-cases/disable-promotion/dune-project @@ -0,0 +1,4 @@ +(lang dune 1.11) + +(package + (name foo)) diff --git a/test/blackbox-tests/test-cases/disable-promotion/run.t b/test/blackbox-tests/test-cases/disable-promotion/run.t new file mode 100644 index 00000000000..f43105b16da --- /dev/null +++ b/test/blackbox-tests/test-cases/disable-promotion/run.t @@ -0,0 +1,12 @@ +This tests shows how all promotion to the source dir may be disabled. This +includes both .install and .merlin files + + $ dune build --disable-promotion @all +.merlin is absent + $ test -f .merlin && echo ".merlin exists" + [1] + +now we build without the option and see that it is present: + $ dune build @all + $ test -f .merlin && echo ".merlin exists" + .merlin exists