Make the output of Dune deterministic in tests (#855)

When the root is not the cwd, print a relative path for the "Entering
..." line rather than an absolute one.

Signed-off-by: Jeremie Dimino <jdimino@janestreet.com>
This commit is contained in:
Jérémie Dimino 2018-06-06 16:25:04 +01:00 committed by GitHub
parent 0fafebe9be
commit bb7827a7b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 77 additions and 24 deletions

View File

@ -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)
-----------------------

View File

@ -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)
else
cwd);
let t =
{ log
; gen_status_line

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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}
@ -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:
@ -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]

View File

@ -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
@ -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

View File

@ -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}
@ -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.
@ -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'

View File

@ -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]