Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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