|
22 | 22 | * along with this program; if not, write to the Free Software |
23 | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) |
24 | 24 |
|
25 | | -let (//) = Ext_path.combine |
| 25 | +let ( // ) = Ext_path.combine |
26 | 26 |
|
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | -let handle_generators oc |
33 | | - (group : Bsb_file_groups.file_group) |
34 | | - custom_rules = |
35 | | - let map_to_source_dir = |
36 | | - (fun x -> Bsb_config.proj_rel (group.dir //x )) in |
37 | | - Ext_list.iter group.generators (fun {output; input; command} -> |
| 27 | +let handle_generators oc (group : Bsb_file_groups.file_group) custom_rules = |
| 28 | + let map_to_source_dir x = Bsb_config.proj_rel (group.dir // x) in |
| 29 | + Ext_list.iter group.generators (fun { output; input; command } -> |
38 | 30 | (*TODO: add a loc for better error message *) |
39 | 31 | match Map_string.find_opt custom_rules command with |
40 | | - | None -> Ext_fmt.failwithf ~loc:__LOC__ "custom rule %s used but not defined" command |
| 32 | + | None -> |
| 33 | + Ext_fmt.failwithf ~loc:__LOC__ "custom rule %s used but not defined" |
| 34 | + command |
41 | 35 | | Some rule -> |
42 | | - Bsb_ninja_targets.output_build oc |
43 | | - ~outputs:(Ext_list.map output map_to_source_dir) |
44 | | - ~inputs:(Ext_list.map input map_to_source_dir) |
45 | | - ~rule |
46 | | - ) |
47 | | - |
48 | | - |
49 | | -let make_common_shadows |
50 | | - package_specs |
51 | | - dirname |
52 | | - dir_index |
53 | | - : Bsb_ninja_targets.shadow list |
54 | | - = |
55 | | - |
56 | | - { key = Bsb_ninja_global_vars.g_pkg_flg; |
57 | | - op = |
58 | | - Append |
59 | | - (Bsb_package_specs.package_flag_of_package_specs |
60 | | - package_specs dirname |
61 | | - ) |
62 | | - } :: |
63 | | - (if Bsb_dir_index.is_lib_dir dir_index then [] else |
64 | | - [ |
65 | | - { key = Bsb_ninja_global_vars.g_dev_incls; |
66 | | - op = OverwriteVar (Bsb_dir_index.string_of_bsb_dev_include dir_index); |
67 | | - } |
68 | | - ] |
69 | | - ) |
70 | | - |
71 | | - |
72 | | - |
73 | | -let emit_module_build |
74 | | - (rules : Bsb_ninja_rule.builtin) |
75 | | - (package_specs : Bsb_package_specs.t) |
76 | | - (group_dir_index : Bsb_dir_index.t) |
77 | | - oc |
78 | | - ~bs_suffix |
79 | | - js_post_build_cmd |
80 | | - namespace |
81 | | - (module_info : Bsb_db.module_info) |
82 | | - = |
| 36 | + Bsb_ninja_targets.output_build oc |
| 37 | + ~outputs:(Ext_list.map output map_to_source_dir) |
| 38 | + ~inputs:(Ext_list.map input map_to_source_dir) |
| 39 | + ~rule) |
| 40 | + |
| 41 | + |
| 42 | +let make_common_shadows package_specs dirname dir_index : |
| 43 | + Bsb_ninja_targets.shadow list = |
| 44 | + { |
| 45 | + key = Bsb_ninja_global_vars.g_pkg_flg; |
| 46 | + op = |
| 47 | + Append |
| 48 | + (Bsb_package_specs.package_flag_of_package_specs package_specs dirname); |
| 49 | + } |
| 50 | + :: |
| 51 | + ( if Bsb_dir_index.is_lib_dir dir_index then [] |
| 52 | + else |
| 53 | + [ |
| 54 | + { |
| 55 | + key = Bsb_ninja_global_vars.g_dev_incls; |
| 56 | + op = OverwriteVar (Bsb_dir_index.string_of_bsb_dev_include dir_index); |
| 57 | + }; |
| 58 | + ] ) |
| 59 | + |
| 60 | + |
| 61 | +let emit_module_build (rules : Bsb_ninja_rule.builtin) |
| 62 | + (package_specs : Bsb_package_specs.t) (group_dir_index : Bsb_dir_index.t) oc |
| 63 | + ~bs_suffix js_post_build_cmd namespace (module_info : Bsb_db.module_info) = |
83 | 64 | let has_intf_file = module_info.info = Ml_mli in |
84 | 65 | let is_re = module_info.is_re in |
85 | 66 | let filename_sans_extension = module_info.name_sans_extension in |
86 | 67 | let is_dev = not (Bsb_dir_index.is_lib_dir group_dir_index) in |
87 | 68 | let input_impl = |
88 | 69 | Bsb_config.proj_rel |
89 | | - (filename_sans_extension ^ if is_re then Literals.suffix_re else Literals.suffix_ml ) in |
| 70 | + ( filename_sans_extension |
| 71 | + ^ if is_re then Literals.suffix_re else Literals.suffix_ml ) |
| 72 | + in |
90 | 73 | let input_intf = |
91 | 74 | Bsb_config.proj_rel |
92 | | - (filename_sans_extension ^ if is_re then Literals.suffix_rei else Literals.suffix_mli) in |
| 75 | + ( filename_sans_extension |
| 76 | + ^ if is_re then Literals.suffix_rei else Literals.suffix_mli ) |
| 77 | + in |
93 | 78 | let output_mlast = |
94 | | - filename_sans_extension ^ if is_re then Literals.suffix_reast else Literals.suffix_mlast in |
| 79 | + filename_sans_extension |
| 80 | + ^ if is_re then Literals.suffix_reast else Literals.suffix_mlast |
| 81 | + in |
95 | 82 | let output_mliast = |
96 | | - filename_sans_extension ^ if is_re then Literals.suffix_reiast else Literals.suffix_mliast in |
| 83 | + filename_sans_extension |
| 84 | + ^ if is_re then Literals.suffix_reiast else Literals.suffix_mliast |
| 85 | + in |
97 | 86 | let output_d = filename_sans_extension ^ Literals.suffix_d in |
98 | 87 | let output_filename_sans_extension = |
99 | | - Ext_namespace.make ?ns:namespace filename_sans_extension |
| 88 | + Ext_namespace.make ?ns:namespace filename_sans_extension |
100 | 89 | in |
101 | | - let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in |
102 | | - let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in |
| 90 | + let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in |
| 91 | + let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in |
103 | 92 | let output_js = |
104 | | - Bsb_package_specs.get_list_of_output_js package_specs bs_suffix output_filename_sans_extension in |
| 93 | + Bsb_package_specs.get_list_of_output_js package_specs bs_suffix |
| 94 | + output_filename_sans_extension |
| 95 | + in |
105 | 96 | let common_shadows = |
106 | 97 | make_common_shadows package_specs |
107 | 98 | (Filename.dirname output_cmi) |
108 | | - group_dir_index in |
109 | | - let ast_rule = |
110 | | - if is_re then |
111 | | - rules.build_ast_from_re |
112 | | - else |
113 | | - rules.build_ast in |
114 | | - Bsb_ninja_targets.output_build oc |
115 | | - ~outputs:[output_mlast] |
116 | | - ~inputs:[input_impl] |
117 | | - ~rule:ast_rule; |
118 | | - Bsb_ninja_targets.output_build |
119 | | - oc |
120 | | - ~outputs:[output_d] |
121 | | - ~inputs:(if has_intf_file then [output_mlast;output_mliast] else [output_mlast] ) |
| 99 | + group_dir_index |
| 100 | + in |
| 101 | + let ast_rule = if is_re then rules.build_ast_from_re else rules.build_ast in |
| 102 | + Bsb_ninja_targets.output_build oc ~outputs:[ output_mlast ] |
| 103 | + ~inputs:[ input_impl ] ~rule:ast_rule; |
| 104 | + Bsb_ninja_targets.output_build oc ~outputs:[ output_d ] |
| 105 | + ~inputs: |
| 106 | + ( if has_intf_file then [ output_mlast; output_mliast ] |
| 107 | + else [ output_mlast ] ) |
122 | 108 | ~rule:rules.build_bin_deps |
123 | | - ?shadows:(if is_dev then |
124 | | - Some [{Bsb_ninja_targets.key = Bsb_build_schemas.bsb_dir_group ; |
125 | | - op = |
126 | | - Overwrite (string_of_int (group_dir_index :> int)) }] |
127 | | - else None) |
128 | | - ; |
129 | | - if has_intf_file then begin |
| 109 | + ?shadows: |
| 110 | + ( if is_dev then |
| 111 | + Some |
| 112 | + [ |
| 113 | + { |
| 114 | + Bsb_ninja_targets.key = Bsb_build_schemas.bsb_dir_group; |
| 115 | + op = Overwrite (string_of_int (group_dir_index :> int)); |
| 116 | + }; |
| 117 | + ] |
| 118 | + else None ); |
| 119 | + if has_intf_file then ( |
130 | 120 | Bsb_ninja_targets.output_build oc |
131 | | - ~outputs:[output_mliast] |
132 | | - (* TODO: we can get rid of absloute path if we fixed the location to be |
133 | | - [lib/bs], better for testing? |
134 | | - *) |
135 | | - ~inputs:[input_intf] |
136 | | - ~rule:ast_rule |
137 | | - ; |
138 | | - Bsb_ninja_targets.output_build oc |
139 | | - ~outputs:[output_cmi] |
140 | | - ~shadows:common_shadows |
141 | | - ~order_only_deps:[output_d] |
142 | | - ~inputs:[output_mliast] |
143 | | - ~rule:(if is_dev then rules.ml_cmi_dev else rules.ml_cmi) |
144 | | - ; |
145 | | - end; |
| 121 | + ~outputs: |
| 122 | + [ output_mliast ] |
| 123 | + (* TODO: we can get rid of absloute path if we fixed the location to be |
| 124 | + [lib/bs], better for testing? *) |
| 125 | + ~inputs:[ input_intf ] ~rule:ast_rule; |
| 126 | + Bsb_ninja_targets.output_build oc ~outputs:[ output_cmi ] |
| 127 | + ~shadows:common_shadows ~order_only_deps:[ output_d ] |
| 128 | + ~inputs:[ output_mliast ] |
| 129 | + ~rule:(if is_dev then rules.ml_cmi_dev else rules.ml_cmi) ); |
146 | 130 |
|
147 | 131 | let shadows = |
148 | 132 | match js_post_build_cmd with |
149 | 133 | | None -> common_shadows |
150 | 134 | | Some cmd -> |
151 | | - {key = Bsb_ninja_global_vars.postbuild; |
152 | | - op = Overwrite ("&& " ^ cmd ^ Ext_string.single_space ^ String.concat Ext_string.single_space output_js)} |
153 | | - :: common_shadows |
| 135 | + { |
| 136 | + key = Bsb_ninja_global_vars.postbuild; |
| 137 | + op = |
| 138 | + Overwrite |
| 139 | + ( "&& " ^ cmd ^ Ext_string.single_space |
| 140 | + ^ String.concat Ext_string.single_space output_js ); |
| 141 | + } |
| 142 | + :: common_shadows |
154 | 143 | in |
155 | 144 | let rule = |
156 | 145 | if has_intf_file then |
157 | | - (if is_dev then rules.ml_cmj_js_dev |
158 | | - else rules.ml_cmj_js) |
159 | | - else |
160 | | - (if is_dev then rules.ml_cmj_cmi_js_dev |
161 | | - else rules.ml_cmj_cmi_js |
162 | | - ) |
| 146 | + if is_dev then rules.ml_cmj_js_dev else rules.ml_cmj_js |
| 147 | + else if is_dev then rules.ml_cmj_cmi_js_dev |
| 148 | + else rules.ml_cmj_cmi_js |
163 | 149 | in |
164 | | - Bsb_ninja_targets.output_build oc |
165 | | - ~outputs:[output_cmj] |
166 | | - ~shadows |
| 150 | + Bsb_ninja_targets.output_build oc ~outputs:[ output_cmj ] ~shadows |
167 | 151 | ~implicit_outputs: |
168 | | - (if has_intf_file then output_js else output_cmi::output_js ) |
169 | | - ~inputs:[output_mlast] |
170 | | - ~implicit_deps:(if has_intf_file then [output_cmi] else [] ) |
171 | | - ~order_only_deps:[output_d] |
172 | | - ~rule |
173 | | - (* ; |
174 | | - {output_cmj; output_cmi} *) |
175 | | - |
| 152 | + (if has_intf_file then output_js else output_cmi :: output_js) |
| 153 | + ~inputs:[ output_mlast ] |
| 154 | + ~implicit_deps:(if has_intf_file then [ output_cmi ] else []) |
| 155 | + ~order_only_deps:[ output_d ] ~rule |
176 | 156 |
|
177 | 157 |
|
178 | | - |
179 | | - |
180 | | - |
181 | | -let handle_files_per_dir |
182 | | - oc |
183 | | - ~bs_suffix |
184 | | - ~(rules : Bsb_ninja_rule.builtin) |
185 | | - ~package_specs |
186 | | - ~js_post_build_cmd |
187 | | - ~(files_to_install : Hash_set_string.t) |
188 | | - ~(namespace : string option) |
189 | | - (group: Bsb_file_groups.file_group ) |
190 | | - : unit = |
191 | | - |
192 | | - handle_generators oc group rules.customs ; |
| 158 | +let handle_files_per_dir oc ~bs_suffix ~(rules : Bsb_ninja_rule.builtin) |
| 159 | + ~package_specs ~js_post_build_cmd ~(files_to_install : Hash_set_string.t) |
| 160 | + ~(namespace : string option) (group : Bsb_file_groups.file_group) : unit = |
| 161 | + handle_generators oc group rules.customs; |
193 | 162 | let installable = |
194 | 163 | match group.public with |
195 | 164 | | Export_all -> fun _ -> true |
196 | 165 | | Export_none -> fun _ -> false |
197 | | - | Export_set set -> |
198 | | - fun module_name -> |
199 | | - Set_string.mem set module_name in |
200 | | - Map_string.iter group.sources (fun module_name module_info -> |
| 166 | + | Export_set set -> fun module_name -> Set_string.mem set module_name |
| 167 | + in |
| 168 | + Map_string.iter group.sources (fun module_name module_info -> |
201 | 169 | if installable module_name then |
202 | | - Hash_set_string.add files_to_install |
203 | | - module_info.name_sans_extension; |
204 | | - emit_module_build rules |
205 | | - package_specs |
206 | | - group.dir_index |
207 | | - oc |
208 | | - ~bs_suffix |
209 | | - js_post_build_cmd |
210 | | - namespace module_info |
211 | | - ) |
212 | | - |
213 | | - (* ; |
214 | | - Bsb_ninja_targets.phony |
215 | | - oc ~order_only_deps:[] ~inputs:[] ~output:group.dir *) |
| 170 | + Hash_set_string.add files_to_install module_info.name_sans_extension; |
| 171 | + emit_module_build rules package_specs group.dir_index oc ~bs_suffix |
| 172 | + js_post_build_cmd namespace module_info) |
216 | 173 |
|
217 | | - (* pseuduo targets per directory *) |
| 174 | +(* pseuduo targets per directory *) |
0 commit comments