Don't use unix in bootstrap.ml

This commit is contained in:
Jeremie Dimino 2017-05-24 14:21:02 +01:00
parent f994c4690e
commit cf121d3640
2 changed files with 35 additions and 30 deletions

View File

@ -4,6 +4,8 @@
- Fix a bug where `jbuild rules` would crash instead of reporting a
proper build error
- Don't use unix in the bootstrap script, to avoid surprises with
Cygwin
1.0+beta9 (19/05/2017)
----------------------

View File

@ -1,5 +1,4 @@
#warnings "-40";;
#load "unix.cma";;
module Array = ArrayLabels
module List = ListLabels
@ -157,37 +156,41 @@ let split_words s =
in
skip_blanks 0
let read_lines fn =
let ic = open_in fn in
let rec loop ic acc =
match try Some (input_line ic) with End_of_file -> None with
| Some line -> loop ic (line :: acc)
| None -> List.rev acc
in
let lines = loop ic [] in
close_in ic;
lines
let read_deps files =
let ic =
let cmd =
sprintf "%s -modules %s"
ocamldep (String.concat ~sep:" " files)
let tmp_fn = Filename.temp_file "jbuilder-ocamldep-output" ".txt" in
at_exit (fun () -> Sys.remove tmp_fn);
let n =
exec "%s -modules %s > %s"
(Filename.quote ocamldep)
(String.concat ~sep:" " (List.map files ~f:Filename.quote))
(Filename.quote tmp_fn)
in
if n <> 0 then exit n;
List.map (read_lines tmp_fn) ~f:(fun line ->
let i = String.index line ':' in
let unit =
String.sub line ~pos:0 ~len:i
|> Filename.basename
|> Filename.chop_extension
|> String.capitalize_ascii
in
print_endline cmd;
Unix.open_process_in cmd
in
set_binary_mode_in ic false;
let rec loop acc =
match input_line ic with
| exception End_of_file ->
ignore (Unix.close_process_in ic);
acc
| line ->
let i = String.index line ':' in
let unit =
String.sub line ~pos:0 ~len:i
|> Filename.basename
|> Filename.chop_extension
|> String.capitalize_ascii
in
let deps =
split_words (String.sub line ~pos:(i + 1)
~len:(String.length line - (i + 1)))
|> List.filter ~f:(fun m -> String_set.mem m modules)
in
loop ((unit, deps) :: acc)
in
loop []
let deps =
split_words (String.sub line ~pos:(i + 1)
~len:(String.length line - (i + 1)))
|> List.filter ~f:(fun m -> String_set.mem m modules)
in
(unit, deps))
let topsort deps =
let n = List.length deps in