Unhardcode _build dir everywhere

This commit is contained in:
Rudi Grinberg 2018-04-25 18:22:48 +07:00
parent 4b2a609396
commit f44b8bdb1b
8 changed files with 25 additions and 14 deletions

View File

@ -728,7 +728,7 @@ let clean =
set_common common ~targets:[];
Build_system.files_in_source_tree_to_delete ()
|> List.iter ~f:Path.unlink_no_err;
Path.(rm_rf (append root (of_string "_build")))
Path.rm_rf Path.build_dir
end
in
( Term.(const go $ common)

View File

@ -647,10 +647,10 @@ module Promotion = struct
Io.copy_file ~src ~dst
end
let db_file = Path.of_string "_build/.to-promote"
let db_file = Path.relative_build_dir ".to-promote"
let dump_db db =
if Sys.file_exists "_build" then begin
if Path.build_dir_exists () then begin
match db with
| [] -> if Path.exists db_file then Path.unlink_no_err db_file
| l ->

View File

@ -14,7 +14,7 @@ let misc_dir = Path.(relative build_dir) ".misc"
module Promoted_to_delete = struct
let db = ref []
let fn = Path.of_string "_build/.to-delete-in-source-tree"
let fn = Path.relative_build_dir ".to-delete-in-source-tree"
let add p = db := p :: !db
@ -27,7 +27,7 @@ module Promoted_to_delete = struct
let dump () =
let db = Pset.union (Pset.of_list !db) (Pset.of_list (load ())) in
if Sys.file_exists "_build" then
if Path.build_dir_exists () then
Io.write_file fn
(String.concat ~sep:""
(List.map (Pset.to_list db) ~f:(fun p ->
@ -1106,7 +1106,7 @@ let stamp_file_for_files_of t ~dir ~ext =
module Trace = struct
type t = (Path.t, Digest.t) Hashtbl.t
let file = Path.of_string "_build/.db"
let file = Path.relative_build_dir ".db"
let dump (trace : t) =
let sexp =
@ -1118,7 +1118,7 @@ module Trace = struct
Sexp.List [ Path.sexp_of_t path;
Atom (Sexp.Atom.of_digest hash) ]))
in
if Sys.file_exists "_build" then
if Path.build_dir_exists () then
Io.write_file file (Sexp.to_string sexp)
let load () =
@ -1451,7 +1451,7 @@ let get_collector t ~dir =
(if Path.is_in_source_tree dir then
"Build_system.get_collector called on source directory"
else if dir = Path.build_dir then
"Build_system.get_collector called on _build"
"Build_system.get_collector called on build_dir"
else if not (Path.is_local dir) then
"Build_system.get_collector called on external directory"
else

View File

@ -8,7 +8,7 @@
- opam switch contexts, where one opam switch correspond to one context
each context is built into a sub-directory of "_build":
each context is built into a sub-directory of Path.build_dir (usually _build):
- _build/default for the default context
- _build/<switch> for other contexts

View File

@ -12,9 +12,8 @@ type t = real option
let no_log = None
let create ?(display=Config.default.display) () =
if not (Sys.file_exists "_build") then
Unix.mkdir "_build" 0o777;
let oc = Io.open_out (Path.of_string "_build/log") in
Path.ensure_build_dir_exists ();
let oc = Io.open_out (Path.relative_build_dir "log") in
Printf.fprintf oc "# %s\n# OCAMLPARAM: %s\n%!"
(String.concat (List.map (Array.to_list Sys.argv) ~f:quote_for_shell) ~sep:" ")
(match Env.get Env.initial "OCAMLPARAM" with

View File

@ -453,6 +453,12 @@ let unlink t =
unlink_operation (to_string t)
let unlink_no_err t = try unlink t with _ -> ()
let build_dir_exists () = is_directory build_dir
let ensure_build_dir_exists () = Local.mkdir_p build_dir
let relative_build_dir = relative build_dir
let extend_basename t ~suffix = t ^ suffix
let insert_after_build_dir_exn =

View File

@ -146,3 +146,9 @@ val extension : t -> string
val drop_prefix : t -> prefix:t -> string option
val pp : Format.formatter -> t -> unit
val build_dir_exists : unit -> bool
val ensure_build_dir_exists : unit -> unit
val relative_build_dir : string -> t

View File

@ -183,7 +183,7 @@ module Cached_digest = struct
let remove fn = Hashtbl.remove cache fn
let db_file = Path.of_string "_build/.digest-db"
let db_file = Path.relative_build_dir ".digest-db"
let dump () =
let module Pmap = Path.Map in
@ -199,7 +199,7 @@ module Cached_digest = struct
(Int64.bits_of_float file.timestamp))
]))
in
if Sys.file_exists "_build" then
if Path.build_dir_exists () then
Io.write_file db_file (Sexp.to_string sexp)
let load () =