Skip to content

Commit

Permalink
Remove automatic sanitation (ocaml#3620)
Browse files Browse the repository at this point in the history
extension sanitation must now be manually ran via dune_cmd sanitize

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Jul 9, 2020
1 parent d981e29 commit fb06a3d
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 131 deletions.
2 changes: 1 addition & 1 deletion otherlibs/cram/bin/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(executable
(name dune_cram)
(libraries dune-private-libs.stdune dune-build-info cmdliner
build_path_prefix_map dune-private-libs.dune_re dune-configurator)
build_path_prefix_map dune-private-libs.dune_re)
(preprocess (future_syntax)))

(ocamllex cram_lexer)
42 changes: 3 additions & 39 deletions otherlibs/cram/bin/sanitize.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ open Stdune
open Cmdliner
open Import.Let_syntax
module Re = Dune_re
module Configurator = Configurator.V1

let rewrite_paths build_path_prefix_map =
match Build_path_prefix_map.decode_map build_path_prefix_map with
Expand All @@ -18,44 +17,9 @@ let rewrite_paths build_path_prefix_map =
Re.replace abs_path_re s ~f:(fun g ->
Build_path_prefix_map.rewrite map (Re.Group.get g 0))

let make_ext_replace config =
let tbl =
List.filter_map [ "ext_exe"; "ext_dll"; "ext_asm"; "ext_lib"; "ext_obj" ]
~f:(fun var ->
match Configurator.ocaml_config_var config var with
| Some "" -> None
| Some s -> Some (s, "$" ^ var)
| None -> (
match (var, Configurator.ocaml_config_var config "system") with
| "ext_exe", Some "Win32" -> Some (".exe", var)
| _ -> None ))
in
let re =
Re.(
compile
(seq
[ diff any (char '/')
; alt (List.map tbl ~f:(fun (s, _) -> str s))
; eow
]))
in
let map = String.Map.of_list_reduce tbl ~f:(fun _ x -> x) in
fun s ->
Re.replace re s ~f:(fun g ->
let s = Re.Group.get g 0 in
sprintf "%c%s" s.[0] (String.Map.find_exn map (String.drop s 1)))

let sanitizer =
let ext_replace =
if Option.is_some (Env.get Env.initial "INSIDE_DUNE") then
make_ext_replace (Configurator.create "sanitizer")
else
fun s ->
s
in
fun (command : Sanitizer.Command.t) ->
command.output |> Ansi_color.strip |> ext_replace
|> rewrite_paths command.build_path_prefix_map
let sanitizer (command : Sanitizer.Command.t) =
command.output |> Ansi_color.strip
|> rewrite_paths command.build_path_prefix_map

let term =
let+ () = Term.pure () in
Expand Down
12 changes: 6 additions & 6 deletions test/blackbox-tests/test-cases/block-strings.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
ARFLAGS="$ARFLAGS" \
CXX="$CXX" \
CXXFLAGS="$CXXFLAGS" \
obj/libre2$ext_lib obj/so/libre2$ext_dll
cp libre2/obj/libre2$ext_lib libre2_c_stubs$ext_lib
cp libre2/obj/so/libre2$ext_dll dllre2_c_stubs$ext_dll
obj/libre2.a obj/so/libre2.so
cp libre2/obj/libre2.a libre2_c_stubs.a
cp libre2/obj/so/libre2.so dllre2_c_stubs.so
${.MAKE} -s -C libre2 clean

$ dune build @new
Expand All @@ -27,9 +27,9 @@
ARFLAGS="$ARFLAGS" \
CXX="$CXX" \
CXXFLAGS="$CXXFLAGS" \
obj/libre2$ext_lib obj/so/libre2$ext_dll
cp libre2/obj/libre2$ext_lib libre2_c_stubs$ext_lib
cp libre2/obj/so/libre2$ext_dll dllre2_c_stubs$ext_dll
obj/libre2.a obj/so/libre2.so
cp libre2/obj/libre2.a libre2_c_stubs.a
cp libre2/obj/so/libre2.so dllre2_c_stubs.so
${.MAKE} -s -C libre2 clean

$ dune build @quoting-test
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/cross-compilation.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
42
$ ls *.install
p-foo.install
$ dune_cmd cat p-foo.install
$ dune_cmd cat p-foo.install | dune_cmd sanitize
lib: [
"_build/install/default.foo/lib/p/META" {"../../foo-sysroot/lib/p/META"}
"_build/install/default.foo/lib/p/dune-package" {"../../foo-sysroot/lib/p/dune-package"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ deprecated library will be resolved in the installed world only.

$ (cd b
> dune build @install --root .
> dune install --prefix $PWD/../_install)
> dune install --prefix $PWD/../_install 2>&1 | 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
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/dune-package.t/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ dune build
$ dune_cmd cat _build/install/default/lib/a/dune-package | sed "s/(lang dune .*)/(lang dune <version>)/"
$ dune_cmd cat _build/install/default/lib/a/dune-package | sed "s/(lang dune .*)/(lang dune <version>)/" | dune_cmd sanitize
(lang dune <version>)
(name a)
(library
Expand Down
3 changes: 1 addition & 2 deletions test/blackbox-tests/test-cases/duplicate-c-cxx-obj.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stubs names, things are still broken if their .o files overlap:
> (c_names foo sub/foo))
> EOF

$ dune build --root diff-stanza @all
$ dune build --root diff-stanza @all 2>&1 | dune_cmd sanitize
Entering directory 'diff-stanza'
File "dune", line 4, characters 10-13:
4 | (c_names foo))
Expand All @@ -16,7 +16,6 @@ stubs names, things are still broken if their .o files overlap:
definition at dune:9.
Hint: You can avoid the name clash by renaming one of the objects, or by
placing it into a different directory.
[1]

Another form of this bug is if the same source is present in different
directories. In this case, the rules are fine, but this is probably not what the
Expand Down
3 changes: 1 addition & 2 deletions test/blackbox-tests/test-cases/duplicate-c-cxx.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ c_names and cxx_names with overlapping names in the same stanza
[1]

c_names with overlapping names in different stanzas
$ dune build --root diff-stanza @all
$ dune build --root diff-stanza @all 2>&1 | dune_cmd sanitize
Entering directory 'diff-stanza'
File "dune", line 4, characters 10-13:
4 | (c_names foo))
Expand All @@ -23,4 +23,3 @@ c_names with overlapping names in different stanzas
definition at dune:9.
Hint: You can avoid the name clash by renaming one of the objects, or by
placing it into a different directory.
[1]
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/foreign-library.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ Testsuite for the (foreign_library ...) stanza.

$ rm -rf _build
$ touch external/external_library.opam
$ ( cd external && ../sdune build @install && ../sdune install --prefix install)
$ ( cd external && ../sdune build @install && ../sdune install --prefix install 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
7 changes: 3 additions & 4 deletions test/blackbox-tests/test-cases/foreign-stubs.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ Testsuite for the (foreign_stubs ...) field.
> value foo(value unit) { return Val_int(9); }
> EOF

$ ./sdune build
$ ./sdune build 2>&1 | dune_cmd sanitize
File "dune", line 1, characters 0-0:
Error: No rule found for libbar$ext_lib
[1]

----------------------------------------------------------------------------------
* Build succeeds when a self-built archive exists.
Expand Down Expand Up @@ -476,7 +475,7 @@ setting [disable_dynamically_linked_foreign_archives] is [true] in the workspace
* Make sure no rules are generated for foreign dynamically linked archives

$ ./sdune build _build/default/dlltime.so
Error: Don't know how to build _build/default/dlltime$ext_dll
Error: Don't know how to build _build/default/dlltime.so
[1]

----------------------------------------------------------------------------------
Expand Down Expand Up @@ -527,7 +526,7 @@ setting [disable_dynamically_linked_foreign_archives] is [true] in the workspace
3 | (name clock)
4 | (modules clock)
5 | (self_build_stubs_archive (time)))
Error: No rule found for dlltime_stubs$ext_dll
Error: No rule found for dlltime_stubs.so
[1]

----------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/gen-opam-install-file.t/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
stubs and js files installed

$ dune build --root stubs
$ dune build --root stubs | dune_cmd sanitize
Entering directory 'stubs'
lib: [
"_build/install/default/lib/foo/META"
Expand Down Expand Up @@ -64,7 +64,7 @@ mld files are installed

unwrapped libraries have the correct artifacts

$ dune build --root lib-unwrapped
$ dune build --root lib-unwrapped | dune_cmd sanitize
Entering directory 'lib-unwrapped'
lib: [
"_build/install/default/lib/foo/META"
Expand All @@ -84,7 +84,7 @@ unwrapped libraries have the correct artifacts

wrapped lib with lib interface module

$ dune build --root lib-wrapped-alias
$ dune build --root lib-wrapped-alias | dune_cmd sanitize
Entering directory 'lib-wrapped-alias'
lib: [
"_build/install/default/lib/foo/META"
Expand Down Expand Up @@ -112,7 +112,7 @@ wrapped lib with lib interface module

wrapped lib without lib interface module

$ dune build --root lib-wrapped-no-alias
$ dune build --root lib-wrapped-no-alias | dune_cmd sanitize
Entering directory 'lib-wrapped-no-alias'
lib: [
"_build/install/default/lib/foo/META"
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/github1549.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Reproduction case for #1549: too many parentheses in installed .dune files
$ dune build @install --root backend
Entering directory 'backend'

$ dune_cmd cat backend/_build/install/default/lib/dune_inline_tests/dune-package | sed "s/(lang dune .*)/(lang dune <version>)/"
$ dune_cmd cat backend/_build/install/default/lib/dune_inline_tests/dune-package | sed "s/(lang dune .*)/(lang dune <version>)/" | dune_cmd sanitize
(lang dune <version>)
(name dune_inline_tests)
(library
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/glob-deps.t/run.t
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$ dune build @glob
$ dune build @glob | dune_cmd sanitize
foo/dune foo/foo$ext_lib foo/foo.cma foo/foo.cmxa foo/foo.cmxs foo/foo.ml
6 changes: 3 additions & 3 deletions test/blackbox-tests/test-cases/inline_tests.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The expected behavior for the following three tests is to output nothing: the te
run alias many-backends-choose/runtest
backend_mbc1

$ dune runtest dune-file | sed "s/(lang dune .*)/(lang dune <version>)/"
$ dune runtest dune-file | sed "s/(lang dune .*)/(lang dune <version>)/" | dune_cmd sanitize
run alias dune-file/runtest
414243
(lang dune <version>)
Expand Down Expand Up @@ -77,10 +77,10 @@ The expected behavior for the following three tests is to output nothing: the te
(echo "\n")
(echo "let () = print_int 43;;")))))

$ dune build dune-file/foo.install && dune install foo --prefix install
$ dune build dune-file/foo.install && dune install foo --prefix install | dune_cmd sanitize
Installing install/lib/foo/META
Installing install/lib/foo/dune-package
Installing install/lib/foo/foo$ext_lib
Installing install/lib/foo/foo.a
Installing install/lib/foo/foo.cma
Installing install/lib/foo/foo.cmi
Installing install/lib/foo/foo.cmt
Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/install-dry-run.t/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ dune build @install
$ dune install --dry-run 2>&1 | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
$ dune install --dry-run 2>&1 | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#' | dune_cmd sanitize
Installing OPAM_PREFIX/lib/mylib/META
Installing OPAM_PREFIX/lib/mylib/dune-package
Installing OPAM_PREFIX/lib/mylib/mylib$ext_lib
Expand Down Expand Up @@ -45,7 +45,7 @@
Creating directory OPAM_PREFIX/lib/mylib
Copying _build/install/default/lib/mylib/opam to OPAM_PREFIX/lib/mylib/opam (executable: false)

$ dune uninstall --dry-run 2>&1 | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#'
$ dune uninstall --dry-run 2>&1 | sed 's#'$(opam config var prefix)'#OPAM_PREFIX#' | dune_cmd sanitize
Removing (if it exists) OPAM_PREFIX/lib/mylib/META
Removing (if it exists) OPAM_PREFIX/lib/mylib/dune-package
Removing (if it exists) OPAM_PREFIX/lib/mylib/mylib$ext_lib
Expand Down
18 changes: 9 additions & 9 deletions test/blackbox-tests/test-cases/install-libdir.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
`dune install` should handle destination directories that don't exist

$ dune build @install
$ dune install --prefix install --libdir lib
$ dune install --prefix install --libdir lib 2>&1 | dune_cmd sanitize
Installing install/lib/foo/META
Installing install/lib/foo/dune-package
Installing install/lib/foo/foo$ext_lib
Expand All @@ -23,7 +23,7 @@

If prefix is passed, the default for libdir is `$prefix/lib`:

$ dune install --prefix install --dry-run
$ dune install --prefix install --dry-run 2>&1 | dune_cmd sanitize
Installing install/lib/foo/META
Installing install/lib/foo/dune-package
Installing install/lib/foo/foo$ext_lib
Expand Down Expand Up @@ -89,8 +89,8 @@ If prefix is not passed, libdir defaults to the output of `ocamlfind printconf
destdir`:

$ (export OCAMLFIND_DESTDIR=/OCAMLFIND_DESTDIR
> dune install --dry-run
> dune uninstall --dry-run)
> dune install --dry-run 2>&1 | dune_cmd sanitize
> dune uninstall --dry-run 2>&1 | dune_cmd sanitize)
Installing /OCAMLFIND_DESTDIR/foo/META
Installing /OCAMLFIND_DESTDIR/foo/dune-package
Installing /OCAMLFIND_DESTDIR/foo/foo$ext_lib
Expand Down Expand Up @@ -175,7 +175,7 @@ destdir`:
If only libdir is passed, binaries are installed under prefix/bin and libraries
in libdir:

$ dune install --libdir /LIBDIR --dry-run
$ dune install --libdir /LIBDIR --dry-run 2>&1 | dune_cmd sanitize
> dune uninstall --libdir /LIBDIR --dry-run
Installing /LIBDIR/foo/META
Installing /LIBDIR/foo/dune-package
Expand Down Expand Up @@ -239,7 +239,7 @@ in libdir:
Copying _build/install/default/man/man3/another-man-page.3 to /OPAM_PREFIX/man/man3/another-man-page.3 (executable: false)
Removing (if it exists) /LIBDIR/foo/META
Removing (if it exists) /LIBDIR/foo/dune-package
Removing (if it exists) /LIBDIR/foo/foo$ext_lib
Removing (if it exists) /LIBDIR/foo/foo.a
Removing (if it exists) /LIBDIR/foo/foo.cma
Removing (if it exists) /LIBDIR/foo/foo.cmi
Removing (if it exists) /LIBDIR/foo/foo.cmt
Expand All @@ -261,7 +261,7 @@ in libdir:
The DESTDIR var is supported. When set, it is prepended to the prefix.
This is the case when the prefix is implicit:

$ DESTDIR=DESTDIR dune install --dry-run
$ DESTDIR=DESTDIR dune install --dry-run 2>&1 | dune_cmd sanitize
Installing DESTDIR/OPAM_PREFIX/lib/foo/META
Installing DESTDIR/OPAM_PREFIX/lib/foo/dune-package
Installing DESTDIR/OPAM_PREFIX/lib/foo/foo$ext_lib
Expand Down Expand Up @@ -325,7 +325,7 @@ This is the case when the prefix is implicit:

But also when the prefix is explicit:

$ DESTDIR=DESTDIR dune install --prefix prefix --dry-run
$ DESTDIR=DESTDIR dune install --prefix prefix --dry-run 2>&1 | dune_cmd sanitize
Installing DESTDIR/prefix/lib/foo/META
Installing DESTDIR/prefix/lib/foo/dune-package
Installing DESTDIR/prefix/lib/foo/foo$ext_lib
Expand Down Expand Up @@ -389,7 +389,7 @@ But also when the prefix is explicit:

DESTDIR can also be passed as a command line flag.

$ dune install --destdir DESTDIR --prefix prefix --dry-run
$ dune install --destdir DESTDIR --prefix prefix --dry-run 2>&1 | dune_cmd sanitize
Installing DESTDIR/prefix/lib/foo/META
Installing DESTDIR/prefix/lib/foo/dune-package
Installing DESTDIR/prefix/lib/foo/foo$ext_lib
Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/lib.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ TODO: Fix %{libexec} and %{libexec-private} variables and test them.
> EOF

$ touch external/external_library.opam
$ ( cd external && ../sdune build @install && ../sdune install --prefix install)
$ ( cd external && ../sdune build @install && ../sdune install --prefix install | dune_cmd sanitize)
Installing install/lib/external_library/META
Installing install/lib/external_library/dune-package
Installing install/lib/external_library/extlib$ext_lib
Installing install/lib/external_library/extlib.a
Installing install/lib/external_library/extlib.cma
Installing install/lib/external_library/extlib.cmi
Installing install/lib/external_library/extlib.cmt
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/no-installable-mode.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ message is displayed:

However, it is possible to build a private one explicitly.

$ dune build --root=private --display=short myprivatelib.so
$ dune build --root=private --display=short myprivatelib.so 2>&1 | dune_cmd sanitize
Entering directory 'private'
ocamldep .myprivatelib.eobjs/myprivatelib.ml.d
ocamlc .myprivatelib.eobjs/byte/myprivatelib.{cmi,cmo,cmt}
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/output-obj.t/run.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ dune build @all
$ dune build @runtest
$ dune build @runtest 2>&1 | dune_cmd sanitize
static alias runtest
OK: ./static.exe
dynamic alias runtest
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/plugin-mode.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Testsuite for (mode plugin).
> Dynlink.loadfile (Dynlink.adapt_filename "b.cma")
> EOF

$ dune build --display short @all
$ dune build --display short @all 2>&1 | dune_cmd sanitize
ocamldep foo/.foo.objs/foo.ml.d
ocamldep $ext_lib.eobjs/a.ml.d
ocamldep foo/.bar.objs/bar.ml.d
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/re-exported-deps.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ transtive deps expressed in the dune-package

$ dune build @install --root transitive
Entering directory 'transitive'
$ dune_cmd cat transitive/_build/install/default/lib/pkg/dune-package | sed "s/(lang dune .*)/(lang dune <version>)/"
$ dune_cmd cat transitive/_build/install/default/lib/pkg/dune-package | sed "s/(lang dune .*)/(lang dune <version>)/" | dune_cmd sanitize
(lang dune <version>)
(name pkg)
(library
Expand Down
Loading

0 comments on commit fb06a3d

Please sign in to comment.