Make extensions portable in cram output
With some really ugly post processing
This commit is contained in:
parent
f8f1a4036e
commit
ab50461741
|
@ -12,13 +12,49 @@ type item =
|
||||||
|
|
||||||
let eol = '\n' | eof
|
let eol = '\n' | eof
|
||||||
|
|
||||||
|
let ext = '.' ['a'-'z' 'A'-'Z' '0'-'9']+
|
||||||
|
|
||||||
rule file = parse
|
rule file = parse
|
||||||
| eof { [] }
|
| eof { [] }
|
||||||
| " $ " ([^'\n']* as str) eol { Command str :: file lexbuf }
|
| " $ " ([^'\n']* as str) eol { Command str :: file lexbuf }
|
||||||
| " " ([^'\n']* as str) eol { Output str :: file lexbuf }
|
| " " ([^'\n']* as str) eol { Output str :: file lexbuf }
|
||||||
| ([^'\n']* as str) eol { Comment 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
|
type version = int * int * int
|
||||||
|
|
||||||
let parse_version s =
|
let parse_version s =
|
||||||
|
@ -58,51 +94,53 @@ rule file = parse
|
||||||
let ocaml_version = ref None in
|
let ocaml_version = ref None in
|
||||||
let skip_versions = ref [] in
|
let skip_versions = ref [] in
|
||||||
let expect_test = ref None in
|
let expect_test = ref None in
|
||||||
let usage = sprintf "%s [OPTIONS]" (Filename.basename Sys.executable_name) in
|
let args =
|
||||||
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
|
|
||||||
[ "-ocamlv"
|
[ "-ocamlv"
|
||||||
, Arg.String (fun s -> ocaml_version := Some (parse_version s))
|
, Arg.String (fun s -> ocaml_version := Some (parse_version s))
|
||||||
, "Version of ocaml being used"
|
, "Version of ocaml being used"
|
||||||
; "-skip-versions"
|
; "-skip-versions"
|
||||||
, Arg.String (fun s -> skip_versions := parse_skip_versions s)
|
, Arg.String (fun s -> skip_versions := parse_skip_versions s)
|
||||||
, "Comma separated versions of ocaml where to skip test"
|
, "Comma separated versions of ocaml where to skip test"
|
||||||
] anon usage;
|
; "-test"
|
||||||
let expect_test =
|
, Arg.String (fun s -> expect_test := Some s)
|
||||||
match !expect_test with
|
, "expect test file"
|
||||||
| None -> raise (Arg.Bad "expect test file must be passed")
|
] in
|
||||||
| Some p -> p in
|
Configurator.main ~args ~name:"cram" (fun configurator ->
|
||||||
begin match !ocaml_version, !skip_versions with
|
let expect_test =
|
||||||
| None, [] -> ()
|
match !expect_test with
|
||||||
| None, _::_ -> raise (Arg.Bad "provide -ocaml along with -skip-versions")
|
| None -> raise (Arg.Bad "expect test file must be passed")
|
||||||
| Some v, skip ->
|
| Some p -> p in
|
||||||
if List.exists skip ~f:(fun (op, v') -> test op v v') then exit 0
|
begin match !ocaml_version, !skip_versions with
|
||||||
end;
|
| None, [] -> ()
|
||||||
Test_common.run_expect_test expect_test ~f:(fun file_contents lexbuf ->
|
| None, _::_ -> raise (Arg.Bad "provide -ocaml along with -skip-versions")
|
||||||
let items = file lexbuf in
|
| Some v, skip ->
|
||||||
let temp_file = Filename.temp_file "jbuilder-test" ".output" in
|
if List.exists skip ~f:(fun (op, v') -> test op v v') then exit 0
|
||||||
at_exit (fun () -> Sys.remove temp_file);
|
end;
|
||||||
let buf = Buffer.create (String.length file_contents + 1024) in
|
Test_common.run_expect_test expect_test ~f:(fun file_contents lexbuf ->
|
||||||
List.iter items ~f:(function
|
let items = file lexbuf in
|
||||||
| Output _ -> ()
|
let temp_file = Filename.temp_file "jbuilder-test" ".output" in
|
||||||
| Comment s -> Buffer.add_string buf s; Buffer.add_char buf '\n'
|
at_exit (fun () -> Sys.remove temp_file);
|
||||||
| Command s ->
|
let buf = Buffer.create (String.length file_contents + 1024) in
|
||||||
Printf.bprintf buf " $ %s\n" s;
|
List.iter items ~f:(function
|
||||||
let fd = Unix.openfile temp_file [O_WRONLY; O_TRUNC] 0 in
|
| Output _ -> ()
|
||||||
let pid =
|
| Comment s -> Buffer.add_string buf s; Buffer.add_char buf '\n'
|
||||||
Unix.create_process "sh" [|"sh"; "-c"; s|] Unix.stdin fd fd
|
| Command s ->
|
||||||
in
|
Printf.bprintf buf " $ %s\n" s;
|
||||||
Unix.close fd;
|
let fd = Unix.openfile temp_file [O_WRONLY; O_TRUNC] 0 in
|
||||||
let n =
|
let pid =
|
||||||
match snd (Unix.waitpid [] pid) with
|
Unix.create_process "sh" [|"sh"; "-c"; s|] Unix.stdin fd fd
|
||||||
| WEXITED n -> n
|
in
|
||||||
| _ -> 255
|
Unix.close fd;
|
||||||
in
|
let n =
|
||||||
List.iter (Io.lines_of_file temp_file) ~f:(fun line ->
|
match snd (Unix.waitpid [] pid) with
|
||||||
Printf.bprintf buf " %s\n" (Ansi_color.strip line));
|
| WEXITED n -> n
|
||||||
if n <> 0 then Printf.bprintf buf " [%d]\n" n);
|
| _ -> 255
|
||||||
Buffer.contents buf)
|
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)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
((name cram)
|
((name cram)
|
||||||
(libraries (test_common jbuilder))))
|
(libraries (test_common jbuilder configurator))))
|
||||||
|
|
||||||
(ocamllex (cram))
|
(ocamllex (cram))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
$ jbuilder exec ./qnativerun/run.exe --display short
|
$ jbuilder exec ./qnativerun/run.exe --display short
|
||||||
ocamldep qnativerun/run.ml.d
|
ocamldep qnativerun/run.ml.d
|
||||||
ocamlc q/q_stub.o
|
ocamlc q/q_stub$ext_obj
|
||||||
ocamlmklib q/dllq_stubs.so,q/libq_stubs.a
|
ocamlmklib q/dllq_stubs$ext_dll,q/libq_stubs$ext_lib
|
||||||
ocamldep q/q.ml.d
|
ocamldep q/q.ml.d
|
||||||
ocamldep q/q.mli.d
|
ocamldep q/q.mli.d
|
||||||
ocamlc q/.q.objs/q.{cmi,cmti}
|
ocamlc q/.q.objs/q.{cmi,cmti}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
ocamlc .foo.objs/dummy.{cmi,cmo,cmt}
|
ocamlc .foo.objs/dummy.{cmi,cmo,cmt}
|
||||||
ocamlopt .foo.objs/dummy.{cmx,o}
|
ocamlopt .foo.objs/dummy.{cmx,o}
|
||||||
ocamlopt foo.{a,cmxa}
|
ocamlopt foo.{a,cmxa}
|
||||||
ocamlc bar.o
|
ocamlc bar$ext_obj
|
||||||
ocamlmklib dllfoo_stubs.so,libfoo_stubs.a
|
ocamlmklib dllfoo_stubs$ext_dll,libfoo_stubs$ext_lib
|
||||||
ocamlc .test.eobjs/lexer1.{cmi,cmo,cmt}
|
ocamlc .test.eobjs/lexer1.{cmi,cmo,cmt}
|
||||||
ocamlopt .test.eobjs/lexer1.{cmx,o}
|
ocamlopt .test.eobjs/lexer1.{cmx,o}
|
||||||
ocamlc .test.eobjs/test.{cmi,cmo,cmt}
|
ocamlc .test.eobjs/test.{cmi,cmo,cmt}
|
||||||
|
|
|
@ -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.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.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.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.cmxs" {"../../foo-sysroot/lib/p/p.cmxs"}
|
||||||
"_build/install/default.foo/lib/p/p.dune" {"../../foo-sysroot/lib/p/p.dune"}
|
"_build/install/default.foo/lib/p/p.dune" {"../../foo-sysroot/lib/p/p.dune"}
|
||||||
]
|
]
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
"_build/install/default/lib/foo/foo.ml" {"foo.ml"}
|
"_build/install/default/lib/foo/foo.ml" {"foo.ml"}
|
||||||
"_build/install/default/lib/foo/foo.cma" {"foo.cma"}
|
"_build/install/default/lib/foo/foo.cma" {"foo.cma"}
|
||||||
"_build/install/default/lib/foo/foo.cmxa" {"foo.cmxa"}
|
"_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.cmxs" {"foo.cmxs"}
|
||||||
"_build/install/default/lib/foo/foo.js" {"foo.js"}
|
"_build/install/default/lib/foo/foo.js" {"foo.js"}
|
||||||
"_build/install/default/lib/foo/cfoo.h" {"cfoo.h"}
|
"_build/install/default/lib/foo/cfoo.h" {"cfoo.h"}
|
||||||
|
|
|
@ -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
|
$ 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
|
ocamlc lib/stubs$ext_obj
|
||||||
ocamlmklib lib/dllx_stubs.so,lib/libx_stubs.a
|
ocamlmklib lib/dllx_stubs$ext_dll,lib/libx_stubs$ext_lib
|
||||||
ocamlopt .ppx/js_of_ocaml-ppx/ppx.exe
|
ocamlopt .ppx/js_of_ocaml-ppx/ppx.exe
|
||||||
ppx lib/x.pp.ml
|
ppx lib/x.pp.ml
|
||||||
ocamldep lib/x.pp.ml.d
|
ocamldep lib/x.pp.ml.d
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
each module cannot appear in more than one "modules" field - it must belong
|
each module cannot appear in more than one "modules" field - it must belong
|
||||||
to a single library or executable.
|
to a single library or executable.
|
||||||
This warning will become an error in the future.
|
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>
|
||||||
- <internal location>
|
- <internal location>
|
||||||
[1]
|
[1]
|
||||||
|
|
Loading…
Reference in New Issue