-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathbsb_ninja_regen.ml
100 lines (93 loc) · 4.33 KB
/
bsb_ninja_regen.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let bsdeps = ".bsdeps"
let ( // ) = Ext_path.combine
(** Regenerate ninja file by need based on [.bsdeps]
return None if we dont need regenerate
otherwise return Some info
*)
let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir ~warn_legacy_config ~warn_as_error
: Bsb_config_types.t option =
let lib_artifacts_dir = Bsb_config.lib_bs in
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
let output_deps = lib_bs_dir // bsdeps in
let check_result =
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~file:output_deps
in
let config_filename, config_json =
Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config
in
match check_result with
| Good -> None (* Fast path, no need regenerate ninja *)
| Bsb_forced | Bsb_bsc_version_mismatch | Bsb_package_kind_inconsistent
| Bsb_file_corrupted | Bsb_file_not_exist | Bsb_source_directory_changed
| Other _ ->
Bsb_log.info "@{<info>BSB check@} build spec : %a @."
Bsb_ninja_check.pp_check_result check_result;
if check_result = Bsb_bsc_version_mismatch then (
Bsb_log.warn
"@{<info>Different compiler version@}: clean current repo@.";
Bsb_clean.clean_bs_deps per_proj_dir;
Bsb_clean.clean_self per_proj_dir);
let config : Bsb_config_types.t =
Bsb_config_parse.interpret_json
~filename:config_filename ~json:config_json ~package_kind ~per_proj_dir
in
let warning = match config.warning with
| None -> (
match warn_as_error with
| Some e -> Some {Bsb_warning.number = Some e; error = Warn_error_number e}
| None -> None)
| Some {error} as t ->
match (warn_as_error, error) with
| (Some error_str, Warn_error_false) ->
Some {number = Some error_str; error = Warn_error_number error_str}
| (Some error_str, Warn_error_number prev) ->
let new_error = prev ^ error_str in
Some {number = Some new_error; error = Warn_error_number new_error}
| _ -> t
in
let config = {config with warning = warning} in
(* create directory, lib/bs, lib/js, lib/es6 etc *)
Bsb_build_util.mkp lib_bs_dir;
Bsb_package_specs.list_dirs_by config.package_specs (fun x ->
let dir = per_proj_dir // x in
(*Unix.EEXIST error*)
if not (Sys.file_exists dir) then Unix.mkdir dir 0o777);
(match package_kind with
| Toplevel ->
Bsb_watcher_gen.generate_sourcedirs_meta
~name:(lib_bs_dir // Literals.sourcedirs_meta)
config.file_groups
| Pinned_dependency _ (* FIXME: seems need to be watched *) | Dependency _
->
());
Bsb_ninja_gen.output_ninja_and_namespace_map ~per_proj_dir ~package_kind
config;
(* PR2184: we still need record empty dir
since it may add files in the future *)
Bsb_ninja_check.record ~package_kind ~per_proj_dir ~config
~file:output_deps
(config.filename :: config.file_groups.globbed_dirs);
Some config