Skip to content
This repository
Newer
Older
100644 913 lines (816 sloc) 34.14 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 =
534ca4de » OpaOnWindowsNow
2011-11-03 [feature] syntax: introduces js-like syntax
231 let dir = ["opalang/classic_syntax";"opalang/js_syntax"] in
fccc6851 » MLstate
2011-06-21 Initial open-source release
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
534ca4de » OpaOnWindowsNow
2011-11-03 [feature] syntax: introduces js-like syntax
235 let opaParserVersion = "opalang"/"classic_syntax"/"opaParserVersion.ml"
fccc6851 » MLstate
2011-06-21 Initial open-source release
236 in
534ca4de » OpaOnWindowsNow
2011-11-03 [feature] syntax: introduces js-like syntax
237 rule "opa parser version: opalang/*_syntax/* stdlib -> opalang/classic_syntax/opaParserVersion.ml"
fccc6851 » MLstate
2011-06-21 Initial open-source release
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
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
302 (* -- js validation -- *)
303 (*
304 TODO: enable all of them as soon as possible.
305 *)
306 let google_closure_compiler_options =
307 A"--warning_level" :: A"VERBOSE"::
308 (*
309 Turn on every available warning as errors.
310 Keep synchronized with the checker.
311 *)
312 (
313 List.fold_left (fun acc s -> A"--jscomp_error" :: A s :: acc)
314 [] [
315 "accessControls" ;
316 "checkRegExp" ;
317 (* "checkTypes" ; *)
318 "checkVars" ;
319 "deprecated" ;
320 "fileoverviewTags" ;
321 "invalidCasts" ;
322 "missingProperties" ;
323 (* "nonStandardJsDocs" ; *)
324 "strictModuleDepCheck" ;
325 "undefinedVars" ;
326 "unknownDefines" ;
327 "visibility" ;
328 ]
329 )
330 in
331
332 let js_checker =
333 let local = windows_mode in
334 A"java" :: A"-jar" :: (get_tool ~local "jschecker.jar") ::
335 (* A"--externs" :: (get_tool ~local "jschecker_externals.js") ::
336 A"--externs" :: (get_tool ~local "jschecker_jquery.js") ::
337 A"--externs" :: (get_tool ~local "jschecker_clientliblib.js") ::
338 A"--js_output_file" :: A output_file :: *)
339 google_closure_compiler_options (*@
340 A"--js" :: A clientlib ::
341 A"--js" :: A "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
342 A"--js" :: A "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ::
343 A"--js" :: A "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
344 A"--js" :: A "opabsl/jsbsl/jquery_extra.externs.js" ::
345 A"--js" :: A"qmlcps/qmlCpsClientLib.js" ::
346 []*)
347 in
348
349 (* -- opa plugin -- *)
350 (* -- plugin that fails to validate -- *)
351 let accept_js_validation_failure = []
352 in
353 (* -- file that are only needed for validation process -- *)
354 let jschecker_file s =
355 let prefix = "jschecker_" in
81350687 » OpaOnWindowsNow
2011-10-20 [fix] plugin: use _tag file to specify used lib of a plugin
356 try String.sub (Pathname.basename s) 0 (String.length prefix) = prefix with _ -> false
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
357 in
81350687 » OpaOnWindowsNow
2011-10-20 [fix] plugin: use _tag file to specify used lib of a plugin
358 let use_tag s =
359 let lenp = String.length "use_" in
360 let t = try String.sub s 0 lenp = "use_" with _ -> false in
361 if t then Some(String.sub s lenp ((String.length s) -lenp))
362 else None
363 in
364 let opa_plugin_builder_name = "opa-plugin-builder-bin" in
365 let opa_plugin_builder = get_tool opa_plugin_builder_name in
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
366 let opp_build opa_plugin opp oppf env build =
81350687 » OpaOnWindowsNow
2011-10-20 [fix] plugin: use _tag file to specify used lib of a plugin
367 let dir = Pathname.dirname (env opa_plugin) in
368 let path = let p = Pathname.to_string dir in if p = "." then "" else p^"/" in
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
369 let files = string_list_of_file (env "%.opa_plugin") in
81350687 » OpaOnWindowsNow
2011-10-20 [fix] plugin: use _tag file to specify used lib of a plugin
370 let caml_use_lib = Tags.fold (fun tag list ->
371 match use_tag tag with
372 | None -> list
373 | Some dep -> dep::list
374 ) (tags_of_pathname (env "%.opa_plugin")) []
375 in
376 let lib_dir s = [A"--ml";A"-I";A"--ml";P (if Pathname.exists s then ".." / s else ("+"^s))] in
377 let include_dirs = List.flatten (List.map lib_dir caml_use_lib) in
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
378 let files = List.map ((^) path) files in
379 build_list build files;
380 let files_validation, files_lib = List.partition jschecker_file files in
381 let files_lib = List.map (fun s -> P s) files_lib in
382 let plugin_name = Pathname.basename (env "%") in
383 let files_js = List.filter (fun f-> Pathname.check_extension f "js") files in
384 let js_validation = if files_js=[]
385 then [A"--js-validator-off"]
386 else (
387 let files_validation = List.flatten (List.map (fun s -> [A"--js-validator-file";P s]) files_validation) in
388 let unsafe_js = if List.mem plugin_name accept_js_validation_failure then [A"--unsafe-js"] else [] in
389 let js_checker = List.tl (List.flatten (List.map (fun opt -> [A"--js-validator-opt";opt]) js_checker)) in
390 unsafe_js @ [A"--js-validator"] @ js_checker @ files_validation
391 )
392 in
f26545b5 » OpaOnWindowsNow
2011-10-21 [fix] plugin: location of 'installed' plugin is incorrect when compil…
393 let options = [A"--static" ; A"-o" ; P((Pathname.basename (env opp)))] @ include_dirs @ js_validation @ files_lib in
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
394 Seq[Cmd(S(opa_plugin_builder::options));
395 Cmd(S[A"touch"; P(env oppf) ] )]
396 in
397 rule "opa_plugin_dir: opa_plugin -> oppf"
81350687 » OpaOnWindowsNow
2011-10-20 [fix] plugin: use _tag file to specify used lib of a plugin
398 ~deps:("%.opa_plugin" :: (tool_deps opa_plugin_builder_name))
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
399 ~prod:"%.oppf" (* use a dummy target because ocamlbuild don't want directory target *)
400 (opp_build "%.opa_plugin" "%" "%oppf")
401 ;
402
fccc6851 » MLstate
2011-06-21 Initial open-source release
403
404
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
405 (* -- BSL compilation (using bslregister) -- *)
fccc6851 » MLstate
2011-06-21 Initial open-source release
406 let ml_sources_bsl = dir_sources_bsl "opabsl/mlbsl" in
407 let js_sources_bsl = dir_sources_bsl "opabsl/jsbsl" in
408 let js_dest_bsl = dir_sources_bsl ~prefix:"opabslgen_" "opabsl/jsbsl" in
409 let mlstate_init_bsl = dir_sources_bsl "opabsl/mlstatebsl" in
410 let js_conf = "opabsl/jsbsl/bsl-sources.jsconf" in
411
412 (*
413 let rec ponctuate s f = function
414 | [] -> ""
415 | [ty] -> f ty
416 | ty::q -> ((f ty) ^ s) ^ ponctuate s f q
417 in
418
419 let _ = Printf.eprintf "js_sources_bsl: %s\n" (ponctuate ", " (fun x -> x) (List.map Ocamlbuild_plugin.Pathname.to_string js_sources_bsl)) in
420 let _ = Printf.eprintf "js_dest_bsl: %s\n" (ponctuate ", " (fun x -> x) (List.map Ocamlbuild_plugin.Pathname.to_string js_dest_bsl)) in
421 *)
422
423 (* TODO: this is not the way to LLVM, the C code is not usable as it is now *)
424 (* let c_sources_bsl = dir_sources_bsl "opabsl/cbsl" in *)
425
426 (* used for js-validation-only *)
427 rule "opabsl_sources"
428 ~deps: (js_conf :: ml_sources_bsl
429 @ js_sources_bsl
430 @ mlstate_init_bsl
431 @ tool_deps "opa-plugin-builder-bin")
432 ~prods: ((List.map (fun s -> "opabsl"/s)
433 ["opabslgenLoader.ml";"opabslgenPlugin.ml";
434 "opabslgen.bypass" ;
435 "opabslgenMLRuntime_x.ml";"opabslgenMLRuntime_x.mli";
436 "opabslgenJSkeys.js";
437 ])@js_dest_bsl)
438 begin fun env build ->
439 Seq[Cmd(S([Sh"cd opabsl && ";
440 get_tool "opa-plugin-builder-bin";
441 A"-o";P"opabslgen";
442 A"--no-opp";
443 A"--no-build";
444 A"--static";
445 ]
446 @special_bsl_options@
447 List.map (fun s -> P (".."/s)) (
448 js_conf ::
449 ml_sources_bsl
450 @js_sources_bsl
451 @mlstate_init_bsl
452 )));
453 mv "opabsl/opabslgenMLRuntime.ml" "opabsl/opabslgenMLRuntime_x.ml";
454 mv "opabsl/opabslgenMLRuntime.mli" "opabsl/opabslgenMLRuntime_x.mli";
455 ]
456 end;
457
458 rule "opa-bslgenMLRuntime interface validation"
459 ~deps: [
460 "opabsl/opabslgenMLRuntime_x.cmo";
461 "opabsl/js_validation/imp_client_lib.js";
462 "opabsl/js_validation/bsl.js";
463 ]
464 ~prod: "opabsl/opabslgenMLRuntime.ml"
465 (fun env build ->
466 Seq[
467 cp "opabsl/opabslgenMLRuntime_x.ml" "opabsl/opabslgenMLRuntime.ml";
468 ]
469 );
470
471 let js_pp_bsl = dir_sources_bsl ~prefix:"opabslgen_" ~suffix:".pp" "opabsl/jsbsl" in
472
473 rule "preprocess JS files for validation"
474 ~deps:((tool_deps "ppjs")@js_dest_bsl)
475 ~prods:js_pp_bsl
476 (fun env build ->
477 let ppjs = get_tool "ppjs" in
478 Cmd(S (ppjs::A"--output-suffix"::A ".pp"::List.map (fun x -> A x) js_dest_bsl))
479 );
480
481 rule "Client lib JS validation"
482 ~deps: (
483 "qmljsimp/qmlJsImpClientLib.js" ::
484 "qmlcps/qmlCpsClientLib.js" ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
485 "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
486 "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ::
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
487 "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
59bd5295 » François-Régis Sinot
2011-10-05 [enhance] jquery: updgrade to 1.6.4
488 "opabsl/jsbsl/jquery_extra.externs.js" ::
fccc6851 » MLstate
2011-06-21 Initial open-source release
489 (tool_deps "jschecker.jar") @
490 (tool_deps "jschecker_externals.js") @
491 (tool_deps "jschecker_clientliblib.js") @
492 (tool_deps "jschecker_jquery.js") )
493 ~prods:[
494 "opabsl/js_validation/imp_client_lib.js";
495 ]
496 (fun env build ->
497 let run_check clientlib output_file =
498 let local = windows_mode in
499 [
500 Cmd(S [Sh"mkdir"; A"-p";P "opabsl/js_validation"]);
501 Cmd(S(
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
502 js_checker @
503 A"--externs" :: (get_tool ~local "jschecker_externals.js") ::
504 A"--externs" :: (get_tool ~local "jschecker_jquery.js") ::
505 A"--externs" :: (get_tool ~local "jschecker_clientliblib.js") ::
506 A"--js_output_file" :: A output_file ::
507 A"--js" :: A clientlib ::
508 A"--js" :: A "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
509 A"--js" :: A "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ::
510 A"--js" :: A "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
511 A"--js" :: A "opabsl/jsbsl/jquery_extra.externs.js" ::
512 A"--js" :: A"qmlcps/qmlCpsClientLib.js" ::
513 []
514 ))
fccc6851 » MLstate
2011-06-21 Initial open-source release
515 ]
516 in
517 Seq (
518 run_check "qmljsimp/qmlJsImpClientLib.js" "opabsl/js_validation/imp_client_lib.js"
519 )
520 );
521
522 rule "opa-bslgenMLRuntime JS validation"
523 ~deps: (
524 (tool_deps "jschecker.jar")
525 @ (tool_deps "jschecker_externals.js")
526 @ (tool_deps "jschecker_jquery.js")
527 @ (tool_deps "jschecker_clientlib.js")
528 @ (tool_deps "jschecker_clientliblib.js")
529 @ (tool_deps "jschecker_cpsclientlib.js")
530 @ js_pp_bsl
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
531 @ [ "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ;
532 "opabsl/jsbsl/jquery_ext_jQueryExtends.extern.js" ;
97f2e433 » fpessaux
2011-06-24 [cleanup] js-warnings: No more "undefined properties". Remaining 9 wa…
533 "opabsl/jsbsl/selection_ext_bsldom.extern.js" ;
59bd5295 » François-Régis Sinot
2011-10-05 [enhance] jquery: updgrade to 1.6.4
534 "opabsl/jsbsl/jquery_extra.externs.js" ;
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
535 "opabsl/opabslgenJSkeys.js" ]
fccc6851 » MLstate
2011-06-21 Initial open-source release
536 )
537 ~prods: ["opabsl/js_validation/bsl.js"]
538 (fun env build ->
539 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*)
59bd5295 » François-Régis Sinot
2011-10-05 [enhance] jquery: updgrade to 1.6.4
540 | "opabsl/jsbsl/opabslgen_jquery-1.6.4.js.pp" -> acc
fccc6851 » MLstate
2011-06-21 Initial open-source release
541 | "opabsl/jsbsl/opabslgen_json2.js.pp" -> acc
542 | _ -> A "--js" :: A file :: acc
543 in
544 let get_tool = get_tool ~local:windows_mode in
545 Seq[
546 Cmd(S [Sh"mkdir";A"-p";P "opabsl/js_validation"]);
547 Cmd(S(
548 A"java" :: A"-jar" :: (get_tool "jschecker.jar") ::
549 A"--externs" :: (get_tool "jschecker_externals.js") ::
550 A"--externs" :: (get_tool "jschecker_clientliblib.js") ::
551 A"--externs" :: (get_tool "jschecker_clientlib.js") ::
552 A"--externs" :: (get_tool "jschecker_jquery.js") ::
553 A"--externs" :: (get_tool "jschecker_cpsclientlib.js") ::
c4cbaf99 » fpessaux
2011-06-23 [cleanup] js-warnings: Less warnings in Google closure compiler (10 r…
554 A"--externs" :: A "opabsl/jsbsl/jquery_ext_bslanchor.extern.js" ::
555 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…
556 A"--externs" :: A "opabsl/jsbsl/selection_ext_bsldom.extern.js" ::
59bd5295 » François-Régis Sinot
2011-10-05 [enhance] jquery: updgrade to 1.6.4
557 A"--externs" :: A "opabsl/jsbsl/jquery_extra.externs.js" ::
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
558 A"--js_output_file" :: A "opabsl/js_validation/bsl.js" ::
fccc6851 » MLstate
2011-06-21 Initial open-source release
559 google_closure_compiler_options @
560 (List.fold_right (fun s acc -> arg_of_file s acc) js_pp_bsl [])
561 @ [ A"--js" ; A "opabsl/opabslgenJSkeys.js" ]
562 ))]
563 );
564
565 (*
566 -The documentation generator does not work if files are not suffixed with '.js'
567 -But, we do not need to preprocess the opabslgen_ files with ppjs,
568 as for JS validation (files js_pp_bsl)
569 -We simply use the files opabslgen_ for generating the doc. It is obtained from
570 the origin js file, and with a resolution of bsl directives (+ generation of additionnal
571 type directive for the js validation
572
573 Configuration stuff for jsdoc generator.
574 Needs to access lots of files. Cf jsdocdir/README.txt
575 *)
576 let jsdocdir =
577 let opageneral = Pathname.to_string Pathname.pwd in
578 opageneral ^ "/tools/jsdoc-toolkit"
579 in
580
581 let jsdoc_target = "doc.jsbsl" in
582
583 rule "opa-bslgenMLRuntime JS documentation"
584 ~deps: (
585 js_dest_bsl
586 )
587 ~prods: (
588 [ jsdoc_target ^ "/index.html" ]
589 )
590 (fun env build ->
591 Cmd(S(
592 A"java" ::
593 A("-Djsdoc.dir="^jsdocdir) ::
594 A("-Djsdoc.template.dir="^jsdocdir^"/templates") ::
595 A"-jar" ::
596 A(jsdocdir^"/jsrun.jar") :: A(jsdocdir^"/app/run.js") ::
597 A("-t="^(jsdocdir^"/templates/jsdoc")) ::
598 A("--allfunctions") ::
599 (* Set the target directory *)
600 A("-d="^jsdoc_target) ::
601 (List.map (fun js -> A js) js_dest_bsl)
602 ))
603 );
604
605
606 (* ------------------------------------------------------------------ *)
607 (* Additional rules: final compilation (compiling using our backends) *)
608 (* ------------------------------------------------------------------ *)
609
610 (* -- OPA compiler rules -- *)
611
612 let stdlib_packages_dir = "stdlib" in
613
614 let opaopt = try Sh(Sys.getenv "OPAOPT") with Not_found -> N in
615
616 let opacomp_deps_js = string_list_of_file "opa-run-js-libs.itarget" in
617 let opacomp_deps_native = string_list_of_file "opa-run-libs.itarget" in
618 let opacomp_deps_byte = List.map (fun l -> Pathname.update_extension "cma" l) opacomp_deps_native in
619
620 let opacomp_deps_native = opacomp_deps_native @ opacomp_deps_js in
621 let opacomp_deps_byte = opacomp_deps_byte @ opacomp_deps_js in
622
623 let opa_prefix = Pathname.pwd / !Options.build_dir in
624
625 let opa_libs_dir = "lib" / "opa" / "static" in
626
627 let opa_share_dir = "share" / "opa" in
628
629 let copy_lib_to_runtime lib =
630 let modules = string_list_of_file (lib -.- "mllib") in
631 let files =
632 List.fold_left
633 (fun acc f ->
634 let dir, modl = Pathname.dirname f, Pathname.basename f -.- "cmi" in
635 List.filter (fun m -> Pathname.exists (opa_prefix / m))
636 [dir / String.uncapitalize modl; dir / String.capitalize modl] @ acc)
637 [] modules
638 in
639 let stubs =
640 List.map (Pathname.update_extension !Options.ext_lib) (dir_ext_files "clib" (mlstate_lib_dir lib))
641 in
642 let files = stubs @ files in
643 Cmd(S(link_cmd :: List.map (fun f -> P (opa_prefix / f)) files @ [ P (opa_prefix / opa_libs_dir) ]))
644 in
645
646 rule "opa run-time libraries"
647 ~deps:("libbase"/"mimetype_database.xml" :: opacomp_deps_native)
648 ~stamp:"runtime-libs.stamp"
649 (fun _env _build ->
650 let mllibs = List.filter (fun f -> Pathname.check_extension f "cmxa") opacomp_deps_native in
651 let mllibs = List.map Pathname.remove_extension mllibs in
652 let copylibs = List.map copy_lib_to_runtime mllibs in
653 Seq[
654 Cmd(S[Sh"rm"; A"-rf"; P (opa_prefix / opa_libs_dir)]);
655 Cmd(S[Sh"mkdir"; A"-p"; P (opa_prefix / opa_libs_dir)]);
656 Cmd(S[Sh"rm"; A"-rf"; P (opa_prefix / opa_share_dir)]);
657 Cmd(S[Sh"mkdir"; A"-p"; P (opa_prefix / opa_share_dir)]);
658 Cmd(S(link_cmd :: List.map (fun f -> P (opa_prefix / f)) opacomp_deps_native
659 @ [ P (opa_prefix / opa_libs_dir) ]));
660 Cmd(S(link_cmd :: List.map (fun f -> P (opa_prefix / f -.- !Options.ext_lib)) mllibs
661 @ [ P (opa_prefix / opa_libs_dir) ]));
662 Cmd(S(link_cmd :: P (opa_prefix / "libbase" / "mimetype_database.xml") :: [ P (opa_prefix / opa_share_dir / "mimetype_database.xml") ]));
663 Seq copylibs
664 ]
665 );
666
667 let opacomp build src dst_ext opt =
668 build_list build
669 (List.map ((/) (Pathname.dirname src)) (string_list_of_file (src-.-"depends")));
670 let dst = Pathname.update_extension dst_ext src in
671 Cmd(S[
672 Sh("MLSTATELIBS=\""^ opa_prefix ^"\"");
673 get_tool "opa-bin"; opt;
674 A"--verbose";(* A"--no-opa-walker"; *)
675 opaopt;
676 A"-o"; P dst; P src
677 ])
678 in
679
680 rule "opa and server dependencies"
681 ~deps:("runtime-libs.stamp" :: tool_deps "opa-bin")
682 ~stamp:"opacomp.stamp"
683 (fun env build -> Nop);
684
685 rule "opackdep: .opack -> .opack.depends"
686 ~dep:"%.opack"
687 ~prod:"%.opack.depends"
688 (fun env build ->
689 Cmd(S[P"grep"; A"-v"; A"^\\w*-"; P(env "%.opack"); Sh">"; P(env "%.opack.depends"); Sh"|| true"]));
690
691 (* A rule to build applications using the stdlib (e.g. opadoc) *)
692 rule "opacomp: .opack -> .native"
693 ~deps: ("%.opack"::"%.opack.depends"::"opa-packages.stamp"::"opacomp.stamp"::[])
694 ~prod: "%.native"
695 (fun env build ->
696 let dir = Pathname.dirname (env "%") in
697 let mano_depends = Pathname.pwd / (env "%.depends") in
698 if Pathname.exists mano_depends then (
699 build_list build (List.map ((/) dir) (string_list_of_file mano_depends))
700 );
701 build_list build (List.map ((/) dir) (string_list_of_file (env "%.opack.depends")));
702 opacomp build (env "%.opack") "native"
703 (S[ A"-I" ; P stdlib_packages_dir ; A"--project-root" ; P dir]));
704
705 rule "opacomp: .opack -> .byte"
706 ~deps: ("%.opack"::"%.opack.depends"::"opa-packages.stamp"::"opacomp-byte.stamp"::[])
707 ~prod: "%.byte"
708 (fun env build ->
709 let dir = Pathname.dirname (env "%") in
710 build_list build (List.map ((/) dir) (string_list_of_file (env "%.opack.depends")));
711 opacomp build (env "%.opack") "byte" (S[A"-I";P stdlib_packages_dir]));
712 (*
713 (A"--bytecode"));
714 Used to give this option to opa-bin, but since the opa package are build by ocamlbuild,
715 we do not generated bytecode version of opa-packages, making the bytecode compilation
716 of server not available anymore.
717 *)
718
719 (* temporary and unreliable *)
720 rule "opadep: .opa -> .opa.depends"
721 ~dep: "%.opa"
722 ~prod: "%.opa.depends"
723 (fun env build ->
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
724 let dep_opx_regex = "^ *import \\*\\(.\\+\\) *$" in
725 let dep_opp_regex = "^ *import-plugin \\*\\(.\\+\\) *$" in
726 let sed_dep dep_regex redir dest = S[sed; A"-n"; A("s%"^dep_regex^"%\\1.opx%p"); P(env "%.opa"); Sh redir; P dest] in
727 Seq[
728 Cmd(sed_dep dep_opp_regex ">" (env "%.opa.depends"));
729 Cmd(sed_dep dep_opx_regex ">>" (env "%.opa.depends"))
730 ]
731 )
732 ;
fccc6851 » MLstate
2011-06-21 Initial open-source release
733
734 rule "opacomp: .opa -> .native"
735 ~deps: ("%.opa"::"%.opa.depends"::"opacomp.stamp"::[])
736 ~prod: "%.native"
737 (fun env build -> opacomp build (env "%.opa") "native" N);
738
739 rule "opacomp: .opa -> .byte"
740 ~deps: ("%.opa"::"%.opa.depends"::"opacomp-byte.stamp"::[])
741 ~prod: "%.byte"
742 (fun env build -> opacomp build (env "%.opa") "byte" (A"--bytecode"));
743
744 rule "opa bash_completion: opa-bin -> bash_completion"
745 ~deps: (tool_deps "opa-bin")
746 ~prod: "bash_completion"
747 (fun env build ->
748 Seq[Cmd(S[get_tool "opa-bin"; A"--bash-completion"])]);
749
750 (* -- OPA packages -- *)
751
752 let package_to_dir s0 =
753 let s = String.copy s0 in
754 for i = 0 to String.length s - 1 do
755 if s.[i] = '.' then s.[i] <- '/'
756 done;
757 s
758 in
759 let dir_to_package s0 =
760 let s = String.copy s0 in
761 let len_std = String.length stdlib_packages_dir in
762 let pfx,s = (* remove optional stdlib_packages_dir prefix *)
763 try
764 let pfx = String.sub s 0 len_std in
765 if pfx = stdlib_packages_dir
766 then pfx, String.sub s (len_std + 1) (String.length s - len_std - 1)
767 else "", s
768 with Invalid_argument _ -> "", s
769 in
770 for i = 0 to String.length s - 1 do
771 if s.[i] = '/' then s.[i] <- '.'
772 done;
773 pfx, s
774 in
775
776 let module RuleFailure = struct exception E end in
777 let files_of_package pkg =
778 let pkdir = package_to_dir pkg in
779 if not (Pathname.is_directory (Pathname.pwd / pkdir)) then
780 let () = Printf.eprintf "Error: can not find sources for package %s (directory %s does not exist)\n" pkg pkdir in
781 raise RuleFailure.E
782 else
783 let opack = dir_ext_files "opack" (Pathname.pwd / pkdir) in
784 let files = dir_ext_files "opa" (Pathname.pwd / pkdir) in
785 let files = files @ opack in
786 (*
787 return relative filenames
788 *)
789 let files =
790 let len = String.length Pathname.pwd + 1 in (* the additinal '/' *)
791 let relative_part s = String.sub s len (String.length s - len) in
792 List.map relative_part files
793 in
794 (*
795 When you compare 2 branches, if the order of opa sources is not deterministic, you can become crazy
796 *)
797 let files = List.sort String.compare files in
798 files in
799
800 let make_all_packages = stdlib_packages_dir/"all_packages.sh" in
801 let all_packages_file = stdlib_packages_dir/"all.packages" in
802
803 rule "all.packages"
804 ~dep: make_all_packages
805 ~prod: all_packages_file
806 (fun env build ->
807 Cmd(S[
808 Sh"cd"; P (Pathname.pwd / stdlib_packages_dir); Sh"&&";
809 P"./all_packages.sh"; Sh">"; P (Pathname.pwd / !Options.build_dir / all_packages_file);
810 ])
811 );
812
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
813 let make_all_plugins = stdlib_packages_dir/"all_plugins.sh" in
814 let all_plugins_file = stdlib_packages_dir/"all.plugins" in
815
816 rule "all.plugins"
817 ~dep: make_all_plugins
818 ~prod: all_plugins_file
819 (fun env build ->
820 Cmd(S[
821 Sh"cd"; P (Pathname.pwd / stdlib_packages_dir); Sh"&&";
822 P"./all_plugins.sh"; Sh">"; P (Pathname.pwd / !Options.build_dir / all_plugins_file);
823 ])
824 );
825
826
827
fccc6851 » MLstate
2011-06-21 Initial open-source release
828 let package_building ~name ~stamp ~stdlib_only ~rebuild =
829 rule name
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
830 ~deps:[opacapi_validation;all_plugins_file;all_packages_file;"opacomp.stamp"]
fccc6851 » MLstate
2011-06-21 Initial open-source release
831 ~stamp
832 ~prod:"i_dont_exist" (* forces ocamlbuild to always run the command *)
833 (fun env build ->
834 try
7178477b » OpaOnWindowsNow
2011-10-20 [feature] plugin: activate compilation of stdlib imported plugins
835 let plugins = string_list_of_file all_plugins_file in
836 let plugins = List.map (fun f -> "plugins" / f / f -.- "oppf") plugins in
837 build_list build plugins;
fccc6851 » MLstate
2011-06-21 Initial open-source release
838 let packages = string_list_of_file all_packages_file in
839 let packages =
840 if stdlib_only
841 then
842 let stdlib = "stdlib.core" in
843 List.filter (fun package ->
844 String.length package > String.length stdlib &&
845 stdlib = String.sub package 0 (String.length stdlib)) packages
846 else packages in
847 let list_package_files = List.map
848 (fun pkg ->
849 let files = files_of_package pkg in
850 (*
851 Copy in _build the opa files of the packages.
852 In this way, files given to the compiler are relative,
853 and api files are generated in the _build
854 This makes also that the packages does not contain absolute filename,
855 which is not valid wrt the deb checker.
856 *)
857 build_list build files;
858 (pkg, files)) packages in
859 let conf =
860 List.concat (
861 List.map
862 (fun (pkg, files) ->
863 (pkg ^ ":\n") ::
864 (
865 (* auto import *)
866 let prefix = "stdlib.core" in
867 let len = String.length prefix in
868 if String.length pkg >= String.length prefix && String.sub pkg 0 len = prefix
869 then (
870 if pkg = prefix
871 then ""
872 else
873 (* subdirectory of stdlib.core import stdlib.core *)
874 "import stdlib.core"
875 )
876 else " import stdlib.core\n import stdlib.core.*\n"
877 ) ::
878 List.map (fun file -> " " ^ file ^ "\n") files)
879 list_package_files
880 ) in
881 let all_files = List.concat (List.map (fun (_,files) -> List.map (fun f -> P f) files) list_package_files) in
882 let rebuild_opt = if rebuild then [A"--rebuild"] else [] in
883 Seq[
884 Echo(conf, "conf");
885 Cmd(S([Sh("MLSTATELIBS=\""^ opa_prefix ^"\"");
886 get_tool "opa-bin";
887 A"--autocompile";
888 (* A"--verbose-build"; *)
889 A"--conf";P "conf";
890 A"--warn-error"; A"root";
891 A"--project-root"; P Pathname.pwd; (* because the @static_resource in the stdlib expect this *)
892 A"--no-stdlib";
893 opaopt;
894 S all_files;
895 ] @ rebuild_opt));
896 ]
897 with RuleFailure.E ->
898 fail_rule build
899 ) in
900
901 package_building
902 ~name:"opa-packages: meta-rule to build all .opx"
903 ~stamp:"opa-packages.stamp"
904 ~stdlib_only:false
905 ~rebuild:false;
906
907 package_building
908 ~name:"opa-stdlib-packages: meta-rule to build all the stdlib .opx"
909 ~stamp:"opa-stdlib-packages.stamp"
910 ~stdlib_only:true
911 ~rebuild:false;
912
913 () (* This file should be an expr of type unit *)
Something went wrong with that request. Please try again.