114.20+69

This commit is contained in:
Jeremie Dimino 2016-12-15 16:54:46 +00:00
parent e054ce4d71
commit 405971694c
7 changed files with 72 additions and 25 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
_build _build
*.install *.install
jbuild boot.exe
jbuild.*

View File

@ -2,7 +2,7 @@ NAME := jbuilder
# Default rule # Default rule
default: default:
ocaml build.ml ocaml build.ml build-package jbuilder
install: install:
opam-installer -i --prefix $(PREFIX) jbuilder.install opam-installer -i --prefix $(PREFIX) jbuilder.install

View File

@ -2,3 +2,7 @@
((names (main)) ((names (main))
(libraries (unix jbuilder)) (libraries (unix jbuilder))
(preprocess no_preprocessing))) (preprocess no_preprocessing)))
(install
((section bin)
(files ((main.exe as jbuilder)))))

View File

@ -1,3 +1,4 @@
#warnings "-40";;
#load "unix.cma";; #load "unix.cma";;
module Array = ArrayLabels module Array = ArrayLabels
@ -14,8 +15,28 @@ open Printf
module String_set = Set.Make(String) module String_set = Set.Make(String)
(* Modules overriden to bootstrap faster *)
let overridden =
String_set.of_list
[ "Re_automata"
; "Re_cset"
; "Re_fmt"
; "Re"
; "Glob_lexer"
]
let ( ^/ ) = Filename.concat let ( ^/ ) = Filename.concat
let protectx x ~finally ~f =
match f x with
| y -> finally x; y
| exception e -> finally x; raise e
let starts_with s ~prefix =
let plen = String.length prefix in
let slen = String.length s in
slen >= plen && String.sub s ~pos:0 ~len:plen = prefix
let exec fmt = let exec fmt =
ksprintf (fun cmd -> ksprintf (fun cmd ->
print_endline cmd; print_endline cmd;
@ -56,7 +77,7 @@ let best_prog dir prog =
let fn = dir ^/ prog ^ ".opt" ^ exe in let fn = dir ^/ prog ^ ".opt" ^ exe in
if Sys.file_exists fn then if Sys.file_exists fn then
Some fn Some fn
else else
let fn = dir ^/ prog ^ exe in let fn = dir ^/ prog ^ exe in
if Sys.file_exists fn then if Sys.file_exists fn then
Some fn Some fn
@ -108,8 +129,13 @@ let modules =
match ext with match ext with
| "ml" | "mll" -> | "ml" | "mll" ->
let base = String.sub fn ~pos:0 ~len:i in let base = String.sub fn ~pos:0 ~len:i in
if ext = "mll" then run_ocamllex base; let mod_name = String.capitalize_ascii base in
String.capitalize_ascii base :: acc if String_set.mem mod_name overridden then
acc
else begin
if ext = "mll" then run_ocamllex base;
String.capitalize_ascii base :: acc
end
| _ -> | _ ->
acc) acc)
|> String_set.of_list |> String_set.of_list
@ -167,7 +193,7 @@ let topsort deps =
let n = List.length deps in let n = List.length deps in
let deps_by_module = Hashtbl.create n in let deps_by_module = Hashtbl.create n in
List.iter deps ~f:(fun (m, deps) -> List.iter deps ~f:(fun (m, deps) ->
Hashtbl.add deps_by_module m deps); Hashtbl.add deps_by_module m deps);
let not_seen = ref (List.map deps ~f:fst |> String_set.of_list) in let not_seen = ref (List.map deps ~f:fst |> String_set.of_list) in
let res = ref [] in let res = ref [] in
let rec loop m = let rec loop m =
@ -202,7 +228,7 @@ let read_file fn =
close_in ic; close_in ic;
data data
let generated_file = "jbuilder.ml" let generated_file = "boot.ml"
let generate_file_with_all_the_sources () = let generate_file_with_all_the_sources () =
let oc = open_out generated_file in let oc = open_out generated_file in
@ -229,6 +255,21 @@ let generate_file_with_all_the_sources () =
pos_in_generated_file := !pos_in_generated_file + newlines; pos_in_generated_file := !pos_in_generated_file + newlines;
pr "# %d %S" (!pos_in_generated_file + 1) generated_file pr "# %d %S" (!pos_in_generated_file + 1) generated_file
in in
let s = {|
module Re = struct
type t = unit
type re = unit
let compile () = ()
let execp _ _ = false
end
module Glob_lexer = struct
let parse_string _ = Error (0, "globs are not available during bootstrap")
end
|}
in
output_string oc s;
pos_in_generated_file := !pos_in_generated_file + count_newlines s;
pr "module Jbuilder = struct"; pr "module Jbuilder = struct";
List.iter modules ~f:(fun m -> List.iter modules ~f:(fun m ->
let base = String.uncapitalize m in let base = String.uncapitalize m in
@ -259,18 +300,21 @@ let () =
| Native -> "cmxa" | Native -> "cmxa"
| Byte -> "cma" | Byte -> "cma"
in in
exit (exec "%s -w -40 -o jbuilder unix.%s %s" compiler lib_ext generated_file) let n =
protectx ()
(* Alternative: ~f:(fun () ->
exec "%s -w -40 -o boot.exe unix.%s %s" compiler lib_ext generated_file)
{[ ~finally:(fun () ->
module Sys = struct try
include Sys Array.iter (Sys.readdir ".") ~f:(fun fn ->
let argv = [|"jbuilder"; "src/jbuilder.exe"|] if fn <> "boot.exe" && starts_with fn ~prefix:"boot." then
end;; Sys.remove fn)
with _ ->
#warnings "-40";; ())
#use "jbuilder.ml";; in
]} if n <> 0 then exit n
*)
let () =
exit
(exec "%s"
(String.concat ~sep:" " ("./boot.exe" :: (List.tl (Array.to_list Sys.argv)))))

View File

@ -1 +0,0 @@
bin: [ "jbuilder" ]

View File

@ -6,7 +6,7 @@ bug-reports: "https://github.com/janestreet/jbuilder/issues"
dev-repo: "https://github.com/janestreet/jbuilder.git" dev-repo: "https://github.com/janestreet/jbuilder.git"
license: "Apache-2.0" license: "Apache-2.0"
build: [ build: [
["ocaml" "build.ml"] ["ocaml" "build.ml" "build-package" "jbuilder" "-j" jobs]
] ]
depends: [ depends: [
] ]

View File

@ -1,7 +1,8 @@
;; This program must have no dependencies outside of the compiler ;; This program must have no dependencies outside of the compiler
;; distribution as it is used to build all of Jane Street packages ;; distribution as it is used to build all of Jane Street packages
(library (library
((name jbuilder) ((name jbuilder)
(public_name jbuilder)
(libraries (unix)) (libraries (unix))
(preprocess no_preprocessing))) (preprocess no_preprocessing)))