Merge pull request #709 from rgrinberg/cram-portable-exts

Cram portable exts
This commit is contained in:
Rudi Grinberg 2018-04-18 22:51:55 +07:00 committed by GitHub
commit d9a90b4f29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 144 additions and 102 deletions

View File

@ -6,7 +6,7 @@
(action
(chdir sample-projects/hello_world
(setenv JBUILDER ${bin:jbuilder}
(run ${exe:../test/blackbox-tests/cram.exe} run.t))))))
(run ${exe:../test/blackbox-tests/cram.exe} -test run.t))))))
(alias
((name runtest)
@ -14,6 +14,6 @@
(action
(chdir sample-projects/with-configure-step
(setenv JBUILDER ${bin:jbuilder}
(run ${exe:../test/blackbox-tests/cram.exe} run.t))))))
(run ${exe:../test/blackbox-tests/cram.exe} -test run.t))))))

View File

@ -12,13 +12,49 @@ type item =
let eol = '\n' | eof
let ext = '.' ['a'-'z' 'A'-'Z' '0'-'9']+
rule file = parse
| eof { [] }
| " $ " ([^'\n']* as str) eol { Command str :: file lexbuf }
| " " ([^'\n']* as str) eol { Output str :: file lexbuf }
| ([^'\n']* as str) eol { Comment str :: file lexbuf }
and postprocess tbl b = parse
| eof { Buffer.contents b }
| ([^ '/'] as c) (ext as e)
{ Buffer.add_char b c;
begin match List.assoc e tbl with
| res -> Buffer.add_string b res
| exception Not_found -> Buffer.add_string b e
end;
postprocess tbl b lexbuf
}
| _ as c { Buffer.add_char b c; postprocess tbl b lexbuf }
{
module Configurator = Configurator.V1
let make_ext_replace config =
let tbl =
let var = Configurator.ocaml_config_var_exn config in
let exts =
[ var "ext_dll", "$ext_dll"
; var "ext_asm", "$ext_asm"
; var "ext_lib", "$ext_lib"
; var "ext_obj", "$ext_obj"
] in
(* need to special case exe since we can only remove this extension in
general *)
match var "ext_exe" with
| "" -> exts
| ext -> (ext, "") :: exts
in
List.iter tbl ~f:(fun (e, _) -> assert (e <> ""));
fun s ->
let l = Lexing.from_string s in
postprocess tbl (Buffer.create (String.length s)) l
type version = int * int * int
let parse_version s =
@ -58,51 +94,53 @@ rule file = parse
let ocaml_version = ref None in
let skip_versions = ref [] in
let expect_test = ref None in
let usage = sprintf "%s [OPTIONS]" (Filename.basename Sys.executable_name) in
let anon s =
match !expect_test with
| None -> expect_test := Some s
| Some _ -> raise (Arg.Bad "test must only be given once") in
Arg.parse
let args =
[ "-ocamlv"
, Arg.String (fun s -> ocaml_version := Some (parse_version s))
, "Version of ocaml being used"
; "-skip-versions"
, Arg.String (fun s -> skip_versions := parse_skip_versions s)
, "Comma separated versions of ocaml where to skip test"
] anon usage;
let expect_test =
match !expect_test with
| None -> raise (Arg.Bad "expect test file must be passed")
| Some p -> p in
begin match !ocaml_version, !skip_versions with
| None, [] -> ()
| None, _::_ -> raise (Arg.Bad "provide -ocaml along with -skip-versions")
| Some v, skip ->
if List.exists skip ~f:(fun (op, v') -> test op v v') then exit 0
end;
Test_common.run_expect_test expect_test ~f:(fun file_contents lexbuf ->
let items = file lexbuf in
let temp_file = Filename.temp_file "jbuilder-test" ".output" in
at_exit (fun () -> Sys.remove temp_file);
let buf = Buffer.create (String.length file_contents + 1024) in
List.iter items ~f:(function
| Output _ -> ()
| Comment s -> Buffer.add_string buf s; Buffer.add_char buf '\n'
| Command s ->
Printf.bprintf buf " $ %s\n" s;
let fd = Unix.openfile temp_file [O_WRONLY; O_TRUNC] 0 in
let pid =
Unix.create_process "sh" [|"sh"; "-c"; s|] Unix.stdin fd fd
in
Unix.close fd;
let n =
match snd (Unix.waitpid [] pid) with
| WEXITED n -> n
| _ -> 255
in
List.iter (Io.lines_of_file temp_file) ~f:(fun line ->
Printf.bprintf buf " %s\n" (Ansi_color.strip line));
if n <> 0 then Printf.bprintf buf " [%d]\n" n);
Buffer.contents buf)
; "-test"
, Arg.String (fun s -> expect_test := Some s)
, "expect test file"
] in
Configurator.main ~args ~name:"cram" (fun configurator ->
let expect_test =
match !expect_test with
| None -> raise (Arg.Bad "expect test file must be passed")
| Some p -> p in
begin match !ocaml_version, !skip_versions with
| None, [] -> ()
| None, _::_ -> raise (Arg.Bad "provide -ocaml along with -skip-versions")
| Some v, skip ->
if List.exists skip ~f:(fun (op, v') -> test op v v') then exit 0
end;
Test_common.run_expect_test expect_test ~f:(fun file_contents lexbuf ->
let items = file lexbuf in
let temp_file = Filename.temp_file "jbuilder-test" ".output" in
at_exit (fun () -> Sys.remove temp_file);
let buf = Buffer.create (String.length file_contents + 1024) in
List.iter items ~f:(function
| Output _ -> ()
| Comment s -> Buffer.add_string buf s; Buffer.add_char buf '\n'
| Command s ->
Printf.bprintf buf " $ %s\n" s;
let fd = Unix.openfile temp_file [O_WRONLY; O_TRUNC] 0 in
let pid =
Unix.create_process "sh" [|"sh"; "-c"; s|] Unix.stdin fd fd
in
Unix.close fd;
let n =
match snd (Unix.waitpid [] pid) with
| WEXITED n -> n
| _ -> 255
in
let ext_replace = make_ext_replace configurator in
List.iter (Io.lines_of_file temp_file) ~f:(fun line ->
Printf.bprintf buf " %s\n"
(ext_replace (Ansi_color.strip line)));
if n <> 0 then Printf.bprintf buf " [%d]\n" n);
Buffer.contents buf)
)
}

View File

@ -2,7 +2,7 @@
(executable
((name cram)
(libraries (test_common jbuilder))))
(libraries (test_common jbuilder configurator))))
(ocamllex (cram))
@ -13,7 +13,7 @@
(action
(chdir test-cases/redirections
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -23,7 +23,7 @@
(action
(chdir test-cases/misc
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -33,7 +33,7 @@
(action
(chdir test-cases/github20
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -44,7 +44,7 @@
(chdir test-cases/js_of_ocaml
(setenv NODE ${bin:node}
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected)))))))
(alias
@ -54,7 +54,7 @@
(action
(chdir test-cases/github24
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -64,7 +64,7 @@
(action
(chdir test-cases/menhir
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -75,7 +75,7 @@
(chdir test-cases/github25/root
(setenv OCAMLPATH ../findlib-packages
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected)))))))
(alias
@ -85,7 +85,7 @@
(action
(chdir test-cases/lib-available
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -95,7 +95,7 @@
(action
(chdir test-cases/copy_files
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -105,7 +105,7 @@
(action
(chdir test-cases/aliases
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -115,7 +115,7 @@
(action
(chdir test-cases/force-test
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -125,7 +125,7 @@
(action
(chdir test-cases/meta-gen
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -135,7 +135,7 @@
(action
(chdir test-cases/exec-cmd
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -145,7 +145,7 @@
(action
(chdir test-cases/ocaml-syntax
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -155,7 +155,7 @@
(action
(chdir test-cases/gen-opam-install-file
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -165,7 +165,7 @@
(action
(chdir test-cases/reason
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -175,7 +175,8 @@
(action
(chdir test-cases/odoc
(progn
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t)
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3
-test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -185,7 +186,7 @@
(action
(chdir test-cases/select
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -195,7 +196,8 @@
(action
(chdir test-cases/multiple-private-libs
(progn
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t)
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3
-test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -205,7 +207,8 @@
(action
(chdir test-cases/ppx-rewriter
(progn
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t)
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3
-test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -215,7 +218,7 @@
(action
(chdir test-cases/utop
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -225,7 +228,7 @@
(action
(chdir test-cases/c-stubs
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -235,7 +238,7 @@
(action
(chdir test-cases/cross-compilation
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -245,7 +248,7 @@
(action
(chdir test-cases/promote
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -255,7 +258,7 @@
(action
(chdir test-cases/include-loop
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -265,7 +268,7 @@
(action
(chdir test-cases/scope-bug
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -275,7 +278,7 @@
(action
(chdir test-cases/scope-ppx-bug
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -285,7 +288,7 @@
(action
(chdir test-cases/loop
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -295,7 +298,7 @@
(action
(chdir test-cases/intf-only
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -305,7 +308,7 @@
(action
(chdir test-cases/installable-dup-private-libs
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -315,7 +318,7 @@
(action
(chdir test-cases/inline_tests
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -325,7 +328,7 @@
(action
(chdir test-cases/byte-code-only
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -335,7 +338,7 @@
(action
(chdir test-cases/merlin-tests
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -346,7 +349,7 @@
(chdir test-cases/findlib
(setenv OCAMLPATH findlib-packages
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected)))))))
(alias
@ -356,7 +359,8 @@
(action
(chdir test-cases/odoc-unique-mlds
(progn
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3 run.t)
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions 4.02.3
-test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -366,7 +370,7 @@
(action
(chdir test-cases/ocamldep-multi-stanzas
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -376,7 +380,7 @@
(action
(chdir test-cases/exclude-missing-module
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -386,7 +390,7 @@
(action
(chdir test-cases/github534
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -396,7 +400,7 @@
(action
(chdir test-cases/github568
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -407,7 +411,7 @@
(chdir test-cases/output-obj
(progn
(run ${exe:cram.exe} -ocamlv ${ocaml_version} -skip-versions <4.06.0
run.t)
-test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -417,7 +421,7 @@
(action
(chdir test-cases/github597
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -427,7 +431,7 @@
(action
(chdir test-cases/private-public-overlap
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -437,7 +441,7 @@
(action
(chdir test-cases/depend-on-the-universe
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -447,7 +451,7 @@
(action
(chdir test-cases/package-dep
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -457,7 +461,7 @@
(action
(chdir test-cases/github644
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -467,7 +471,7 @@
(action
(chdir test-cases/configurator
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -477,7 +481,7 @@
(action
(chdir test-cases/quoting
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -487,7 +491,7 @@
(action
(chdir test-cases/null-dep
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))
(alias
@ -497,5 +501,5 @@
(action
(chdir test-cases/github660
(progn
(run ${exe:cram.exe} run.t)
(run ${exe:cram.exe} -test run.t)
(diff? run.t run.t.corrected))))))

View File

@ -1,7 +1,7 @@
$ jbuilder exec ./qnativerun/run.exe --display short
ocamldep qnativerun/run.ml.d
ocamlc q/q_stub.o
ocamlmklib q/dllq_stubs.so,q/libq_stubs.a
ocamlc q/q_stub$ext_obj
ocamlmklib q/dllq_stubs$ext_dll,q/libq_stubs$ext_lib
ocamldep q/q.ml.d
ocamldep q/q.mli.d
ocamlc q/.q.objs/q.{cmi,cmti}

View File

@ -6,8 +6,8 @@
ocamlc .foo.objs/dummy.{cmi,cmo,cmt}
ocamlopt .foo.objs/dummy.{cmx,o}
ocamlopt foo.{a,cmxa}
ocamlc bar.o
ocamlmklib dllfoo_stubs.so,libfoo_stubs.a
ocamlc bar$ext_obj
ocamlmklib dllfoo_stubs$ext_dll,libfoo_stubs$ext_lib
ocamlc .test.eobjs/lexer1.{cmi,cmo,cmt}
ocamlopt .test.eobjs/lexer1.{cmx,o}
ocamlc .test.eobjs/test.{cmi,cmo,cmt}

View File

@ -33,7 +33,7 @@
"_build/install/default.foo/lib/p/p.ml" {"../../foo-sysroot/lib/p/p.ml"}
"_build/install/default.foo/lib/p/p.cma" {"../../foo-sysroot/lib/p/p.cma"}
"_build/install/default.foo/lib/p/p.cmxa" {"../../foo-sysroot/lib/p/p.cmxa"}
"_build/install/default.foo/lib/p/p.a" {"../../foo-sysroot/lib/p/p.a"}
"_build/install/default.foo/lib/p/p$ext_lib" {"../../foo-sysroot/lib/p/p$ext_lib"}
"_build/install/default.foo/lib/p/p.cmxs" {"../../foo-sysroot/lib/p/p.cmxs"}
"_build/install/default.foo/lib/p/p.dune" {"../../foo-sysroot/lib/p/p.dune"}
]

View File

@ -25,7 +25,7 @@
"_build/install/default/lib/foo/foo.ml" {"foo.ml"}
"_build/install/default/lib/foo/foo.cma" {"foo.cma"}
"_build/install/default/lib/foo/foo.cmxa" {"foo.cmxa"}
"_build/install/default/lib/foo/foo.a" {"foo.a"}
"_build/install/default/lib/foo/foo$ext_lib" {"foo$ext_lib"}
"_build/install/default/lib/foo/foo.cmxs" {"foo.cmxs"}
"_build/install/default/lib/foo/foo.js" {"foo.js"}
"_build/install/default/lib/foo/cfoo.h" {"cfoo.h"}

View File

@ -1,6 +1,6 @@
$ jbuilder build --display short --dev bin/technologic.bc.js @install lib/x.cma.js lib/x__Y.cmo.js bin/z.cmo.js
ocamlc lib/stubs.o
ocamlmklib lib/dllx_stubs.so,lib/libx_stubs.a
ocamlc lib/stubs$ext_obj
ocamlmklib lib/dllx_stubs$ext_dll,lib/libx_stubs$ext_lib
ocamlopt .ppx/js_of_ocaml-ppx/ppx.exe
ppx lib/x.pp.ml
ocamldep lib/x.pp.ml.d

View File

@ -8,7 +8,7 @@
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.
This warning will become an error in the future.
Multiple rules generated for _build/default/lib.o:
Multiple rules generated for _build/default/lib$ext_obj:
- <internal location>
- <internal location>
[1]