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

Make the output of Dune deterministic in tests #855

Merged
1 commit merged into from Jun 6, 2018
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ next
- Remove hard-coded knowledge of ppx_driver and
ocaml-migrate-parsetree when using a `dune` file (#576, @diml)

- Make the output of Dune slightly more deterministic when run from
inside Dune (#855, @diml)

1.0+beta20 (10/04/2018)
-----------------------

Expand Down
25 changes: 24 additions & 1 deletion src/scheduler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,30 @@ let go ?(log=Log.no_log) ?(config=Config.default)
(Path.to_absolute_filename Path.root |> String.maybe_quoted);
let cwd = Sys.getcwd () in
if cwd <> initial_cwd then
Printf.eprintf "Entering directory '%s'\n%!" cwd;
Printf.eprintf "Entering directory '%s'\n%!"
(if Config.inside_dune then
let descendant_simple p ~of_ =
match
String.drop_prefix p ~prefix:of_
with
| None | Some "" -> None
| Some s -> Some (String.sub s ~pos:1 ~len:(String.length s - 1))
in
match descendant_simple cwd ~of_:initial_cwd with
| Some s -> s
| None ->
match descendant_simple initial_cwd ~of_:cwd with
| None -> cwd
| Some s ->
let rec loop acc dir =
if dir = Filename.current_dir_name then
acc
else
loop (Filename.concat acc "..") (Filename.dirname dir)
in
loop ".." (Filename.dirname s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just use Path.descendant here? I'm a bit worried that that we're hitting that annoying infinite loop case again if dir ends up being an absolute path.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently Path.descendant doesn't work for absolute paths. Here the two paths come from Sys.getcwd, so I assumed they'd be normalized.

else
cwd);
let t =
{ log
; gen_status_line
Expand Down
8 changes: 6 additions & 2 deletions test/blackbox-tests/test-cases/bad-alias-error/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
$ dune runtest --root absolute-path 2>&1 | grep -v Entering
$ dune runtest --root absolute-path
Entering directory 'absolute-path'
File "jbuild", line 3, characters 16-24:
Error: Invalid alias!
Tried to reference path outside build dir: "/foo/bar"
$ dune runtest --root outside-workspace 2>&1 | grep -v Entering
[1]
$ dune runtest --root outside-workspace
Entering directory 'outside-workspace'
File "jbuild", line 4, characters 16-39:
Error: path outside the workspace: ./../../../foobar from default
[1]
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/github644/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

These should print something:

$ dune external-lib-deps --display quiet @runtest
$ dune external-lib-deps @runtest
These are the external library dependencies in the default context:
- ocaml-migrate-parsetree
- ppx_that_doesn't_exist

$ dune external-lib-deps --display quiet --missing @runtest
$ dune external-lib-deps --missing @runtest
Error: The following libraries are missing in the default context:
- ppx_that_doesn't_exist
Hint: try: opam install ppx_that_doesn't_exist
Expand Down
12 changes: 8 additions & 4 deletions test/blackbox-tests/test-cases/github660/run.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
When there are explicit interfaces, modules must be rebuilt.

$ dune runtest --root explicit-interfaces --display quiet -j1 2>&1 | grep -v Entering
$ dune runtest --root explicit-interfaces
Entering directory 'explicit-interfaces'
main alias runtest
hello
$ echo 'let x = 1' >> explicit-interfaces/lib_sub.ml
$ dune runtest --root explicit-interfaces --display quiet -j1 2>&1 | grep -v Entering | grep -v ocamlopt
$ dune runtest --root explicit-interfaces
Entering directory 'explicit-interfaces'
main alias runtest
hello

When there are no interfaces, the situation is the same, but it is not possible
to rely on these.

$ dune runtest --root no-interfaces --display quiet -j1 2>&1 | grep -v Entering
$ dune runtest --root no-interfaces
Entering directory 'no-interfaces'
main alias runtest
hello
$ echo 'let x = 1' >> no-interfaces/lib_sub.ml
$ dune runtest --root no-interfaces --display quiet -j1 2>&1 | grep -v Entering | grep -v ocamlopt
$ dune runtest --root no-interfaces
Entering directory 'no-interfaces'
main alias runtest
hello
17 changes: 12 additions & 5 deletions test/blackbox-tests/test-cases/intf-only/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Successes:

$ dune build --display short --root foo --debug-dep 2>&1 | grep -v Entering
$ dune build --display short --root foo --debug-dep
Entering directory 'foo'
ocamldep test/bar.ml.d
ocamldep foo.ml.d
ocamlc .foo.objs/foo__.{cmi,cmo,cmt}
Expand All @@ -20,7 +21,8 @@ Successes:

Errors:

$ dune build --display short --root a foo.cma 2>&1 | grep -v Entering
$ dune build --display short --root a foo.cma
Entering directory 'a'
File "dune", line 2, characters 1-13:
Warning: Some modules don't have an implementation.
You need to add the following field to this stanza:
Expand All @@ -30,16 +32,21 @@ Errors:
This will become an error in the future.
ocamlc .foo.objs/foo.{cmi,cmo,cmt}
ocamlc foo.cma
$ dune build --display short --root b foo.cma 2>&1 | grep -v Entering
$ dune build --display short --root b foo.cma
Entering directory 'b'
File "dune", line 3, characters 34-37:
Warning: The following modules must be listed here as they don't have an implementation:
- y
This will become an error in the future.
ocamlc .foo.objs/foo.{cmi,cmo,cmt}
ocamlc foo.cma
$ dune build --display short --root c foo.cma 2>&1 | grep -v Entering
$ dune build --display short --root c foo.cma
Entering directory 'c'
File "dune", line 3, characters 35-36:
Error: Module X doesn't exist.
$ dune build --display short --root d foo.cma 2>&1 | grep -v Entering
[1]
$ dune build --display short --root d foo.cma
Entering directory 'd'
File "dune", line 3, characters 35-36:
Error: Module X has an implementation, it cannot be listed here
[1]
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/odoc-unique-mlds/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Duplicate mld's in the same scope
$ dune build @doc --display short --root ./same-scope 2>&1 | grep -v Entering
$ dune build @doc --display short --root ./same-scope
Entering directory 'same-scope'
odoc _doc/_html/odoc.css
ocamlc lib1/.root_lib1.objs/root_lib1.{cmi,cmo,cmt}
odoc _doc/_odoc/lib/root.lib1/root_lib1.odoc
Expand All @@ -12,7 +13,8 @@ Duplicate mld's in the same scope

Duplicate mld's in different scope
$ rm -rf diff-scope/_build
$ dune build @doc --display short --root ./diff-scope 2>&1 | grep -v Entering
$ dune build @doc --display short --root ./diff-scope
Entering directory 'diff-scope'
odoc _doc/_html/odoc.css
ocamlc scope1/.scope1.objs/scope1.{cmi,cmo,cmt}
odoc _doc/_odoc/lib/scope1/scope1.odoc
Expand Down
18 changes: 12 additions & 6 deletions test/blackbox-tests/test-cases/private-public-overlap/run.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
public libraries may not have private dependencies

$ dune build --display short --root private-dep 2>&1 | grep -v Entering
$ dune build --display short --root private-dep
Entering directory 'private-dep'
File "dune", line 10, characters 14-24:
Error: Library "privatelib" is private, it cannot be a dependency of a public library.
You need to give "privatelib" a public name.
ocamldep publiclib.ml.d
[1]

On the other hand, public libraries may have private preprocessors
$ dune build --display short --root private-rewriter 2>&1 | grep -v Entering
$ dune build --display short --root private-rewriter
Entering directory 'private-rewriter'
ocamlc .ppx_internal.objs/ppx_internal.{cmi,cmo,cmt}
ocamlopt .ppx_internal.objs/ppx_internal.{cmx,o}
ocamlopt ppx_internal.{a,cmxa}
Expand All @@ -21,7 +24,8 @@ On the other hand, public libraries may have private preprocessors
ocamlc mylib.cma

Unless they introduce private runtime dependencies:
$ dune build --display short --root private-runtime-deps 2>&1 | grep -v Entering
$ dune build --display short --root private-runtime-deps
Entering directory 'private-runtime-deps'
File "jbuild", line 16, characters 20-31:
Error: Library "private_runtime_dep" is private, it cannot be a dependency of a public library.
You need to give "private_runtime_dep" a public name.
Expand All @@ -31,14 +35,16 @@ Unless they introduce private runtime dependencies:
ocamlopt .ppx/jbuild/private_ppx@mylib/ppx.exe
ppx mylib.pp.ml
ocamldep mylib.pp.ml.d
[1]

However, public binaries may accept private dependencies
$ dune build --display short --root exes 2>&1 | grep -v Entering
$ dune build --display short --root exes
Entering directory 'exes'
ocamldep publicbin.ml.d
ocamlc .publicbin.eobjs/publicbin.{cmi,cmo,cmt}
ocamlopt .publicbin.eobjs/publicbin.{cmx,o}
ocamlopt publicbin.exe

Private dependencies shouldn't make the library optional
$ dune build --display short --root optional 2>&1 | grep -v Entering
[1]
$ dune build --display short --root optional
Entering directory 'optional'
8 changes: 6 additions & 2 deletions test/blackbox-tests/test-cases/quoting/run.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
This behavior is surprising, we should get an error about the fact
that ${@} is not quoted and doesn't contain exactly 1 element

$ dune build --root bad x 2>&1 | grep -v Entering
$ dune build --root bad x
Entering directory 'bad'
Error: Rule failed to generate the following targets:
- x
- y
[1]


The targets should only be interpreted as a single path when quoted

$ dune build --root good s 2>&1 | grep -v Entering
$ dune build --root good s
Entering directory 'good'
Error: Rule failed to generate the following targets:
- s
- t
[1]