Skip to content
This repository
Newer
Older
100644 942 lines (688 sloc) 22.181 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 This application is the register generator, used as a preprocessor
20 on all files including to build the Bypass Standard Library.
21
22 @author Mathieu Barbin
23 @author Mehdi Bouaziz
24 *)
25
26 (*
27 <!> The layout of this file can seems weird,
28 it is a prototype for optimizing maintenace as well as git conflicts
29 and commit diffing. WIP, RFC
30 *)
31
32 (* TODO: refactoring of libbase *)
33 (* open Base is BAD, hoisting modules *)
34 module Arg = Base.Arg
35 module Format = Base.Format
36 module String = Base.String
37
38 (* shorthand *)
39 module BI = BslInterface
40 module BR = BslRegisterLib
41
42 let (|>) x f = f x
43
44 let opp_extension = BslConvention.Extension.plugin
45 let cwd = Sys.getcwd ()
46 let build_dir = ref ""
47 let opp_dir = ref ""
48 let is_default_lib = ref true
49 let bsl_pref = ref "default"
50
51 (**
52 A boolean to say if we want to generate the Plugin and the Loader file.
53 these files are used to link statically a plugin with an executable,
54 so that there is no need to load dynamically a .bypass file for beeing
55 able to load bypasses of a given plugin.
56
57 Currently, the static mode is used only for the opabsl, and the resulting
58 plugin is linked with opa.exe
59
60 The loader file can be used for interpreter in ml only (opatop)
61 to add new primitives.
62 *)
63 let static = ref false
64
65 (**
66 A boolean to say that generated files should be put in the build_dir directly,
67 without storing them in a opp directory.
68 *)
69 let no_opp = ref false
70
71 (**
72 These are the inclusion to give for compiling plugins.
73 This text will be produced in the Makefile, which will interprate shell expension like $(MY_VAR)
74 *)
75 let static_extrapaths () =
76 Printf.sprintf "-I $(%s)/%s" InstallDir.name InstallDir.lib_opa
77
78 (**
79 outputs in build_dir/libname.opp/libnameSuffix.ext
80 path to file may be absolute, in this case, produces
81 all the absolute path inside the build dir
82 *)
83 let finalize_opp_dir () =
84 opp_dir := (
85 if !no_opp then !build_dir
86 else
87 let opp = !bsl_pref ^ "." ^ opp_extension in
88 Filename.concat !build_dir opp
89 )
90
91
92 let output_prefix ?(mkdir=true) prefix filename =
93 (*
94 info about the file
95 *)
96 let dirname =
97 let d = Filename.dirname filename in
98 if d = "." then "" else d
99 in
100 let basename = Filename.basename filename in
101 let filename = prefix ^ basename in
102
103 (*
104 output directory
105 *)
106 let directory = !opp_dir in
107 let directory = Filename.concat directory dirname in
108
109 (*
110 eventually, check or create the directory
111 *)
112 if mkdir then (
113 if not (File.check_create_path directory) then
114 OManager.error "cannot create directory %s" directory
115 );
116
117 let filename = Filename.concat directory filename in
118 filename
119
120
121 module Name =
122 struct
123 let map f () =
124 output_prefix !bsl_pref f
125
126 let jskeys = map (BslConvention.Suffix.jskeys ^ ".js")
127 let loader = map (BslConvention.Suffix.loader ^ ".ml")
128 let marshalplugin = map (BslConvention.Suffix.marshalplugin ^ "." ^ BslConvention.Extension.bypass)
129 let mlruntime = map (BslConvention.Suffix.mlruntime ^ ".ml")
130 let mlruntime_mli = map (BslConvention.Suffix.mlruntime ^ ".mli")
131 let plugin = map (BslConvention.Suffix.plugin ^ ".ml")
132 end
133
134
135 (*
136 This function is used for itering opa and js generated files
137 *)
138 let prefix filename =
139 output_prefix (!bsl_pref ^ "_") filename
140
141
142 let js_code = prefix
143 let opa_code = prefix
144 let opa_interface f = (prefix f)^"i"
145
146
147 let jskeys = ref ""
148 let loader = ref ""
149 let marshalplugin = ref ""
150 let mlruntime = ref ""
151 let mlruntime_mli = ref ""
152 let plugin = ref ""
153
154 let makefile = ref "Makefile"
155 let stamp = ref "stamp"
156 let stamp_date = ref ""
157
158 let customize_lib_name name =
159 let name =
160 String.remove_suffix_if_possible ("."^BslConvention.Extension.plugin) name
161 in
162 if
56308976 » François-Régis Sinot
2011-09-30 [feature] stdlib: more tolerant naming of files
163 not (String.is_universal_ident name)
fccc6851 » MLstate
2011-06-21 Initial open-source release
164 || name.[0] = '_' (* an universal ident is not empty *)
165 then
166 OManager.error (
167 "@{<bright>%S@} is not a valid plugin name@\n"^^
168 "Plugin name should be alphanumeric and start with a letter"
169 )
170 name
171 ;
172 let name = BslConvention.plugin_name name in
173
174 is_default_lib := false ;
175 bsl_pref := name ;
176 ()
177
178
179 let finalize_options () =
180 finalize_opp_dir () ;
181
182 jskeys := Name.jskeys () ;
183 loader := Name.loader () ;
184 marshalplugin := Name.marshalplugin () ;
185 mlruntime := Name.mlruntime () ;
186 mlruntime_mli := Name.mlruntime_mli () ;
187 plugin := Name.plugin () ;
188
189 makefile := output_prefix "" !makefile ;
190 stamp := output_prefix "" !stamp ;
191
192 ()
193
194
195 let spliter g =
196 List.map String.trim
461365b0 » Louis Gesbert
2011-06-23 [cleanup] Base.String: changed String.split to a much simpler String.…
197 (String.slice_chars "{} ,;" g)
fccc6851 » MLstate
2011-06-21 Initial open-source release
198
199
200 let itersplit f sss = List.iter f (spliter sss)
201
202
203 let rename_factory src ml filename =
204 let s = if String.is_suffix ("."^ml) filename then filename else
205 (File.chop_extension filename)^"."^ml in
206 src := s
207
208
209 let rename_pair (ml, mli) src head filename =
210 let s =
211 if String.is_suffix ("."^ml) filename
212 then Filename.chop_extension filename
213 else filename in
214 src := s^"."^ml ;
215 head := s^"."^mli ;
216 ()
217
218
219 (* a *)
220
221
222 let auto_build = ref true
223
224
225 (* b *)
226
227
228 let bypass_plugins = MutableList.create ()
229 let bypass_plugins_add_file files =
230 List.iter (
231 fun file ->
232 if String.is_suffix ("." ^ BslConvention.Extension.bypass) file
233 then MutableList.add bypass_plugins (BslDynlink.MarshalPlugin file)
234 else MutableList.add bypass_plugins (BslDynlink.SharedObject file)
235 )
236 (spliter files)
237
238
239 (* c *)
240
241
242 let check_style = ref false
243
244
245 let clean = ref false
246 let clean_would_only = ref false
247
248
249 (* d *)
250
251
252 let default_iformats = ref true
253
254
255 (* e *)
256
257
258 let extrapaths = MutableList.create ()
259 let extrapaths_add d =
260 let existing_dir d = Sys.file_exists d && Sys.is_directory d in
261 let iter d =
262 if d.[0] <> '+' && not (existing_dir d)
263 then OManager.error "Option -I %S\nNo such file or directory" d
264 else (
265 let d =
266 if File.is_relative_include_path d
267 then
268 Filename.concat cwd d
269 else d
270 in
271 MutableList.add extrapaths d
272 )
273 in
274 List.iter iter (Arg.split d)
275
276
277 (* f *)
278
279
280 let files = MutableList.create ()
281 let files_generated = ref 0
282
283
284 (* j *)
285
286
287 let js_files = MutableList.create ()
288
6f114593 » OpaOnWindowsNow
2011-10-18 [feature] bslregister: activate js validation
289 let js_validator = ref (Some "js")
fccc6851 » MLstate
2011-06-21 Initial open-source release
290 let js_validator_files = MutableList.create ()
6f114593 » OpaOnWindowsNow
2011-10-18 [feature] bslregister: activate js validation
291 let js_validator_files_set = ref StringSet.empty
fccc6851 » MLstate
2011-06-21 Initial open-source release
292 let js_validator_add_file s =
293 List.iter (fun f ->
294 if not (File.is_regular f)
295 then OManager.error "cannot find file %S (js-validation)" f
296 else MutableList.add js_validator_files f)
297 (spliter s)
298
299 let js_validator_options = MutableList.create ()
300 let js_validator_add_option o =
301 MutableList.add js_validator_options o
302
303
304 (* m *)
305
306
307 let ml_flags = MutableList.create ()
308 let mlopt_flags = MutableList.create ()
309
310
311 (* r *)
312
313
314 let rename_mlruntime = rename_pair ( "ml" , "mli" ) mlruntime mlruntime_mli
315
316
317 (* u *)
318
319
320 let unsafe_js = ref false
321 let unsafe_opa = ref false
322
323
324 let plugin_inclusion file =
325 let inclusion = BslConvention.inclusion ~cwd file in
326 MutableList.add extrapaths inclusion.BslConvention.extrapath ;
327 bypass_plugins_add_file inclusion.BslConvention.plugin ;
328 ()
329
330
331 (* following guidelines for command line tools *)
332
333
334 let (!>) = Format.sprintf
335
336
337 let spec = [
338
339 (* b *)
340
341
342 "--build-dir",
343 Arg.Set_string build_dir,
344 !>
345 " Change the build directory. Default is $PWD" ;
346
347
348 (* c *)
349
350
351 "--check-style",
352 Arg.Set check_style,
353 !>
354 " Make some more check about some guidelines used in the files" ;
355
356
357 "--clean",
358 Arg.Symbol (["-n" ; "-f"], (
359 function
360 | "-f" ->
361 clean := true
362 | _ ->
363 clean := true;
364 clean_would_only := true
365 )),
366 !>
367 " With -n, it only says the files which would be cleaned, with '-f' the files are removed" ;
368
369
370 (* i *)
371
372
373 "-I",
374 Arg.String extrapaths_add,
375 !>
376 " Add path to external librairies for the compilation" ;
377
378 (* j *)
379
380 "--js-validator",
381 Arg.String (fun s -> js_validator := Some s),
382 !>
383 " Specify a js-validator (default is %a)" (Option.pp Format.pp_print_string) !js_validator ;
384
385
386 "--js-validator-file",
387 Arg.String js_validator_add_file,
388 !>
389 "<file> Add an js init file for the js-validation only" ;
390
391
392 "--js-validator-off",
393 Arg.Unit (fun () -> js_validator := None),
394 !>
395 " Disable the js validation (sad)" ;
396
397
398 "--js-validator-opt",
399 Arg.String js_validator_add_option,
400 !>
401 "<opt> Add an shell option for the the js-validator" ;
402
403
404 (* l *)
405
406
407 (* m *)
408
409
410 "--ml",
411 Arg.String (fun s -> List.iter (MutableList.add ml_flags) (Arg.split s)),
412 !>
413 "<flags> Add options for ocaml compilation (both byte and native)" ;
414
415
416 "--mlopt",
417 Arg.String (fun s -> List.iter (MutableList.add mlopt_flags) (Arg.split s)),
418 !>
419 "<flags> Add options for ocaml native compilation" ;
420
421 (* n *)
422
423 "--no-build",
424 Arg.Clear auto_build,
425 !>
426 " Do not build the plugin, just generate opp-files" ;
427
428
429 "--no-default-iformats",
430 Arg.Clear default_iformats,
431 !>
432 " Do not load default format for ##include" ;
433
434
435 "--no-opp",
436 Arg.Set no_opp,
437 !>
438 " Produces files in the build_dir directly, do not produce any opp directoy" ;
439
440
441 (* o *)
442
443
444 "-o",
445 Arg.String customize_lib_name,
446 !>
447 "<name> Specify the name of the plugin, default is %s"
448 !bsl_pref ;
449
450
451 (* p *)
452
453
454 "--plugin",
455 Arg.String plugin_inclusion,
456 !>
457 "<opp> Take the following argument as an opa plugin (opp)" ;
458
459
460 (* u *)
461
462
463 "--unsafe-js",
464 Arg.Set unsafe_js,
465 !>
466 " Activate unsafe-js mode (ignore js errors)" ;
467
468
469 "--unsafe-opa",
470 Arg.Set unsafe_opa,
471 !>
472 " Activate unsafe-opa mode (ignore opa errors)" ;
473
474 (* s *)
475
476 "--static",
477 Arg.Set static,
478 !>
479 "produces files for static linking with opa.exe (not for standard distrib)" ;
480
481 ]
482
483
484 let anon_fun file =
485 match File.extension file with
486
487 | opp when opp = BslConvention.Extension.plugin ->
488 plugin_inclusion file
489
490 | js ->
491 if js = "js"
492 then (
493 (*
494 The js files are indexed by their basename.
495 *)
6f114593 » OpaOnWindowsNow
2011-10-18 [feature] bslregister: activate js validation
496 let key = file in
497 if StringSet.mem key (!js_validator_files_set)
fccc6851 » MLstate
2011-06-21 Initial open-source release
498 then
499 OManager.error (
500 "Found several js files with the same basename : @{<bright>%s@}@\n"^^
501 "@[<2>{@<bright>Hint@}:@\n"^^
502 "Perhaps the same file is passed several time in the command line@\n"^^
503 "or maybe you could rename one of the clashing javascript files@]@\n"
504 )
505 file
506 ;
6f114593 » OpaOnWindowsNow
2011-10-18 [feature] bslregister: activate js validation
507 js_validator_files_set := StringSet.add key (!js_validator_files_set);
fccc6851 » MLstate
2011-06-21 Initial open-source release
508 MutableList.add js_files file
509 ) ;
510 MutableList.add files file
511
512
513 let usage_msg =
9a4a8eed » Mathieu Baudet
2011-12-19 [enhance] help/manpages: global pass for improving help messages of O…
514 !> "@{<bright>%s@}: Opa External Libraries Register\nUsage: %s [options] files\n"
515 Sys.argv.(0) Sys.argv.(0)
fccc6851 » MLstate
2011-06-21 Initial open-source release
516
517
518 let parse () =
519 let spec = (
ee9137a2 » Mathieu Baudet
2011-12-13 [cleanup] options: removed useless () argument to cmdline options
520 WarningClass.Arg.options @
fccc6851 » MLstate
2011-06-21 Initial open-source release
521 (OManager.Arg.version "bslregister" :: OManager.Arg.options) @
522 BslLib.Arg.options @
523 spec
524 )
525
526 |> Arg.add_bash_completion
527 |> Arg.sort
528 |> Arg.align
529
530 in
9a4a8eed » Mathieu Baudet
2011-12-19 [enhance] help/manpages: global pass for improving help messages of O…
531 Arg.parse spec anon_fun (usage_msg^"Options:") ;
fccc6851 » MLstate
2011-06-21 Initial open-source release
532 finalize_options ()
533
534
535 (* ======================================================================= *)
96b18ab5 » Mathieu Baudet
2011-12-19 [fix] bslregister: 2 minor typos in comments
536 (** {6 Makefile Generation} *)
fccc6851 » MLstate
2011-06-21 Initial open-source release
537 (* ======================================================================= *)
538 module Makefile :
539 sig
540 (**
541 Return a buffer containing the generated Makefile.
542 *)
543 val generate : unit -> Buffer.t
544 end =
545 struct
546 (**
96b18ab5 » Mathieu Baudet
2011-12-19 [fix] bslregister: 2 minor typos in comments
547 For lisibility of this generation there, we use the add_substitute function
fccc6851 » MLstate
2011-06-21 Initial open-source release
548 of the [Buffer] module. This means that we use a list of binding for inserting
549 dynamic parts into this generated makefile.
550 As we generating a Makefile, we need to generate the $ character, in this case,
551 it is echaped '\$'.
552 *)
553
554 let bindings () =
555 let extrapaths =
556 static_extrapaths () ^ (
557 String.concat_map ~left:" " " " (Printf.sprintf "-I %s")
558 (MutableList.to_list extrapaths)
559 ) in
560 let suffix = String.concat " " (
561 BslConvention.Suffix.mlruntime ::
562 if !static then [
563 BslConvention.Suffix.loader ;
564 BslConvention.Suffix.plugin ;
565 ] else []
566 )
567 in
568 let date =
569 let d = DebugTracer.now () in
570 stamp_date := d ;
571 d
572 in
573
574 [
575
576 (* c *)
577
578 "command", String.concat " " (Array.to_list Sys.argv) ;
579
580 (* d *)
581
582 "date", date ;
583
584 (* g *)
585
586 "generator", Sys.argv.(0) ;
587
588 (* i *)
589
590 "include", extrapaths ;
591
592 (* m *)
593
594 "ml_flags", String.concat " " (MutableList.to_list ml_flags) ;
595 "mlopt_flags", String.concat " " (MutableList.to_list mlopt_flags) ;
596
597 (* p *)
598
599 "plugin", !bsl_pref ;
600
601 (* s *)
602
603 "suffix", suffix ;
604
605 (* v *)
606
607 "version", BuildInfos.version_id ;
608 ]
609
610 let makefile_pattern =
611 "# ============================== #
612 # ==== BSL-CUSTOMLIB-MAKER ===== #
613 # ========== MLstate =========== #
614
615 # Generated Makefile by $(generator) version $(version) : $(date)
616 # from command : $(command)
617
618 OPP=$(plugin)
619
620 SUFFIX=$(suffix)
621 INCLUDE=$(include)
622
623 OCAML_FLAGS=$(ml_flags)
624 OCAMLOPT_FLAGS=$(mlopt_flags)
625 "
626
627 let static_part = "
628 TARGETS_CMI=$(patsubst %, $(OPP)%.cmi, $(SUFFIX))
629 TARGETS_CMX=$(patsubst %, $(OPP)%.cmx, $(SUFFIX))
630
631 all: $(TARGETS_CMI) $(TARGETS_CMX)
632
633 OCAMLOPT ?= ocamlopt.opt
634 TRX ?= $(MLSTATELIBS)/bin/trx
635
636 %.ml : %.trx
637 \t$(TRX) $^ > $@
638
639 %.cmx : %.ml %.cmi
640 \t$(OCAMLOPT) $(OCAML_FLAGS) $(OCAMLOPT_FLAGS) $(INCLUDE) -c $<
641
642 %.cmi : %.mli
643 \t$(OCAMLOPT) $(OCAML_FLAGS) $(OCAMLOPT_FLAGS) $(INCLUDE) -c $<
644
645 %.cmi : %.ml
646 \t$(OCAMLOPT) $(OCAML_FLAGS) $(OCAMLOPT_FLAGS) $(INCLUDE) -c $<
647
648 clean :
649 \trm -f *.cmx *.cmo *.o *.cmi
650
651 wclean :
652 \t@echo \"Would remove *.cmx *.cmo *.o *.cmi\"
653 "
654
655 let generate () =
656 let bindings = bindings () in
657 let map = StringMap.from_list bindings in
658 let subst var =
659 try StringMap.find var map with
660 | Not_found ->
661 OManager.apologies ();
662 OManager.printf (
663 "@[<2>@{<bright>Hint@}:@\nvar %S is not found during Makefile generation.@]@\n"
664 )
665 var
666 ;
667 assert false
668 in
669 let buf = Buffer.create 1024 in
670 let () =
671 try
672 Buffer.add_substitute buf subst makefile_pattern
673 with
674 | Not_found ->
675 OManager.apologies ();
676 OManager.printf (
677 "@[<2>@{<bright>Hint@}:@\nthe closing character of a parenthesized variable@\n"^^
678 "cannot be found during Makefile generation.@]@\n"
679 ) ;
680 assert false
681 in
682 Buffer.add_string buf static_part ;
683 buf
684
685 end
686 (* ======================================================================= *)
687
688
689 let iter_generated_files fct =
690
691 MutableList.iter (
692 fun f ->
693 match File.extension f with
694 | "opa" ->
695 fct (opa_code f) ;
696 fct (opa_interface f) ;
697 ()
698 | "js" ->
699 fct (js_code f) ;
700 ()
701 | _ -> ()
702 ) files ;
703
704 fct !jskeys ;
705 fct !marshalplugin ;
706 fct !mlruntime ;
707 fct !mlruntime_mli ;
708
709 if !static then (
710 fct !loader ;
711 fct !plugin ;
712 ) ;
713
714 fct !makefile ;
715 fct !stamp ;
716
717 ()
718
719
720 let check_safety_overwrite () =
721 let fct n =
722 if MutableList.mem n files then (
723 OManager.error (
724 "@[<2><!> bslregister refuse to do that !@\n"^^
725 "The file @{<bright>%S@} would be @{<bright>overwritten@} during the process@]"
726 ) n
727 ) in
728 iter_generated_files fct
729
730
731 let remove_file f =
732 try Unix.unlink f with Unix.Unix_error (e,_,_) ->
733 OManager.verbose "@[<2><!> Cannot clean @{<bright>%s@}:@\n%s@]" f (Unix.error_message e)
734
735
736 (* preprocessing format, for ##include *)
737 let may_add_format () =
738 if !default_iformats then (
739 BslLib.HLParser.add_iformat BslLib.HLParser.default_opa_iformats ;
740 ()
741 )
742
743
744 (* build BR.options from the current state of parameters *)
745 let bslregister_options ()=
746
747 let basename = !bsl_pref in
748
749 let bypass_plugins = MutableList.to_list bypass_plugins in
750
751 let check_style = !check_style in
752
753 let js_files = MutableList.to_list js_files in
754
755 let js_validator =
756 Option.map (
757 fun js -> (js, MutableList.to_list js_validator_files), MutableList.to_list js_validator_options
758 ) (!js_validator)
759 in
760
761 let ml_plugin_filename = !plugin in
762 let ml_runtime_filename = !mlruntime in
763
764 let unsafe_js = !unsafe_js in
765 let unsafe_opa = !unsafe_opa in
766
767
768 let options = {
769 BI.
770
771 basename ;
772 bypass_plugins ;
773
774 check_style ;
775
776 js_files ;
777 js_validator ;
778
779 ml_plugin_filename ;
780 ml_runtime_filename ;
781
782 unsafe_js ;
783 unsafe_opa ;
784
785 } in
786 options
787
788
789 (* clean, or just say what would be cleaned *)
790 let may_clean () =
791 if !clean then (
792 let rm f =
793 if !clean_would_only
794 then OManager.printf "Would remove @{<bright>%s@}@\n" f
795 else (
796 OManager.unquiet "rm -f %s" f ;
797 remove_file f ;
798 ()
799 )
800 in iter_generated_files rm;
801 exit 0
802 )
803
804 (* open_out_bin : read ocaml doc,
805 Marshal should be used with binary channel
806 for a win OS compatilibity *)
807 let handle_open_out file =
808 try open_out_bin file
809 with
810 | Sys_error s ->
811 OManager.error "@[<2>@{<bright>bslregister@}: cannot open_out @{<bright>%s@}:@\n%s@]" file s
812
813
814 let handle_close_out file oc =
815 try close_out oc
816 with
817 | Sys_error s ->
818 OManager.error "@[<2>@{<bright>bslregister@}: cannot close_out @{<bright>%s@}:@\n%s@]" file s
819
820
821 let output filename pp a =
822 OManager.verbose "writing file @{<bright>%S@}..." filename ;
823 let oc = handle_open_out filename in
824 pp oc a ;
825 handle_close_out filename oc ;
826 incr(files_generated) ;
827 ()
828
829
830 let make_iterator rename =
831 let output filename =
832 let filename = rename filename in
833 output filename
834 in
835 { BR.output = output }
836
837
838 (* after finalization of register session, actually produce files *)
839 let files_generation ( finalized_t : BR.finalized_t ) =
840 let iterator_js_code = make_iterator js_code in
841 let iterator_opa_code = make_iterator opa_code in
842 let iterator_opa_interface = make_iterator opa_interface in
843
844 BR.out_js_code iterator_js_code finalized_t ;
845 BR.out_opa_code iterator_opa_code finalized_t ;
846 BR.out_opa_interface iterator_opa_interface finalized_t ;
847
848 output !jskeys BR.out_js_keys finalized_t ;
849
850 output !marshalplugin BR.out_ml_marshal_plugin finalized_t ;
851 output !mlruntime BR.out_ml_runtime finalized_t ;
852 output !mlruntime_mli BR.out_ml_runtime_mli finalized_t ;
853
854 if !static then (
855 output !loader BR.out_ml_loader finalized_t ;
856 output !plugin BR.out_ml_plugin finalized_t ;
857 ) ;
858
859 output !makefile Buffer.output_buffer (Makefile.generate ()) ;
860 output !stamp Pervasives.output_string !stamp_date ;
861
862 ()
863
864
865 (* Checking options *)
866 let check_options options =
867 (* if needed, add some checks *)
868 ignore options ;
869
870 (* default lib name *)
871 if !is_default_lib then
872 OManager.warning ~wclass:WarningClass.bsl_register (
873 "@[<2>You did not precise a name for your lib.@\n"^^
874 "By default the lib name will be @{<bright>%S@}.@]@\n"^^
875 "@[<2>@{<bright>Hint@}:@\n"^^
876 "use option @{<bright>-o@} <libname>@]" )
877 !bsl_pref ;
878
879 ()
880
881 (* === *)
882
883 (* Main *)
884 let _ =
885 try
886 WarningClass.load_set BR.warning_set;
887 BR.set_signal_sigint ();
888 parse ();
889 check_safety_overwrite ();
890 may_clean ();
891 OManager.this_is_tool "bslregister";
892 may_add_format ();
893 if MutableList.length files = 0 then (
894 OManager.unquiet "no input files";
895 exit 0
896 );
897 let session =
898 let options = bslregister_options () in
899 check_options options ;
900 BR.create ~options
901 in
902 let session = MutableList.fold_left (
903 fun session file ->
904 OManager.verbose "registering file @{<bright>%S@}" file ;
905 BR.preprocess_file session file
906 ) session files
907 in
908 OManager.verbose "generating files ...";
909 let finalized_t = BR.finalize session in
910 files_generation finalized_t ;
911
6f114593 » OpaOnWindowsNow
2011-10-18 [feature] bslregister: activate js validation
912 BR.js_validator finalized_t;
913
fccc6851 » MLstate
2011-06-21 Initial open-source release
914 OManager.verbose "successfull generation of plugin files : @{<bright>%d@} files" !files_generated ;
915
916 if !auto_build then (
917 OManager.verbose "building plugin...";
918 let ret = Sys.command (Printf.sprintf "make -C %s -f %s" !opp_dir (Filename.basename !makefile)) in
919 if ret <> 0
920 then
921 OManager.error "building failure due to error(s) in source files@\n"
922 else
923 OManager.verbose "successfull compilation of plugin @{<bright>%s@}" !bsl_pref
924 );
925
926 (* if success : remove unused logs from previous error *)
927 if not (!unsafe_opa || !unsafe_js) then ignore (Sys.command "rm -f bsl_log_*");
928
929 ()
930 with
931 | BR.SigInt ->
932 OManager.error
933 "building process @{<bright>not accomplished@} due to an @{<bright>user interruption@}"
934 | e ->
935 let backtrace = Printexc.get_backtrace () in
936 OManager.apologies ();
937 (* if not BuildInfos.is_release then ( *)
938 (* OManager.printf "Now you get an extra hint, because this is not the @{<bright>release@} mode:@\n"; *)
939 OManager.printf "@[<2>@{<bright>Hint@}:@\n%s@]@\n@{<bright>Backtrace@}:@\n%s@\n"
940 (Printexc.to_string e) backtrace;
941 (* ); *)
942 exit 2
Something went wrong with that request. Please try again.