Permalink
Browse files

Refactor ocamlbuild build plugin to have some features in doc plugin.

- ExtraArgs, PluginTags are now available for ocamlbuild doc plugin
- '-use-ocamlfind' is set for doc and build plugin.
  • Loading branch information...
1 parent 83981cc commit f2bb1c48372de57f1bb5b4cccb60441fc5d8b469 @gildor478 gildor478 committed Feb 22, 2014
View
@@ -117,7 +117,7 @@ PRECOMMIT_ARGS= \
--exclude _tags
precommit:
- @if command -v OCamlPrecommit > /dev/null; then \
+ -@if command -v OCamlPrecommit > /dev/null; then \
OCamlPrecommit $(PRECOMMIT_ARGS); \
else \
echo "Skipping precommit checks.";\
View
1 _tags
@@ -222,6 +222,7 @@
"src/plugins/ocamlbuild/OCamlbuildPlugin.ml": syntax_camlp4o, pkg_odn.with.syntax
"src/plugins/ocamlbuild/OCamlbuildPlugin.ml": use_ocamlbuild
"src/plugins/ocamlbuild/OCamlbuildDocPlugin.ml": syntax_camlp4o, pkg_odn.with.syntax
+"src/plugins/ocamlbuild/OCamlbuildCommon.ml": syntax_camlp4o, pkg_odn.with.syntax
# TODO: The fact that we need to remove these tags is maybe a bug
<test/test.byte>: -use_base
@@ -28,10 +28,15 @@
open OASISGettext
open BaseEnv
open BaseStandardVar
+open OASISTypes
+
+
+TYPE_CONV_PATH "OCamlbuildCommon"
+
+type extra_args = string list with odn
-let ocamlbuild_clean_ev =
- "ocamlbuild-clean"
+let ocamlbuild_clean_ev = "ocamlbuild-clean"
let ocamlbuildflags =
@@ -128,9 +133,7 @@ let build_dir extra_argv =
(* END EXPORT *)
-
-open OASISTypes
-
+open OASISValues
let fix_build_tools tool pkg =
let fix_build_tools' sct bs =
@@ -175,3 +178,82 @@ struct
let filename_concat fn1 fn2 =
OASISUnixPath.concat (OASISUnixPath.reduce fn1) fn2
end
+
+(** Check OCaml version constraint defined in _oasis. *)
+let check_ocaml_version version pkg =
+ match pkg.ocaml_version with
+ | Some ocaml_version ->
+ let min_ocaml_version = OASISVersion.version_of_string version in
+ OASISVersion.comparator_ge min_ocaml_version ocaml_version
+ | None ->
+ false
+
+
+let ocamlbuild_more_args =
+ OASISFeatures.create "ocamlbuild_more_args"
+ OASISFeatures.alpha
+ (fun () ->
+ s_ "Allow to pass arguments to ocamlbuild.")
+
+
+let ocamlbuild_supports_ocamlfind = check_ocaml_version "3.12.1"
+let ocamlbuild_supports_plugin_tags = check_ocaml_version "4.01"
+
+
+type ocamlbuild_common =
+ {
+ plugin_tags: string option;
+ extra_args: string list;
+ } with odn
+
+
+let ocamlbuild_common_generator pivot_data schm id =
+ let new_field nm = OASISSchema.new_field schm id nm in
+ let plugin_tags =
+ new_field
+ "PluginTags"
+ ~default:None
+ ~feature:ocamlbuild_more_args
+ (opt string_not_empty)
+ (fun () -> s_ "Gives the plugin tags to ocambuild through \
+ '-plugin-tags' (OCaml >= 4.01 only)")
+ pivot_data (fun _ t -> t.plugin_tags)
+ in
+ let extra_args =
+ new_field
+ "ExtraArgs"
+ ~default:[]
+ ~feature:ocamlbuild_more_args
+ command_line_options
+ (fun () -> s_ "Gives extra arguments to ocamlbuild")
+ pivot_data (fun _ t -> t.extra_args)
+ in
+ fun data ->
+ {
+ extra_args = extra_args data;
+ plugin_tags = plugin_tags data;
+ }
+
+
+let extra_args_ocamlbuild_common ~ctxt pkg t =
+ let extra_args =
+ if t.plugin_tags <> None &&
+ not (ocamlbuild_supports_plugin_tags pkg) then begin
+ OASISMessage.error
+ ~ctxt:ctxt
+ (f_ "'XOCamlbuildPluginTags' in only available for OCaml >= 4.01. \
+ Please restrict your requirements with 'OCamlVersion: >= 4.01'");
+ t.extra_args
+ end else begin
+ match t.plugin_tags with
+ | Some tags -> "-plugin-tags" :: ("'" ^ tags ^ "'") :: t.extra_args
+ | None -> t.extra_args
+ end
+ in
+ let extra_args =
+ if ocamlbuild_supports_ocamlfind pkg then
+ "-use-ocamlfind" :: extra_args
+ else
+ extra_args
+ in
+ extra_args
@@ -35,12 +35,18 @@ open BaseStandardVar
TYPE_CONV_PATH "OCamlbuildDocPlugin"
+type run_t =
+ {
+ extra_args: string list;
+ run_path: unix_filename;
+ } with odn
-let doc_build path pkg (cs, doc) argv =
+
+let doc_build run pkg (cs, doc) argv =
let index_html =
OASISUnixPath.make
[
- path;
+ run.run_path;
cs.cs_name^".docdir";
"index.html";
]
@@ -49,11 +55,11 @@ let doc_build path pkg (cs, doc) argv =
OASISHostPath.make
[
build_dir argv;
- OASISHostPath.of_unix path;
+ OASISHostPath.of_unix run.run_path;
cs.cs_name^".docdir";
]
in
- run_ocamlbuild [index_html] argv;
+ run_ocamlbuild (index_html :: run.extra_args) argv;
List.iter
(fun glb ->
BaseBuilt.register
@@ -64,7 +70,7 @@ let doc_build path pkg (cs, doc) argv =
["*.html"; "*.css"]
-let doc_clean t pkg (cs, doc) argv =
+let doc_clean run pkg (cs, doc) argv =
run_clean argv;
BaseBuilt.unregister BaseBuilt.BDoc cs.cs_name
@@ -92,11 +98,12 @@ type t =
libraries: findlib_full list;
intro: unix_filename option;
flags: string list;
+ common: ocamlbuild_common;
}
-let pivot_data =
- data_new_property plugin
+let pivot_data = data_new_property plugin
+let pivot_sub_data = data_new_property plugin
let self_id, all_id =
@@ -167,75 +174,89 @@ let flags =
(* TODO: use -t for title *)
-let doit ctxt pkg (cs, doc) =
-
- let path =
- path cs.cs_data
+let generator =
+ let generator_common =
+ (* Register fields. *)
+ ocamlbuild_common_generator pivot_sub_data OASISDocument.schema all_id
in
+ fun data pkg ->
+ let path = path data in
+
+ let modules_from_libraries =
+ (* Convert findlib name to internal library and compute
+ * the module they shipped.
+ *)
+ let lib_of_findlib =
+ let _, _, library_name_of_findlib_name =
+ OASISFindlib.findlib_mapping pkg
+ in
+ let lib_of_name =
+ List.fold_left
+ (fun mp ->
+ function
+ | Library ({cs_name = name}, bs, lib) ->
+ MapString.add name (bs, lib) mp
+ | _ ->
+ mp)
+ MapString.empty
+ pkg.sections
+ in
+ fun fndlb_nm ->
+ let nm =
+ library_name_of_findlib_name fndlb_nm
+ in
+ MapString.find nm lib_of_name
+ in
+
+ (* Fetch modules from internal libraries *)
+ List.flatten
+ (List.map
+ (fun fndlb_nm ->
+ let bs, lib =
+ lib_of_findlib fndlb_nm
+ in
+ (* Rebase modules in the doc path *)
+ List.map
+ (fun modul ->
+ OASISUnixPath.make_relative
+ path
+ (OASISUnixPath.concat bs.bs_path modul))
+ lib.lib_modules)
+
+ (libraries data))
+ in
- let modules_from_libraries =
- (* Convert findlib name to internal library and compute
- * the module they shipped.
- *)
- let lib_of_findlib =
- let _, _, library_name_of_findlib_name =
- OASISFindlib.findlib_mapping pkg
+ let modules_from_doc =
+ (* Fetch modules defined directly *)
+ modules data
in
- let lib_of_name =
- List.fold_left
- (fun mp ->
- function
- | Library ({cs_name = name}, bs, lib) ->
- MapString.add name (bs, lib) mp
- | _ ->
- mp)
- MapString.empty
- pkg.sections
+
+ let modules =
+ modules_from_libraries @ modules_from_doc
in
- fun fndlb_nm ->
- let nm =
- library_name_of_findlib_name fndlb_nm
- in
- MapString.find nm lib_of_name
- in
-
- (* Fetch modules from internal libraries *)
- List.flatten
- (List.map
- (fun fndlb_nm ->
- let bs, lib =
- lib_of_findlib fndlb_nm
- in
- (* Rebase modules in the doc path *)
- List.map
- (fun modul ->
- OASISUnixPath.make_relative
- path
- (OASISUnixPath.concat bs.bs_path modul))
- lib.lib_modules)
-
- (libraries cs.cs_data))
- in
+ {
+ path = path;
+ modules = modules;
+ libraries = libraries data;
+ intro = None;
+ flags = [];
+ common = generator_common data;
+ }
- let modules_from_doc =
- (* Fetch modules defined directly *)
- modules cs.cs_data
- in
- let modules =
- modules_from_libraries @ modules_from_doc
- in
+let doit ctxt pkg (cs, doc) =
+ let t = generator cs.cs_data pkg in
let ctxt =
(* Create .odocl file *)
add_file
(template_make
(OASISHostPath.add_extension
- (Filename.concat path cs.cs_name)
+ (Filename.concat t.path cs.cs_name)
"odocl")
comment_ocamlbuild
[]
- modules
+ t.modules
[])
ctxt
in
@@ -260,32 +281,38 @@ let doit ctxt pkg (cs, doc) =
cs.cs_name);
set_error
- (modules = [])
+ (t.modules = [])
(Printf.sprintf
(f_ "No module defined for document %s.")
cs.cs_name);
]
in
- ctxt,
+ let run =
{
- chng_moduls =
- [OCamlbuildData.ocamlbuildsys_ml];
-
- chng_main =
- ODNFunc.func_with_arg
- doc_build "OCamlbuildDocPlugin.doc_build"
- path ODN.of_string;
-
- chng_clean =
- Some
- (ODNFunc.func_with_arg
- doc_clean "OCamlbuildDocPlugin.doc_clean"
- path ODN.of_string);
-
- chng_distclean =
- None;
+ run_path = t.path;
+ extra_args = extra_args_ocamlbuild_common ~ctxt:ctxt.ctxt pkg t.common;
}
+ in
+ ctxt,
+ {
+ chng_moduls =
+ [OCamlbuildData.ocamlbuildsys_ml];
+
+ chng_main =
+ ODNFunc.func_with_arg
+ doc_build "OCamlbuildDocPlugin.doc_build"
+ run odn_of_run_t;
+
+ chng_clean =
+ Some
+ (ODNFunc.func_with_arg
+ doc_clean "OCamlbuildDocPlugin.doc_clean"
+ run odn_of_run_t);
+
+ chng_distclean =
+ None;
+ }
let qstrt_completion pkg =
Oops, something went wrong.

0 comments on commit f2bb1c4

Please sign in to comment.