Skip to content
This repository
Newer
Older
100644 818 lines (726 sloc) 30.102 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* ------------------------------------------------------------ *)
19 (* Tags, flags, directory contexts and custom stuff *)
20 (* ------------------------------------------------------------ *)
21
22 (* -- Directory contexts -- *)
23
24 shared_namespace_dir "libqmlcompil";
25 shared_namespace_dir "database";
26 shared_namespace_dir "opa";
27 include_subdirs "opalib";
28 shared_namespace_dir "opalang";
29 shared_namespace_dir "appruntime";
30 shared_namespace_dir "libnet";
31 include_subdirs "qmlflat";
32
33 (* -- Stubs -- *)
34
35 def_stubs ~dir:"libbase" "stubs";
36 def_stubs ~dir:"libsecurity" "ssl_ext";
37 def_stubs ~dir:"appruntime" "io";
38
39 let root_ocamldir = Config.ocamllib in
40
41 let is_release () = Config.is_release in
42
43 let link_cmd = if windows_mode then S[Sh"cp";A"-r"] else S[Sh"ln";A"-s";A"-f"] in
44
45 let extralib_opt = function
46 | Some (lib,ldir,idir) ->
47 flag ["link"; "use_"^lib] (S [A "-ccopt"; P ("-L" ^ ldir); A"-cclib"; A ("-l" ^ lib)]);
48 flag ["compile"; "c"; "use_"^lib] (S [A"-I"; P idir])
49 | None -> ()
50 in
51 extralib_opt Config.libnatpmp;
52 extralib_opt Config.miniupnpc;
53
54
55 begin
56 match Config.camlidl with
57 | None -> ()
58 | Some camlidl ->
59 flag ["link"; "use_camlidl"] (S [A "-cclib"; P "-lcamlidl" ]);
60
61 rule "camlidl processing: .idl -> .ml .mli _stubs.c lib_stubs.clib"
62 ~deps:[ "%(dir)stubs%(name).idl" ]
63 ~prods:[ "%(dir:<**/>)stubs%(name:<*> and not <*.*> and not <>).mli";
64 "%(dir:<**/>)stubs%(name:<*> and not <*.*> and not <>).ml" ;
65 "%(dir:<**/>)stubs%(name:<*> and not <*.*> and not <>)_stubs.c" ]
66 ~insert:`top
67 (fun env _build ->
68 let dir = env "%(dir)" in
69 let name = env "%(name)" in
70
71 def_stubs ~dir (name ^ "_idl");
72
73 Cmd(S[Sh"cd"; P dir; Sh"&&";
74 P camlidl; A"-prepro"; P"/usr/bin/cpp"; A"-no-include"; P ("stubs" ^ name -.- "idl") ])
75 )
76 end;
77
78 (* -- Ocamldoc plugin -- *)
79
80 flag_and_dep ["ocaml"; "doc"] (S[A"-g";P"utils/ocamldoc_plugin.cmxs"]);
81
82 (* ------------------------------------------------------------ *)
83 (* Hacks *)
84 (* ------------------------------------------------------------ *)
85
86 (* opatop needs to link its serverLib *then* opabsl *then* the rest. We
87 cheat by copying the opabsl generated files so that they can be seen as
88 local by opatop. *)
89 let magic_import_from_opabsl dest f =
90 rule ("import from opabsl: "^f) ~deps:["opabsl/"^f] ~prod:(dest / f)
91 (fun env build ->
92 Seq[Cmd(S[Sh"mkdir";A"-p";P dest]);
93 if Pathname.exists "opabsl"
94 then (build_list build ["opabsl" / f]; cp ("opabsl"/ f) dest)
95 else cp (mlstatelibs/"opabsl"/ f) dest
96 ])
97 in
98 List.iter
99 (fun m -> magic_import_from_opabsl "opatop" (m ^ ".ml"))
100 [ "opabslgenMLRuntime"; "opabslgenLoader" ];
101
102
103 (* ------------------------------------------------------------ *)
104 (* Additional rules: internal *)
105 (* ------------------------------------------------------------ *)
106
107 (* -- static ppdebug -- *)
108 (* what happens here is:
109 * - generate the file _build/environment containing the environment vars used by ppdebug
110 * - make files tagged with with_static_proprecessing depend on _build/environment
111 * - tag any ml file containing some static ppdebug with the tag with_static_proprecessing
112 *)
113
114 let static_ppdebug_vars = [
115 "CPS_WITH_ML_CLOSURE"; (* disable the use of qml closures in cps continuations
116 * (for performance reasons) *)
117 "CPS_STACK_SIZE" ; (* observe the size of the stack @ cps return *)
118 ] in
119 let environment = "environment" in
120 let build_env_strings =
121 (List.map
122 (fun s ->
123 Printf.sprintf "let %s = %s\n"
124 s (try Printf.sprintf "Some %S" (Sys.getenv s)
125 with Not_found -> "None")
126 ) static_ppdebug_vars) in
127 dep ["with_static_preprocessing"] [environment];
128
129 rule "environment generation"
130 ~prods:[environment;"i_dont_exist"](* fake prod to make sure this rule is
131 * always called *)
132 (fun env build ->
133 Echo (build_env_strings, environment));
134
135 let generate_ocamldep_rule ml_or_mli =
136 rule ("ocaml dependencies " ^ ml_or_mli ^ " reloaded (deps of static ppdebug)")
137 ~prod:("%." ^ ml_or_mli ^ ".depends")
138 ~dep:("%." ^ ml_or_mli)
139 ~insert:`top (* need to be inserted before the real ocamldep rule *)
140 (fun env build ->
141 let ml = env "%." ^ ml_or_mli in
142 if Tags.mem "with_mlstate_debug" (tags_of_pathname ml) &&
143 Sys.command ("grep -q '#<Ifstatic:' " ^ Pathname.to_string ml) = 0
144 then
145 tag_file ml ["with_static_preprocessing"];
146 fail_rule build (* failing to that ocamlbuild calls the real ocamldep rule *)
147 ) in
148 generate_ocamldep_rule "ml";
149 generate_ocamldep_rule "mli";
150
151 (* -- Macro-rules generating mlstate_platform.h files -- *)
152 (* TODO BUG 2 : droits du script invalides *)
153 (* TODO BUG 3 : path du fichier généré foireux *)
154 rule "mlstate_platform: () -> libbase/mlstate_platform.h"
155 ~deps:(tool_deps "mlstate_platform")
156 ~prods:["libbase/mlstate_platform.h"]
157 (fun env build ->
158 Seq[
159 Cmd(S[Sh"chmod +x"; P "libbase/gen_platform"]);
160 Cmd(S[get_tool "mlstate_platform"; A (if windows_mode then "WIN" else "")]);
161 Cmd(S[Sh"mv mlstate_platform.h libbase/mlstate_platform.h"])
162 ]
163 );
164
165 (* -- Opa stdlib -- *)
166
167 (*
168 <!> Mathieu Fri Oct 22 10:54:50 CEST 2010
169 !! IF YOU NEED TO PATCH THE FOLLOWING RULE !!
170 ---> come to me, we have to talk first.
171 *)
172 let stdlib_files =
173 (* keep in sync with s3passes@pass_AddStdlibFiles*)
174 let core_dir = "stdlib/core" in
175 let tests_dir = "stdlib/tests" in
176 let dirs = core_dir :: tests_dir :: rec_subdirs [ core_dir ] in
177 let files = List.fold_right (fun dir acc -> dir_ext_files "js" dir @ dir_ext_files "opa" dir @ acc) dirs [] in
178 files
179 in
180 rule "stdlib embedded: stdlib_files -> opalib/staticsInclude.of"
181 ~deps:stdlib_files
182 ~prod:"opalib/staticsInclude.of"
183 (fun env build -> Echo (List.map (fun f -> f^"\n") stdlib_files, "opalib/staticsInclude.of"));
184
185 let opa_opacapi_files =
186 let dirs = rec_subdirs ["stdlib"] in
187 let files = List.fold_right (fun dir acc -> dir_ext_files "opa" dir @ acc) dirs [] in
188 files
189 in
190
191 (* used in mkinstall *)
192 let opacapi_validation = "opacapi.validation" in
193 rule "Opa Compiler Interface Validation (opacapi)"
194 ~deps:("opa/checkopacapi.native" :: opa_opacapi_files)
195 ~prod:opacapi_validation
196 (fun env build ->
197 Cmd(S ([
198 P "./opa/checkopacapi.native" ;
199 A "-o" ;
200 P opacapi_validation ;
201 ] @ (List.rev_map (fun file -> P file) opa_opacapi_files)));
202 );
203
204 (* -- Build infos and runtime version handling -- *)
205
206 (* TODO: probably same bugs than mlstate_platform *)
207 let generate_buildinfos = "buildinfos/generate_buildinfos.sh" in
208 let version_buildinfos = "buildinfos/version.txt" in
209 let pre_buildinfos = "buildinfos/buildInfos.ml.pre" in
210 let post_buildinfos = "buildinfos/buildInfos.ml.post" in
211 let buildinfos = "buildinfos/buildInfos.ml" in
212 rule "buildinfos: buildinfos/* -> buildinfos/buildInfos.ml"
213 ~deps:[version_buildinfos ; pre_buildinfos ; generate_buildinfos ; post_buildinfos]
214 ~prods:(buildinfos :: (if is_release() then ["always_rebuild"] else []))
215 (fun env build ->
216 let version = env version_buildinfos in
217 let pre_prod = env pre_buildinfos in
218 let prod = env buildinfos in
219 let post_prod = env post_buildinfos in
220 Seq[
221 Cmd(S[Sh "cat" ; P pre_prod ; Sh ">" ; P prod]);
222 Cmd(S[P "bash"; A "-e"; P generate_buildinfos; P Pathname.pwd;
223 if is_release () then A "--release" else N;
224 A "--version" ; P version ;
225 Sh ">>" ; P prod]);
226 Cmd(S[Sh "cat" ; P post_prod ; Sh ">>" ; P prod]);
227 ]
228 );
229
230 let parser_files =
231 let dir = ["opalang/syntax"] in
232 let files = List.fold_right (fun dir acc -> dir_ext_files "trx" dir @ dir_ext_files "ml" dir) dir ["general/surfaceAst.ml"] in
233 files
234 in
235 let opaParserVersion = "opalang"/"syntax"/"opaParserVersion.ml"
236 in
237 rule "opa parser version: opalang/syntax/* stdlib -> opalang/syntax/opaParserVersion.ml"
238 ~deps:parser_files
239 ~prod:opaParserVersion
240 (fun build env ->
241 let files = List.map (fun s-> P s) parser_files in
242 Seq[
243 Cmd(S ( [Sh"echo let hash = \\\" > "; P (opaParserVersion)]));
39997a8c » Frédéric Perrin
2011-09-25 On FreeBSD, use md5, use md5sum elsewhere
244 Cmd(S ( [Sh"cat"] @ files @ [Sh"|"; md5; Sh">>"; P opaParserVersion]));
fccc6851 » MLstate
2011-06-21 Initial open-source release
245 Cmd(S ( [Sh"echo \\\" >>"; P opaParserVersion ] ))
246 ]
247 );
248
249 (* -- Internal use of built tools -- *)
250
251 rule " ofile"
252 ~deps:("%.of" :: tool_deps "ofile")
253 ~prod:"%.ml"
254 (fun env build ->
255 let dir = Pathname.dirname (env "%.of") in
256 build_list build (string_list_of_file (env "%.of"));
257 Cmd(S[get_tool "ofile"; A"-path"; P(Pathname.pwd / !Options.build_dir); P(env "%.of")]));
258
259 (* -- Proto rules -- *)
260
261 rule "proto_deps: proto -> proto.depends"
262 ~dep: "%.proto"
263 ~prod: "%.proto.depends"
264 (proto_deps "%.proto" "%.proto.depends");
265
266 rule "proto: proto & proto_depends -> ml & mli & trx_parse"
267 ~deps:("%.proto" :: "%.proto.depends" :: tool_deps "genproto")
268 ~prods: [ "%.ml" ; "%.mli" ; "%_parse.trx" ]
269 (fun env build ->
270 let dir = Pathname.dirname (env "%.proto") in
271 let proto_deps = (string_list_of_file (env "%.proto.depends")) in
272 if proto_deps <> [] then build_list build proto_deps;
273 Cmd(S[get_tool "genproto"
274 ; P (env "%.proto")
275 ; P dir
276 ; P (Pathname.basename (env "%"))
277 ; P (Pathname.basename (env "%") ^ "_parse")
278 ]));
279
280 (* -- Wsdl2ml rules -- *)
281
282 rule "wsdl2ml: wsdl -> types.ml"
283 ~deps:("%.wsdl" :: tool_deps "wsdl2ml")
284 ~prods: [ "%types.ml" ]
285 (fun env build ->
286 let dir = Pathname.dirname (env "%.wsdl") in
287 Cmd(S[get_tool "wsdl2ml"
288 ; P (env "%.wsdl")
289 ]));
290
291 (* -- Mlidl rules -- *)
292
293 rule "mlidl: mlidl -> types.ml & types.mli"
294 ~deps:("%.mlidl" :: tool_deps "mlidl")
295 ~prods: [ "%types.ml"; "%types.mli" ]
296 (fun env build ->
297 let dir = Pathname.dirname (env "%.mlidl") in
298 Cmd(S[get_tool "mlidl"
299 ; P (env "%.mlidl")
300 ]));
301
302 (* -- BSL compilation (using bslregister) -- *)
303
304
305 let ml_sources_bsl = dir_sources_bsl "opabsl/mlbsl" in
306 let js_sources_bsl = dir_sources_bsl "opabsl/jsbsl" in
307 let js_dest_bsl = dir_sources_bsl ~prefix:"opabslgen_" "opabsl/jsbsl" in
308 let mlstate_init_bsl = dir_sources_bsl "opabsl/mlstatebsl" in
309 let js_conf = "opabsl/jsbsl/bsl-sources.jsconf" in
310
311 (*
312 let rec ponctuate s f = function
313 | [] -> ""
314 | [ty] -> f ty
315 | ty::q -> ((f ty) ^ s) ^ ponctuate s f q
316 in
317
318 let _ = Printf.eprintf "js_sources_bsl: %s\n" (ponctuate ", " (fun x -> x) (List.map Ocamlbuild_plugin.Pathname.to_string js_sources_bsl)) in
319 let _ = Printf.eprintf "js_dest_bsl: %s\n" (ponctuate ", " (fun x -> x) (List.map Ocamlbuild_plugin.Pathname.to_string js_dest_bsl)) in
320 *)
321
322 (* TODO: this is not the way to LLVM, the C code is not usable as it is now *)
323 (* let c_sources_bsl = dir_sources_bsl "opabsl/cbsl" in *)
324
325 (* used for js-validation-only *)
326 rule "opabsl_sources"
327 ~deps: (js_conf :: ml_sources_bsl
328 @ js_sources_bsl
329 @ mlstate_init_bsl
330 @ tool_deps "opa-plugin-builder-bin")
331 ~prods: ((List.map (fun s -> "opabsl"/s)
332 ["opabslgenLoader.ml";"opabslgenPlugin.ml";
333 "opabslgen.bypass" ;
334 "opabslgenMLRuntime_x.ml";"opabslgenMLRuntime_x.mli";
335 "opabslgenJSkeys.js";
336 ])@js_dest_bsl)
337 begin fun env build ->
338 Seq[Cmd(S([Sh"cd opabsl && ";
339 get_tool "opa-plugin-builder-bin";
340 A"-o";P"opabslgen";
341 A"--no-opp";
342 A"--no-build";
343 A"--static";
344 ]
345 @special_bsl_options@
346 List.map (fun s -> P (".."/s)) (
347 js_conf ::
348 ml_sources_bsl
349 @js_sources_bsl
350 @mlstate_init_bsl
351 )));
352 mv "opabsl/opabslgenMLRuntime.ml" "opabsl/opabslgenMLRuntime_x.ml";
353 mv "opabsl/opabslgenMLRuntime.mli" "opabsl/opabslgenMLRuntime_x.mli";
354 ]
355 end;
356
357 rule "opa-bslgenMLRuntime interface validation"
358 ~deps: [
359 "opabsl/opabslgenMLRuntime_x.cmo";
360 "opabsl/js_validation/imp_client_lib.js";
361 "opabsl/js_validation/bsl.js";
362 ]
363 ~prod: "opabsl/opabslgenMLRuntime.ml"
364 (fun env build ->
365 Seq[
366 cp "opabsl/opabslgenMLRuntime_x.ml" "opabsl/opabslgenMLRuntime.ml";
367 ]
368 );
369
370 let js_pp_bsl = dir_sources_bsl ~prefix:"opabslgen_" ~suffix:".pp" "opabsl/jsbsl" in
371
372 rule "preprocess JS files for validation"
373 ~deps:((tool_deps "ppjs")@js_dest_bsl)
374 ~prods:js_pp_bsl
375 (fun env build ->
376 let ppjs = get_tool "ppjs" in
377 Cmd(S (ppjs::A"--output-suffix"::A ".pp"::List.map (fun x -> A x) js_dest_bsl))
378 );
379
380 (*
381 TODO: enable all of them as soon as possible.
382 *)
383 let google_closure_compiler_options =
384 A"--warning_level" :: A"VERBOSE"::
385 (*
386 Turn on every available warning as errors.
387 Keep synchronized with the checker.
388 *)
389 (
390 List.fold_left (fun acc s -> A"--jscomp_error" :: A s :: acc)
391 [] [
392 "accessControls" ;
393 "checkRegExp" ;
394 (* "checkTypes" ; *)
395 "checkVars" ;
396 "deprecated" ;
397 "fileoverviewTags" ;
398 "invalidCasts" ;
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
399 "missingProperties" ;
fccc6851 » MLstate
2011-06-21 Initial open-source release
400 (* "nonStandardJsDocs" ; *)
401 "strictModuleDepCheck" ;
402 "undefinedVars" ;
403 "unknownDefines" ;
404 "visibility" ;
405 ]
406 ) in
407
408
409 rule "Client lib JS validation"
410 ~deps: (
411 "qmljsimp/qmlJsImpClientLib.js" ::
412 "qmlcps/qmlCpsClientLib.js" ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
413 "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
414 "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ::
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
415 "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
416 "opabsl/jsbsl/jquery_ext_1.6.1.externs.js" ::
fccc6851 » MLstate
2011-06-21 Initial open-source release
417 (tool_deps "jschecker.jar") @
418 (tool_deps "jschecker_externals.js") @
419 (tool_deps "jschecker_clientliblib.js") @
420 (tool_deps "jschecker_jquery.js") )
421 ~prods:[
422 "opabsl/js_validation/imp_client_lib.js";
423 ]
424 (fun env build ->
425 let run_check clientlib output_file =
426 let local = windows_mode in
427 [
428 Cmd(S [Sh"mkdir"; A"-p";P "opabsl/js_validation"]);
429 Cmd(S(
430 A"java" :: A"-jar" :: (get_tool ~local "jschecker.jar") ::
431 A"--externs" :: (get_tool ~local "jschecker_externals.js") ::
432 A"--externs" :: (get_tool ~local "jschecker_jquery.js") ::
433 A"--externs" :: (get_tool ~local "jschecker_clientliblib.js") ::
434 A"--js_output_file" :: A output_file ::
435 google_closure_compiler_options @
436 A"--js" :: A clientlib ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
437 A"--js" :: A "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
438 A"--js" :: A "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ::
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
439 A"--js" :: A "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
440 A"--js" :: A "opabsl/jsbsl/jquery_ext_1.6.1.externs.js" ::
fccc6851 » MLstate
2011-06-21 Initial open-source release
441 A"--js" :: A"qmlcps/qmlCpsClientLib.js" ::
442 []
443 ))
444 ]
445 in
446 Seq (
447 run_check "qmljsimp/qmlJsImpClientLib.js" "opabsl/js_validation/imp_client_lib.js"
448 )
449 );
450
451 rule "opa-bslgenMLRuntime JS validation"
452 ~deps: (
453 (tool_deps "jschecker.jar")
454 @ (tool_deps "jschecker_externals.js")
455 @ (tool_deps "jschecker_jquery.js")
456 @ (tool_deps "jschecker_clientlib.js")
457 @ (tool_deps "jschecker_clientliblib.js")
458 @ (tool_deps "jschecker_cpsclientlib.js")
459 @ js_pp_bsl
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
460 @ [ "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ;
461 "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ;
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
462 "opabsl/jsbsl/selection_ext_bsldom.extern.js" ;
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
463 "opabsl/jsbsl/jquery_ext_1.6.1.externs.js" ;
464 "opabsl/opabslgenJSkeys.js" ]
fccc6851 » MLstate
2011-06-21 Initial open-source release
465 )
466 ~prods: ["opabsl/js_validation/bsl.js"]
467 (fun env build ->
468 let arg_of_file file acc = match file with (*A very dumb filter to get rid of files that we just can't fix in the first place*)
469 | "opabsl/jsbsl/opabslgen_jquery-1.6.1.js.pp" -> acc
470 | "opabsl/jsbsl/opabslgen_json2.js.pp" -> acc
471 | _ -> A "--js" :: A file :: acc
472 in
473 let get_tool = get_tool ~local:windows_mode in
474 Seq[
475 Cmd(S [Sh"mkdir";A"-p";P "opabsl/js_validation"]);
476 Cmd(S(
477 A"java" :: A"-jar" :: (get_tool "jschecker.jar") ::
478 A"--externs" :: (get_tool "jschecker_externals.js") ::
479 A"--externs" :: (get_tool "jschecker_clientliblib.js") ::
480 A"--externs" :: (get_tool "jschecker_clientlib.js") ::
481 A"--externs" :: (get_tool "jschecker_jquery.js") ::
482 A"--externs" :: (get_tool "jschecker_cpsclientlib.js") ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
483 A"--externs" :: A "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
484 A"--externs" :: A "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ::
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
485 A"--externs" :: A "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
486 A"--externs" :: A "opabsl/jsbsl/jquery_ext_1.6.1.externs.js" ::
fccc6851 » MLstate
2011-06-21 Initial open-source release
487 A"--js_output_file" :: A"opabsl/js_validation/bsl.js" ::
488 google_closure_compiler_options @
489 (List.fold_right (fun s acc -> arg_of_file s acc) js_pp_bsl [])
490 @ [ A"--js" ; A "opabsl/opabslgenJSkeys.js" ]
491 ))]
492 );
493
494 (*
495 -The documentation generator does not work if files are not suffixed with '.js'
496 -But, we do not need to preprocess the opabslgen_ files with ppjs,
497 as for JS validation (files js_pp_bsl)
498 -We simply use the files opabslgen_ for generating the doc. It is obtained from
499 the origin js file, and with a resolution of bsl directives (+ generation of additionnal
500 type directive for the js validation
501
502 Configuration stuff for jsdoc generator.
503 Needs to access lots of files. Cf jsdocdir/README.txt
504 *)
505 let jsdocdir =
506 let opageneral = Pathname.to_string Pathname.pwd in
507 opageneral ^ "/tools/jsdoc-toolkit"
508 in
509
510 let jsdoc_target = "doc.jsbsl" in
511
512 rule "opa-bslgenMLRuntime JS documentation"
513 ~deps: (
514 js_dest_bsl
515 )
516 ~prods: (
517 [ jsdoc_target ^ "/index.html" ]
518 )
519 (fun env build ->
520 Cmd(S(
521 A"java" ::
522 A("-Djsdoc.dir="^jsdocdir) ::
523 A("-Djsdoc.template.dir="^jsdocdir^"/templates") ::
524 A"-jar" ::
525 A(jsdocdir^"/jsrun.jar") :: A(jsdocdir^"/app/run.js") ::
526 A("-t="^(jsdocdir^"/templates/jsdoc")) ::
527 A("--allfunctions") ::
528 (* Set the target directory *)
529 A("-d="^jsdoc_target) ::
530 (List.map (fun js -> A js) js_dest_bsl)
531 ))
532 );
533
534
535 (* ------------------------------------------------------------------ *)
536 (* Additional rules: final compilation (compiling using our backends) *)
537 (* ------------------------------------------------------------------ *)
538
539 (* -- OPA compiler rules -- *)
540
541 let stdlib_packages_dir = "stdlib" in
542
543 let opaopt = try Sh(Sys.getenv "OPAOPT") with Not_found -> N in
544
545 let opacomp_deps_js = string_list_of_file "opa-run-js-libs.itarget" in
546 let opacomp_deps_native = string_list_of_file "opa-run-libs.itarget" in
547 let opacomp_deps_byte = List.map (fun l -> Pathname.update_extension "cma" l) opacomp_deps_native in
548
549 let opacomp_deps_native = opacomp_deps_native @ opacomp_deps_js in
550 let opacomp_deps_byte = opacomp_deps_byte @ opacomp_deps_js in
551
552 let opa_prefix = Pathname.pwd / !Options.build_dir in
553
554 let opa_libs_dir = "lib" / "opa" / "static" in
555
556 let opa_share_dir = "share" / "opa" in
557
558 let copy_lib_to_runtime lib =
559 let modules = string_list_of_file (lib -.- "mllib") in
560 let files =
561 List.fold_left
562 (fun acc f ->
563 let dir, modl = Pathname.dirname f, Pathname.basename f -.- "cmi" in
564 List.filter (fun m -> Pathname.exists (opa_prefix / m))
565 [dir / String.uncapitalize modl; dir / String.capitalize modl] @ acc)
566 [] modules
567 in
568 let stubs =
569 List.map (Pathname.update_extension !Options.ext_lib) (dir_ext_files "clib" (mlstate_lib_dir lib))
570 in
571 let files = stubs @ files in
572 Cmd(S(link_cmd :: List.map (fun f -> P (opa_prefix / f)) files @ [ P (opa_prefix / opa_libs_dir) ]))
573 in
574
575 rule "opa run-time libraries"
576 ~deps:("libbase"/"mimetype_database.xml" :: opacomp_deps_native)
577 ~stamp:"runtime-libs.stamp"
578 (fun _env _build ->
579 let mllibs = List.filter (fun f -> Pathname.check_extension f "cmxa") opacomp_deps_native in
580 let mllibs = List.map Pathname.remove_extension mllibs in
581 let copylibs = List.map copy_lib_to_runtime mllibs in
582 Seq[
583 Cmd(S[Sh"rm"; A"-rf"; P (opa_prefix / opa_libs_dir)]);
584 Cmd(S[Sh"mkdir"; A"-p"; P (opa_prefix / opa_libs_dir)]);
585 Cmd(S[Sh"rm"; A"-rf"; P (opa_prefix / opa_share_dir)]);
586 Cmd(S[Sh"mkdir"; A"-p"; P (opa_prefix / opa_share_dir)]);
587 Cmd(S(link_cmd :: List.map (fun f -> P (opa_prefix / f)) opacomp_deps_native
588 @ [ P (opa_prefix / opa_libs_dir) ]));
589 Cmd(S(link_cmd :: List.map (fun f -> P (opa_prefix / f -.- !Options.ext_lib)) mllibs
590 @ [ P (opa_prefix / opa_libs_dir) ]));
591 Cmd(S(link_cmd :: P (opa_prefix / "libbase" / "mimetype_database.xml") :: [ P (opa_prefix / opa_share_dir / "mimetype_database.xml") ]));
592 Seq copylibs
593 ]
594 );
595
596 let opacomp build src dst_ext opt =
597 build_list build
598 (List.map ((/) (Pathname.dirname src)) (string_list_of_file (src-.-"depends")));
599 let dst = Pathname.update_extension dst_ext src in
600 Cmd(S[
601 Sh("MLSTATELIBS=\""^ opa_prefix ^"\"");
602 get_tool "opa-bin"; opt;
603 A"--verbose";(* A"--no-opa-walker"; *)
604 opaopt;
605 A"-o"; P dst; P src
606 ])
607 in
608
609 rule "opa and server dependencies"
610 ~deps:("runtime-libs.stamp" :: tool_deps "opa-bin")
611 ~stamp:"opacomp.stamp"
612 (fun env build -> Nop);
613
614 rule "opackdep: .opack -> .opack.depends"
615 ~dep:"%.opack"
616 ~prod:"%.opack.depends"
617 (fun env build ->
618 Cmd(S[P"grep"; A"-v"; A"^\\w*-"; P(env "%.opack"); Sh">"; P(env "%.opack.depends"); Sh"|| true"]));
619
620 (* A rule to build applications using the stdlib (e.g. opadoc) *)
621 rule "opacomp: .opack -> .native"
622 ~deps: ("%.opack"::"%.opack.depends"::"opa-packages.stamp"::"opacomp.stamp"::[])
623 ~prod: "%.native"
624 (fun env build ->
625 let dir = Pathname.dirname (env "%") in
626 let mano_depends = Pathname.pwd / (env "%.depends") in
627 if Pathname.exists mano_depends then (
628 build_list build (List.map ((/) dir) (string_list_of_file mano_depends))
629 );
630 build_list build (List.map ((/) dir) (string_list_of_file (env "%.opack.depends")));
631 opacomp build (env "%.opack") "native"
632 (S[ A"-I" ; P stdlib_packages_dir ; A"--project-root" ; P dir]));
633
634 rule "opacomp: .opack -> .byte"
635 ~deps: ("%.opack"::"%.opack.depends"::"opa-packages.stamp"::"opacomp-byte.stamp"::[])
636 ~prod: "%.byte"
637 (fun env build ->
638 let dir = Pathname.dirname (env "%") in
639 build_list build (List.map ((/) dir) (string_list_of_file (env "%.opack.depends")));
640 opacomp build (env "%.opack") "byte" (S[A"-I";P stdlib_packages_dir]));
641 (*
642 (A"--bytecode"));
643 Used to give this option to opa-bin, but since the opa package are build by ocamlbuild,
644 we do not generated bytecode version of opa-packages, making the bytecode compilation
645 of server not available anymore.
646 *)
647
648 (* temporary and unreliable *)
649 rule "opadep: .opa -> .opa.depends"
650 ~dep: "%.opa"
651 ~prod: "%.opa.depends"
652 (fun env build ->
5b71cd75 » Frédéric Perrin
2011-09-03 Modify sed expression to make it accessible to both GNU and BSD sed
653 let dep_regex = "^ *import \\*\\(.\\+\\) *$" in
654 Cmd(S[sed; A"-n"; A("s%"^dep_regex^"%\\1.opx%p"); P(env "%.opa");
fccc6851 » MLstate
2011-06-21 Initial open-source release
655 Sh">";P(env "%.opa.depends")]));
656
657 rule "opacomp: .opa -> .native"
658 ~deps: ("%.opa"::"%.opa.depends"::"opacomp.stamp"::[])
659 ~prod: "%.native"
660 (fun env build -> opacomp build (env "%.opa") "native" N);
661
662 rule "opacomp: .opa -> .byte"
663 ~deps: ("%.opa"::"%.opa.depends"::"opacomp-byte.stamp"::[])
664 ~prod: "%.byte"
665 (fun env build -> opacomp build (env "%.opa") "byte" (A"--bytecode"));
666
667 rule "opa bash_completion: opa-bin -> bash_completion"
668 ~deps: (tool_deps "opa-bin")
669 ~prod: "bash_completion"
670 (fun env build ->
671 Seq[Cmd(S[get_tool "opa-bin"; A"--bash-completion"])]);
672
673 (* -- OPA packages -- *)
674
675 let package_to_dir s0 =
676 let s = String.copy s0 in
677 for i = 0 to String.length s - 1 do
678 if s.[i] = '.' then s.[i] <- '/'
679 done;
680 s
681 in
682 let dir_to_package s0 =
683 let s = String.copy s0 in
684 let len_std = String.length stdlib_packages_dir in
685 let pfx,s = (* remove optional stdlib_packages_dir prefix *)
686 try
687 let pfx = String.sub s 0 len_std in
688 if pfx = stdlib_packages_dir
689 then pfx, String.sub s (len_std + 1) (String.length s - len_std - 1)
690 else "", s
691 with Invalid_argument _ -> "", s
692 in
693 for i = 0 to String.length s - 1 do
694 if s.[i] = '/' then s.[i] <- '.'
695 done;
696 pfx, s
697 in
698
699 let module RuleFailure = struct exception E end in
700 let files_of_package pkg =
701 let pkdir = package_to_dir pkg in
702 if not (Pathname.is_directory (Pathname.pwd / pkdir)) then
703 let () = Printf.eprintf "Error: can not find sources for package %s (directory %s does not exist)\n" pkg pkdir in
704 raise RuleFailure.E
705 else
706 let opack = dir_ext_files "opack" (Pathname.pwd / pkdir) in
707 let files = dir_ext_files "opa" (Pathname.pwd / pkdir) in
708 let files = files @ opack in
709 (*
710 return relative filenames
711 *)
712 let files =
713 let len = String.length Pathname.pwd + 1 in (* the additinal '/' *)
714 let relative_part s = String.sub s len (String.length s - len) in
715 List.map relative_part files
716 in
717 (*
718 When you compare 2 branches, if the order of opa sources is not deterministic, you can become crazy
719 *)
720 let files = List.sort String.compare files in
721 files in
722
723 let make_all_packages = stdlib_packages_dir/"all_packages.sh" in
724 let all_packages_file = stdlib_packages_dir/"all.packages" in
725
726 rule "all.packages"
727 ~dep: make_all_packages
728 ~prod: all_packages_file
729 (fun env build ->
730 Cmd(S[
731 Sh"cd"; P (Pathname.pwd / stdlib_packages_dir); Sh"&&";
732 P"./all_packages.sh"; Sh">"; P (Pathname.pwd / !Options.build_dir / all_packages_file);
733 ])
734 );
735
736 let package_building ~name ~stamp ~stdlib_only ~rebuild =
737 rule name
738 ~deps:[opacapi_validation;all_packages_file;"opacomp.stamp"]
739 ~stamp
740 ~prod:"i_dont_exist" (* forces ocamlbuild to always run the command *)
741 (fun env build ->
742 try
743 let packages = string_list_of_file all_packages_file in
744 let packages =
745 if stdlib_only
746 then
747 let stdlib = "stdlib.core" in
748 List.filter (fun package ->
749 String.length package > String.length stdlib &&
750 stdlib = String.sub package 0 (String.length stdlib)) packages
751 else packages in
752 let list_package_files = List.map
753 (fun pkg ->
754 let files = files_of_package pkg in
755 (*
756 Copy in _build the opa files of the packages.
757 In this way, files given to the compiler are relative,
758 and api files are generated in the _build
759 This makes also that the packages does not contain absolute filename,
760 which is not valid wrt the deb checker.
761 *)
762 build_list build files;
763 (pkg, files)) packages in
764 let conf =
765 List.concat (
766 List.map
767 (fun (pkg, files) ->
768 (pkg ^ ":\n") ::
769 (
770 (* auto import *)
771 let prefix = "stdlib.core" in
772 let len = String.length prefix in
773 if String.length pkg >= String.length prefix && String.sub pkg 0 len = prefix
774 then (
775 if pkg = prefix
776 then ""
777 else
778 (* subdirectory of stdlib.core import stdlib.core *)
779 "import stdlib.core"
780 )
781 else " import stdlib.core\n import stdlib.core.*\n"
782 ) ::
783 List.map (fun file -> " " ^ file ^ "\n") files)
784 list_package_files
785 ) in
786 let all_files = List.concat (List.map (fun (_,files) -> List.map (fun f -> P f) files) list_package_files) in
787 let rebuild_opt = if rebuild then [A"--rebuild"] else [] in
788 Seq[
789 Echo(conf, "conf");
790 Cmd(S([Sh("MLSTATELIBS=\""^ opa_prefix ^"\"");
791 get_tool "opa-bin";
792 A"--autocompile";
793 (* A"--verbose-build"; *)
794 A"--conf";P "conf";
795 A"--warn-error"; A"root";
796 A"--project-root"; P Pathname.pwd; (* because the @static_resource in the stdlib expect this *)
797 A"--no-stdlib";
798 opaopt;
799 S all_files;
800 ] @ rebuild_opt));
801 ]
802 with RuleFailure.E ->
803 fail_rule build
804 ) in
805
806 package_building
807 ~name:"opa-packages: meta-rule to build all .opx"
808 ~stamp:"opa-packages.stamp"
809 ~stdlib_only:false
810 ~rebuild:false;
811
812 package_building
813 ~name:"opa-stdlib-packages: meta-rule to build all the stdlib .opx"
814 ~stamp:"opa-stdlib-packages.stamp"
815 ~stdlib_only:true
816 ~rebuild:false;
817
818 () (* This file should be an expr of type unit *)
Something went wrong with that request. Please try again.