X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=tools%2Fwhenjobs.ml;h=440d4251bc1fd290308a685829531f0e0f91125e;hb=9f7c94086330deb1c6dc0c51355a60b19ff78055;hp=9449abca2f446e593dd9c80715a828f568f97d93;hpb=77707acb12b5424488757569f376e1d9b58e5a22;p=whenjobs.git diff --git a/tools/whenjobs.ml b/tools/whenjobs.ml index 9449abc..440d425 100644 --- a/tools/whenjobs.ml +++ b/tools/whenjobs.ml @@ -307,12 +307,28 @@ and list_file () = close_in chan and upload_file () = + let suffix = if not Config.have_ocamlopt then "cmo" else "cmx" in + (* Recompile the jobs file(s). *) let files = get_multijobs_filenames () in + + (* Choose a random name for the output file. time_t is convenient. + * See: https://sympa-roc.inria.fr/wws/arc/caml-list/2012-03/msg00276.html?checked_cas=2 + *) + let t = Int64.of_float (time ()) in + + (* Compilation step. *) List.iter ( fun file -> - let cmd = sprintf "ocamlfind ocamlc -I +camlp4 -I %s -package unix,camlp4.lib -pp 'camlp4o %s/pa_when.cmo' -c %s" - !libdir !libdir file in + let cmd = + if not Config.have_ocamlopt then + (* bytecode *) + sprintf "%s c -for-pack Jobs__%Ld -I +camlp4 -I %s -package unix,camlp4.lib -pp 'camlp4o %s/pa_when.cmo' -c %s" + Config.ocamlfind t !libdir !libdir file + else + (* native code *) + sprintf "%s opt -for-pack Jobs__%Ld -I +camlp4 -I %s -package unix,camlp4.lib -pp 'camlp4o %s/pa_when.cmo' -c %s" + Config.ocamlfind t !libdir !libdir file in if Sys.command cmd <> 0 then ( eprintf "whenjobs: %s: could not compile jobs script, see earlier errors\n" file; @@ -321,25 +337,46 @@ and upload_file () = ) ) files; - let cmo_files = List.map ( - fun file -> - let n = String.length file in - if n < 4 then assert false; - String.sub file 0 (n-3) ^ ".cmo" - ) files in + (* Pack into a single file. *) + let filename = sprintf "%s/jobs__%Ld.%s" jobsdir t suffix in + let cmd = + let objects = List.map ( + fun file -> + let base = Filename.chop_extension file in + base ^ if not Config.have_ocamlopt then ".cmo" else ".cmx" + ) files in + sprintf "%s %s -pack -o %s %s" + Config.ocamlfind + (if not Config.have_ocamlopt then "c" else "opt") + filename (String.concat " " objects) in + if Sys.command cmd <> 0 then ( + eprintf "whenjobs: could not pack jobs script, see earlier errors\n"; + eprintf "compile command was:\n%s\n" cmd; + exit 1 + ); + + (* For native code only, write a *.cmxs file. *) + let filename = + if Config.have_ocamlopt then ( + let cmd = sprintf "%s opt -shared -linkall %s -o %ss" + Config.ocamlfind filename filename in + if Sys.command cmd <> 0 then ( + eprintf "whenjobs: could not convert to *.cmxs, see earlier errors\n"; + eprintf "compile command was:\n%s\n" cmd; + exit 1 + ); + filename ^ "s" (* .cmx -> .cmxs *) + ) + else filename in (* Test-load the jobs files to ensure they make sense. *) Whenfile.init Whenstate.empty; - (try - List.iter Dynlink.loadfile cmo_files + (try Dynlink.loadfile filename with Dynlink.Error err -> - eprintf "whenjobs: %s\n" (Dynlink.error_message err); - (* Since it failed, unlink the cmo files. *) - List.iter ( - fun cmo_file -> - (try unlink cmo_file with Unix_error _ -> ()) - ) cmo_files; + eprintf "whenjobs: dynlink: %s\n" (Dynlink.error_message err); + (* Since it failed, unlink the compiled file. *) + (try unlink filename with Unix_error _ -> ()); exit 1 ); @@ -571,11 +608,7 @@ and get_jobs_filename () = and get_multijobs_filenames () = (* Get dir/*.ml *) let files = Array.to_list (Sys.readdir jobsdir) in - let files = List.filter ( - fun file -> - let n = String.length file in - n >= 4 && String.sub file (n-3) 3 = ".ml" - ) files in + let files = List.filter (fun file -> string_endswith file ".ml") files in let files = List.map (fun file -> jobsdir // file) files in List.sort compare files