Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --context argument to dune install/uninstall #2412

Merged
2 commits merged into from Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------

Expand Down
15 changes: 13 additions & 2 deletions bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions test/blackbox-tests/test-cases/install-multiple-contexts/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Test installation when multiple contexts are defined

$ cat > dune-workspace <<EOF
> (lang dune 1.11)
> (context (default (name a)))
> (context (default (name b)))
> EOF

$ cat > dune-project <<EOF
> (lang dune 1.11)
> (package (name a))
> EOF

$ cat > dune <<EOF
> (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]