Skip to content

Commit

Permalink
fix(install): respect display options
Browse files Browse the repository at this point in the history
<!-- ps-id: e2cecc12-1609-4398-97d1-1d56cdbcfd8d -->

Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter committed Feb 26, 2023
1 parent 89d73f2 commit f5524a9
Show file tree
Hide file tree
Showing 46 changed files with 167 additions and 103 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Unreleased
- Accept the Ordered Set Language for the `modes` field in `library` stanzas
(#6611, @anmonteiro).

- dune install now respects --display quiet mode (#7116, fixes #4573, fixes
#7106, @Alizter)

- Stub shared libraries (dllXXX_stubs.so) in Dune-installed libraries could not
be used as dependencies of libraries in the workspace (eg when compiling to
bytecode and/or Javascript). This is now fixed. (#7151, @nojb)
Expand Down
69 changes: 41 additions & 28 deletions bin/install_uninstall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ let synopsis =
present"
]

let print_line fmt =
Printf.ksprintf (fun s -> Console.print [ Pp.verbatim s ]) fmt
let print_line ~verbosity fmt =
Printf.ksprintf
(fun s ->
match verbosity with
| Dune_engine.Display.Quiet -> ()
| _ -> Console.print [ Pp.verbatim s ])
fmt

let interpret_destdir ~destdir path =
match destdir with
Expand Down Expand Up @@ -121,37 +126,42 @@ type rmdir_mode =
(** Operations that act on real files or just pretend to (for --dry-run) *)
module type File_operations = sig
val copy_file :
src:Path.t
verbosity:Dune_engine.Display.t
-> src:Path.t
-> dst:Path.t
-> executable:bool
-> special_file:Special_file.t option
-> package:Package.Name.t
-> conf:Dune_rules.Artifact_substitution.conf
-> unit Fiber.t

val mkdir_p : Path.t -> unit
val mkdir_p : verbosity:Dune_engine.Display.t -> Path.t -> unit

val remove_file_if_exists : Path.t -> unit
val remove_file_if_exists : verbosity:Dune_engine.Display.t -> Path.t -> unit

val remove_dir_if_exists : if_non_empty:rmdir_mode -> Path.t -> unit
val remove_dir_if_exists :
verbosity:Dune_engine.Display.t -> if_non_empty:rmdir_mode -> Path.t -> unit
end

module File_ops_dry_run : File_operations = struct
let copy_file ~src ~dst ~executable ~special_file:_ ~package:_ ~conf:_ =
print_line "Copying %s to %s (executable: %b)"
let copy_file ~verbosity ~src ~dst ~executable ~special_file:_ ~package:_
~conf:_ =
print_line ~verbosity "Copying %s to %s (executable: %b)"
(Path.to_string_maybe_quoted src)
(Path.to_string_maybe_quoted dst)
executable;
Fiber.return ()

let mkdir_p path =
print_line "Creating directory %s" (Path.to_string_maybe_quoted path)
let mkdir_p ~verbosity path =
print_line ~verbosity "Creating directory %s"
(Path.to_string_maybe_quoted path)

let remove_file_if_exists path =
print_line "Removing (if it exists) %s" (Path.to_string_maybe_quoted path)
let remove_file_if_exists ~verbosity path =
print_line ~verbosity "Removing (if it exists) %s"
(Path.to_string_maybe_quoted path)

let remove_dir_if_exists ~if_non_empty path =
print_line "Removing directory (%s if not empty) %s"
let remove_dir_if_exists ~verbosity ~if_non_empty path =
print_line ~verbosity "Removing directory (%s if not empty) %s"
(match if_non_empty with
| Fail -> "fail"
| Warn -> "warn")
Expand Down Expand Up @@ -298,7 +308,7 @@ end) : File_operations = struct
in
Some { need_version; callback }

let copy_file ~src ~dst ~executable ~special_file ~package
let copy_file ~verbosity:_ ~src ~dst ~executable ~special_file ~package
~(conf : Dune_rules.Artifact_substitution.conf) =
let chmod = if executable then fun _ -> 0o755 else fun _ -> 0o644 in
match (special_file : Special_file.t option) with
Expand All @@ -319,16 +329,16 @@ end) : File_operations = struct
| None ->
Dune_rules.Artifact_substitution.copy_file ~conf ~src ~dst ~chmod ()

let remove_file_if_exists dst =
let remove_file_if_exists ~verbosity dst =
if Path.exists dst then (
print_line "Deleting %s" (Path.to_string_maybe_quoted dst);
print_line ~verbosity "Deleting %s" (Path.to_string_maybe_quoted dst);
print_unix_error (fun () -> Path.unlink dst))

let remove_dir_if_exists ~if_non_empty dir =
let remove_dir_if_exists ~verbosity ~if_non_empty dir =
if Path.exists dir then
match Path.readdir_unsorted dir with
| Ok [] ->
print_line "Deleting empty directory %s"
print_line ~verbosity "Deleting empty directory %s"
(Path.to_string_maybe_quoted dir);
print_unix_error (fun () -> Path.rmdir dir)
| Error (e, _, _) ->
Expand All @@ -346,7 +356,7 @@ end) : File_operations = struct
User_error.raise
[ Pp.textf "Please delete non-empty directory %s manually." dir ])

let mkdir_p p =
let mkdir_p ~verbosity:_ p =
(* CR-someday amokhov: We should really change [Path.mkdir_p dir] to fail if
it turns out that [dir] exists and is not a directory. Even better, make
[Path.mkdir_p] return an explicit variant to deal with. *)
Expand Down Expand Up @@ -666,6 +676,7 @@ let install_uninstall ~what =
|> map ~f:(Option.map ~f:Path.of_string)
|> complete
in
let verbosity = config.display.verbosity in
let+ () =
Fiber.sequential_iter install_files_by_context
~f:(fun (context, entries_per_package) ->
Expand Down Expand Up @@ -712,21 +723,23 @@ let install_uninstall ~what =
let* () =
(match Path.is_directory dst with
| true ->
Ops.remove_dir_if_exists ~if_non_empty:Fail dst
| false -> Ops.remove_file_if_exists dst);
print_line "%s %s" msg
Ops.remove_dir_if_exists ~verbosity
~if_non_empty:Fail dst
| false ->
Ops.remove_file_if_exists ~verbosity dst);
print_line ~verbosity "%s %s" msg
(Path.to_string_maybe_quoted dst);
Ops.mkdir_p dir;
Ops.mkdir_p ~verbosity dir;
let executable =
Section.should_set_executable_bit entry.section
in
Ops.copy_file ~src:entry.src ~dst ~executable
~special_file ~package ~conf
Ops.copy_file ~verbosity ~src:entry.src ~dst
~executable ~special_file ~package ~conf
in
Fiber.return (Install.Entry.set_src entry dst)
else Fiber.return entry
| Uninstall ->
Ops.remove_file_if_exists dst;
Ops.remove_file_if_exists ~verbosity dst;
files_deleted_in := Path.Set.add !files_deleted_in dir;
Fiber.return entry)
in
Expand All @@ -739,7 +752,7 @@ let install_uninstall ~what =
(* This [List.rev] is to ensure we process children directories before
their parents *)
|> List.rev
|> List.iter ~f:(Ops.remove_dir_if_exists ~if_non_empty:Warn))
|> List.iter ~f:(Ops.remove_dir_if_exists ~verbosity ~if_non_empty:Warn))
in
Cmd.v
(Cmd.info (cmd_what what) ~doc
Expand Down
6 changes: 3 additions & 3 deletions otherlibs/build-info/test/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Test embedding of build information
> EOF

$ dune build
$ dune install --prefix _install 2> /dev/null
$ dune install --prefix _install

Inside _build, we have no version information:

Expand Down Expand Up @@ -130,7 +130,7 @@ craft an example with a single placeholder to make the output stable:
$ cp c/c.ml d/d.ml

$ dune build d/d.install
$ dune install d --prefix _install --debug-artifact-substitution 2>&1|grep -v '^\(Installing\|Deleting\)'
$ dune install d --prefix _install --debug-artifact-substitution
Found placeholder in _build/install/default/bin/d:
- placeholder: Vcs_describe In_source_tree "d"
- evaluates to: "1.0+d"
Expand All @@ -149,7 +149,7 @@ Version is picked from dune-project if available

$ echo '(version project-version)' >> c/dune-project
$ dune build
$ dune install --prefix _install 2> /dev/null
$ dune install --prefix _install
$ _install/bin/c | sed 's/build-info: .*/build-info: XXX/'
project-version
lib a: 1.0+a
Expand Down
2 changes: 1 addition & 1 deletion otherlibs/site/test/github4389.t/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ dune build @install
$ dune install --prefix _install
$ dune install --prefix _install --display short
Installing _install/lib/github4389/META
Installing _install/lib/github4389/dune-package
Installing _install/bin/main
Expand Down
2 changes: 1 addition & 1 deletion otherlibs/site/test/github4389_without_build_info.t/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ dune build @install
$ dune install --prefix _install
$ dune install --prefix _install --display short
Installing _install/lib/github4389/META
Installing _install/lib/github4389/dune-package
Installing _install/bin/main
Expand Down
8 changes: 4 additions & 4 deletions otherlibs/site/test/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Test with an opam like installation
$ test -e a/a.install
[1]

$ dune install -p a --create-install-files a 2>&1 | sed -e "/^Copying/d"
$ dune install -p a --create-install-files a

$ grep "_destdir" a/a.install -c
7
Expand All @@ -191,7 +191,7 @@ Build everything
Test with a normal installation
--------------------------------

$ dune install --prefix _install 2>&1 | sed -e "/^Installing/d"
$ dune install --prefix _install

Once installed, we have the sites information:

Expand All @@ -213,7 +213,7 @@ Once installed, we have the sites information:
Test with a relocatable installation
--------------------------------

$ dune install --prefix _install_relocatable --relocatable 2>&1 | sed -e "/^Installing/d"
$ dune install --prefix _install_relocatable --relocatable

Once installed, we have the sites information:

Expand Down Expand Up @@ -354,7 +354,7 @@ Test compiling an external plugin
info.txt is found: true
run c: registered:e,b.

$ OCAMLPATH=$(pwd)/_install/lib:$OCAMLPATH dune install --root=e --prefix $(pwd)/_install 2>&1 | sed -e "/^Installing/d"
$ OCAMLPATH=$(pwd)/_install/lib:$OCAMLPATH dune install --root=e --prefix $(pwd)/_install

$ OCAMLPATH=_install/lib:$OCAMLPATH _install/bin/c
run a
Expand Down
8 changes: 4 additions & 4 deletions otherlibs/site/test/run_2_9.t
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Test with an opam like installation
$ test -e a/a.install
[1]

$ dune install -p a --create-install-files a 2> /dev/null
$ dune install -p a --create-install-files a

$ grep "_destdir" a/a.install -c
7
Expand All @@ -179,7 +179,7 @@ Build everything
Test with a normal installation
--------------------------------

$ dune install --prefix _install 2> /dev/null
$ dune install --prefix _install

Once installed, we have the sites information:

Expand All @@ -198,7 +198,7 @@ Once installed, we have the sites information:
Test with a relocatable installation
--------------------------------

$ dune install --prefix _install_relocatable --relocatable 2> /dev/null
$ dune install --prefix _install_relocatable --relocatable

Once installed, we have the sites information:

Expand Down Expand Up @@ -339,7 +339,7 @@ Test compiling an external plugin
info.txt is found: true
run c: registered:e,b.

$ OCAMLPATH=$PWD/_install/lib:$OCAMLPATH dune install --root=e --prefix $PWD/_install 2> /dev/null
$ OCAMLPATH=$PWD/_install/lib:$OCAMLPATH dune install --root=e --prefix $PWD/_install

$ OCAMLPATH=_install/lib:$OCAMLPATH _install/bin/c
run a
Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/depend-on/installed-packages.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Entering directory 'a'
Leaving directory 'a'

$ dune install --root a --prefix $PWD/prefix
$ dune install --root a --prefix $PWD/prefix --display short
Installing $TESTCASE_ROOT/prefix/lib/a/META
Installing $TESTCASE_ROOT/prefix/lib/a/dune-package
Installing $TESTCASE_ROOT/prefix/share/a/CATME
Expand Down Expand Up @@ -51,7 +51,7 @@
Entering directory 'a'
Leaving directory 'a'

$ dune install --root a --prefix $PWD/prefix
$ dune install --root a --prefix $PWD/prefix --display short
Deleting $TESTCASE_ROOT/prefix/lib/a/META
Installing $TESTCASE_ROOT/prefix/lib/a/META
Deleting $TESTCASE_ROOT/prefix/lib/a/dune-package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tests that the "old_public_name" field is evaluated lazily

$ (cd a
> dune build @install --root .
> dune install --prefix $PWD/../_install)
> dune install --prefix $PWD/../_install --display short)
Installing $TESTCASE_ROOT/a/../_install/lib/a/META
Installing $TESTCASE_ROOT/a/../_install/lib/a/dune-package

Expand All @@ -68,7 +68,7 @@ deprecated library will be resolved in the installed world only.

$ (cd b
> dune build @install --root .
> dune install --prefix $PWD/../_install 2>&1 | dune_cmd sanitize)
> dune install --prefix $PWD/../_install 2>&1 --display short | dune_cmd sanitize)
Installing $TESTCASE_ROOT/b/../_install/lib/b/META
Installing $TESTCASE_ROOT/b/../_install/lib/b/b$ext_lib
Installing $TESTCASE_ROOT/b/../_install/lib/b/b.cma
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Allow directories to be installable
]

$ mkdir ./installation
$ dune install --prefix ./installation
$ dune install --prefix ./installation --display short
Installing installation/lib/foo/META
Installing installation/lib/foo/dune-package
Installing installation/lib/foo/renamed/x
Expand Down
3 changes: 1 addition & 2 deletions test/blackbox-tests/test-cases/dune-package.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ Build with "DUNE_STORE_ORIG_SOURCE_DIR=true" profile

Install the package directly

$ dune install "--prefix=$PWD/prefix" --root=a 2>&1 | grep -v "Installing"
[1]
$ dune install "--prefix=$PWD/prefix" --root=a

$ dune_cmd cat prefix/lib/a/dune-package | grep -e 'lib/a' -e 'share/a'
$TESTCASE_ROOT/prefix/lib/a)
Expand Down
3 changes: 2 additions & 1 deletion test/blackbox-tests/test-cases/foreign-library.t
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ Testsuite for the (foreign_library ...) stanza.

$ rm -rf _build
$ touch external/external_library.opam
$ ( cd external && ../sdune build @install && ../sdune install --prefix install 2>&1 | dune_cmd sanitize )
$ ( cd external && ../sdune build @install \
> && ../sdune install --prefix install --display=short 2>&1 | dune_cmd sanitize )
Installing install/lib/external_library/META
Installing install/lib/external_library/correction.h
Installing install/lib/external_library/dune-package
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/github2228.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ would fail because the .cmi wasn't correctly copied to the _build/install dir.
$ dune build @install
$ dune runtest
testing
$ dune install --prefix ./installed 2>&1 | grep -i cmi
$ dune install --prefix ./installed --display short 2>&1 | grep -i cmi
Installing installed/lib/foobar/foobar.cmi
Installing installed/lib/foobar/impl/foobar.cmi
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/github2629.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$ export DUNE_BUILD_DIR=$(mktemp -d -t github2629XXXXXX);
> dune build @install;
> cat $DUNE_BUILD_DIR/default/foo.install | sed s#$DUNE_BUILD_DIR#DUNE_BUILD_DIR#g;
> dune install --dry-run 2>&1 | awk '/Internal/,/External/'
> dune install --dry-run
lib: [
"DUNE_BUILD_DIR/install/default/lib/foo/META"
"DUNE_BUILD_DIR/install/default/lib/foo/dune-package"
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/github3727.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ visible regardless if the stanzas were filtered.

$ rm -rf _build
$ dune build -p foo
$ dune install foo --prefix ./_install
$ dune install foo --prefix ./_install --display=short
Installing _install/lib/foo/META
Installing _install/lib/foo/bar/private_foo.a
Installing _install/lib/foo/bar/private_foo.cma
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Then we install the backend and check that the "inline_tests.backend"
field is properly generated in the installed `dune-package` file:

$ dune build dune-file/foo.install
$ dune install foo --prefix _install 2> /dev/null
$ dune install foo --prefix _install
$ grep -A8 inline_tests.backend _install/lib/foo/dune-package
(inline_tests.backend
(runner_libraries str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
> EOF
$ dune build @install
$ mkdir install bindir sbindir
$ dune install --dry-run --prefix ./install --bindir $PWD/bindir --sbindir $PWD/sbindir 2>&1 | grep bindir
$ dune install --dry-run --prefix ./install --bindir $PWD/bindir --sbindir $PWD/sbindir --display short 2>&1 | grep bindir
Removing (if it exists) $TESTCASE_ROOT/bindir/user
Installing $TESTCASE_ROOT/bindir/user
Creating directory $TESTCASE_ROOT/bindir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
> EOF
$ dune build @install
$ mkdir install datadir
$ dune install --dry-run --prefix ./install --datadir $PWD/datadir 2>&1 | grep datadir
$ dune install --dry-run --prefix ./install --datadir $PWD/datadir --display short 2>&1 | grep datadir
Removing (if it exists) $TESTCASE_ROOT/datadir/foo/datafile
Installing $TESTCASE_ROOT/datadir/foo/datafile
Creating directory $TESTCASE_ROOT/datadir/foo
Expand Down
Loading

0 comments on commit f5524a9

Please sign in to comment.