Skip to content

Commit

Permalink
test: introduce --debug-package-logs
Browse files Browse the repository at this point in the history
Introduce a new flag to force stdout printing
when dealing with package management.

Signed-off-by: Etienne Marais <[email protected]>
  • Loading branch information
maiste committed Jun 28, 2024
1 parent 3485eb9 commit 11c3ff7
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 14 deletions.
11 changes: 11 additions & 0 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ module Builder = struct
; debug_artifact_substitution : bool
; debug_load_dir : bool
; debug_digests : bool
; debug_package_logs : bool
; wait_for_filesystem_clock : bool
; only_packages : Only_packages.Clflags.t
; capture_outputs : bool
Expand Down Expand Up @@ -666,6 +667,14 @@ module Builder = struct
[ "debug-digests" ]
~docs
~doc:"Explain why Dune decides to re-digest some files")
and+ debug_package_logs =
Arg.(
value
& flag
& info
[ "debug-package-logs" ]
~docs
~doc:"Always print the standard logs when building packages")
and+ no_buffer =
let doc =
"Do not buffer the output of commands executed by dune. By default dune buffers \
Expand Down Expand Up @@ -970,6 +979,7 @@ module Builder = struct
; debug_artifact_substitution
; debug_load_dir
; debug_digests
; debug_package_logs
; wait_for_filesystem_clock
; only_packages
; capture_outputs = not no_buffer
Expand Down Expand Up @@ -1236,6 +1246,7 @@ let init (builder : Builder.t) =
Dune_engine.Clflags.debug_load_dir := c.builder.debug_load_dir;
Dune_engine.Clflags.debug_fs_cache := c.builder.cache_debug_flags.fs_cache;
Dune_digest.Clflags.debug_digests := c.builder.debug_digests;
Dune_rules.Clflags.debug_package_logs := c.builder.debug_package_logs;
Dune_digest.Clflags.wait_for_filesystem_clock := c.builder.wait_for_filesystem_clock;
Dune_engine.Clflags.capture_outputs := c.builder.capture_outputs;
Dune_engine.Clflags.diff_command := c.builder.diff_command;
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let promote_install_files = ref false
let display = Dune_engine.Clflags.display
let capture_outputs = Dune_engine.Clflags.capture_outputs
let debug_artifact_substitution = ref false
let debug_package_logs = ref false
let ignore_lock_dir = ref false

type on_missing_dune_project_file =
Expand Down
3 changes: 3 additions & 0 deletions src/dune_rules/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ val capture_outputs : bool ref
(** Print debug info about artifact substitution *)
val debug_artifact_substitution : bool ref

(** Print package output when building with package management *)
val debug_package_logs : bool ref

(** Whether we are ignoring "dune.lock/". *)
val ignore_lock_dir : bool ref

Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ module Run_with_path = struct
in
Output.with_error ~accepted_exit_codes:eenv.exit_codes ~pkg ~display (fun error ->
let stdout_to =
match display with
| Display.Verbose -> eenv.stdout_to
match !Clflags.debug_package_logs, display with
| true, _ | false, Display.Verbose -> eenv.stdout_to
| _ -> Process.Io.(null Out)
in
Process.run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Test that section pforms are substituted with absolute paths.

Note that currently dune incorrectly substitutes relative paths for pforms that
appear in string interpolations.
$ dune build 2>&1 | strip_sandbox
$ dune build --debug-package-logs 2>&1 | strip_sandbox
--prefix $SANDBOX/_private/default/.pkg/test/target
$SANDBOX/_private/default/.pkg/test/target
3 changes: 2 additions & 1 deletion test/blackbox-tests/test-cases/pkg/build-package-logs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Test the error message when installing package that fails.

$ . ./helpers.sh
$ make_lockdir
$ export DUNE_DEBUG_PACKAGE_LOGS=0

Make a project with two packages, one successful and one that fails:

Expand All @@ -13,7 +14,7 @@ Create a package with a failing command that throws an error:

$ make_lockpkg x << EOF
> (version 0.0.1)
> (build
> (build
> (progn
> (run cat i_dont_exist)))
> EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ Make a fake dune exe:
$ dune clean
Try building in an environment where `dune` refers to the fake dune.
$ DUNE=$(which dune) # otherwise we would start by running the wrong dune
$ PATH=$PWD/bin:$PATH $DUNE build
$ PATH=$PWD/bin:$PATH $DUNE build --debug-package-logs
Fake dune! (args: build -p bar @install)
Fake dune! (args: build -p foo @install)
5 changes: 5 additions & 0 deletions test/blackbox-tests/test-cases/pkg/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
(alias pkg)
(applies_to :whole_subtree))

(env
(_
(env-vars
(DUNE_DEBUG_PACKAGE_LOGS 1))))

(cram
(deps helpers.sh)
(applies_to :whole_subtree))
Expand Down
6 changes: 5 additions & 1 deletion test/blackbox-tests/test-cases/pkg/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ dune="dune"
pkg_root="_build/_private/default/.pkg"

build_pkg() {
$dune build $pkg_root/$1/target/
if [ $DUNE_DEBUG_PACKAGE_LOGS -eq 1 ] ; then
$dune build --debug-package-logs $pkg_root/$1/target/
else
$dune build $pkg_root/$1/target/
fi
}

show_pkg() {
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/pkg/lock-directory-selection.t
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ are only dependent on on certain systems.

Build macos package on macos:
$ dune clean
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=arm64 dune build _build/_private/default/.pkg/macos-only/target/
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=arm64 dune build --debug-package-logs _build/_private/default/.pkg/macos-only/target/
macos-only

Build macos package on macos:
$ dune clean
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=amd64 dune build _build/_private/default/.pkg/macos-only/target/
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=amd64 dune build --debug-package-logs _build/_private/default/.pkg/macos-only/target/
macos-only

Build linux package on macos (will fail):
Expand All @@ -98,7 +98,7 @@ Build macos package on linux (will fail):

Build linux package on linux:
$ dune clean
$ DUNE_CONFIG__OS=linux DUNE_CONFIG__ARCH=amd64 dune build _build/_private/default/.pkg/linux-only/target/
$ DUNE_CONFIG__OS=linux DUNE_CONFIG__ARCH=amd64 dune build --debug-package-logs _build/_private/default/.pkg/linux-only/target/
linux-only

Try setting the os to one which doesn't have a corresponding lockdir:
Expand Down Expand Up @@ -133,5 +133,5 @@ Test that cond statements can have a default value:
Solution for dune.lock:
- linux-only.0.0.1
$ dune clean
$ dune build _build/_private/default/.pkg/linux-only/target/
$ dune build --debug-package-logs _build/_private/default/.pkg/linux-only/target/
linux-only
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ Make a package "foo" whose build will fail after printing a message:

Attempt to build the package the first time:
(the error from make is grep'd out because it is not consistant across different systems)
$ dune build 2>&1 | grep -v make
$ dune build --debug-package-logs 2>&1 | grep -v make
echo aaa
aaa
false
-> required by _build/_private/default/.pkg/foo/target/cookie
File "dune.lock/foo.pkg", line 4, characters 6-13:
^^^^^^^
Error: Logs for package foo


Update the message that gets printed while building foo:
$ cat >foo/Makefile <<EOF
Expand All @@ -51,8 +54,11 @@ Update the message that gets printed while building foo:
> EOF

The change to the package is picked up:
$ dune build 2>&1 | grep -v make
$ dune build --debug-package-logs 2>&1 | grep -v make
echo bbb
bbb
false
-> required by _build/_private/default/.pkg/foo/target/cookie
File "dune.lock/foo.pkg", line 4, characters 6-13:
^^^^^^^
Error: Logs for package foo

0 comments on commit 11c3ff7

Please sign in to comment.