diff --git a/CHANGES.md b/CHANGES.md index a0e930bc216..be22efaab3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -99,6 +99,8 @@ - Add (dialect ...) stanza (@nojb, #2404) +- Add a `--context` argument to `dune install/uninstall` (@diml, #2412) + 1.10.0 (04/06/2019) ------------------- diff --git a/bin/install_uninstall.ml b/bin/install_uninstall.ml index 61d89424c54..f04c1276154 100644 --- a/bin/install_uninstall.ml +++ b/bin/install_uninstall.ml @@ -282,12 +282,23 @@ let install_uninstall ~what = ) and+ pkgs = Arg.(value & pos_all package_name [] name_) + and+ context = + Arg.(value + & opt (some string) None + & info ["context"] ~docv:"CONTEXT" + ~doc:"Select context to install from. By default, \ + install files from all defined contexts.") in Common.set_common common ~targets:[]; let log = Log.create common in Scheduler.go ~log ~common (fun () -> let open Fiber.O in let* workspace = Import.Main.scan_workspace ~log common in + let contexts = + match context with + | None -> workspace.contexts + | Some name -> [Import.Main.find_context_exn workspace ~name] + in let pkgs = match pkgs with | [] -> Package.Name.Map.keys workspace.conf.packages @@ -296,7 +307,7 @@ let install_uninstall ~what = let install_files, missing_install_files = List.concat_map pkgs ~f:(fun pkg -> let fn = resolve_package_install workspace pkg in - List.map workspace.contexts ~f:(fun ctx -> + List.map contexts ~f:(fun ctx -> let fn = Path.append_source (Path.build ctx.Context.build_dir) fn in if Path.exists fn then Left (ctx, (pkg, fn)) @@ -313,7 +324,7 @@ let install_uninstall ~what = ~hints:[ Pp.text "try running: dune build @install" ] end; (match - workspace.contexts, + contexts, prefix_from_command_line, libdir_from_command_line with diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index d56406ecee5..8ed2245437e 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -889,6 +889,14 @@ test-cases/install-libdir (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name install-multiple-contexts) + (deps (package dune) (source_tree test-cases/install-multiple-contexts)) + (action + (chdir + test-cases/install-multiple-contexts + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name install-partial-package) (deps (package dune) (source_tree test-cases/install-partial-package)) @@ -1734,6 +1742,7 @@ (alias inline_tests) (alias install-dry-run) (alias install-libdir) + (alias install-multiple-contexts) (alias install-partial-package) (alias install-rule-order) (alias install-with-var) @@ -1923,6 +1932,7 @@ (alias include-loop) (alias include-qualified) (alias inline_tests) + (alias install-multiple-contexts) (alias install-partial-package) (alias install-rule-order) (alias install-with-var) diff --git a/test/blackbox-tests/test-cases/install-multiple-contexts/run.t b/test/blackbox-tests/test-cases/install-multiple-contexts/run.t new file mode 100644 index 00000000000..11cca07ddad --- /dev/null +++ b/test/blackbox-tests/test-cases/install-multiple-contexts/run.t @@ -0,0 +1,44 @@ +Test installation when multiple contexts are defined + + $ cat > dune-workspace < (lang dune 1.11) + > (context (default (name a))) + > (context (default (name b))) + > EOF + + $ cat > dune-project < (lang dune 1.11) + > (package (name a)) + > EOF + + $ cat > dune < (rule (with-stdout-to hello (echo "Hello, world!"))) + > (install (section share) (files hello)) + > EOF + + $ dune build @install + +Cannot install into a specific prefix with multiple contexts defined: + + $ dune install --prefix _install + Error: Cannot specify --prefix or --libdir when installing into multiple + contexts! + [1] + +One must pass a --context argument: + + $ dune install --prefix _install/a --context a + Installing _install/a/lib/a/META + Installing _install/a/lib/a/dune-package + Installing _install/a/share/a/hello + + $ dune install --prefix _install/b --context b + Installing _install/b/lib/a/META + Installing _install/b/lib/a/dune-package + Installing _install/b/share/a/hello + +Passing an invalid context name fails: + + $ dune install --prefix _install/c --context c + Error: Context "c" not found! + [1]