Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file OCamlbuildCommon.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265(******************************************************************************)(* OASIS: architecture for building OCaml libraries and applications *)(* *)(* Copyright (C) 2011-2016, Sylvain Le Gall *)(* Copyright (C) 2008-2011, OCamlCore SARL *)(* *)(* This library is free software; you can redistribute it and/or modify it *)(* under the terms of the GNU Lesser General Public License as published by *)(* the Free Software Foundation; either version 2.1 of the License, or (at *)(* your option) any later version, with the OCaml static compilation *)(* exception. *)(* *)(* This library is distributed in the hope that it will be useful, but *)(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *)(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more *)(* details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this library; if not, write to the Free Software Foundation, *)(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *)(******************************************************************************)(** Functions common to OCamlbuild build and doc plugin
*)openOASISGettextopenBaseEnvopenBaseStandardVaropenOASISTypestypeextra_args=stringlistletocamlbuild_clean_ev="ocamlbuild-clean"letocamlbuildflags=var_define~short_desc:(fun()->"OCamlbuild additional flags")"ocamlbuildflags"(fun()->"")(** Fix special arguments depending on environment *)letfix_argsargsextra_argv=List.flatten[if(os_type())="Win32"then["-classic-display";"-no-log";"-no-links";]else[];ifOASISVersion.comparator_apply(OASISVersion.version_of_string(ocaml_version()))(OASISVersion.VLesser(OASISVersion.version_of_string"3.11.1"))then["-install-lib-dir";(Filename.concat(standard_library())"ocamlbuild")]else[];ifnot(bool_of_string(is_native()))||(os_type())="Win32"then["-byte-plugin"]else[];args;ifbool_of_string(debug())then["-tag";"debug"]else[];ifbool_of_string(tests())then["-tag";"tests"]else[];ifbool_of_string(profile())then["-tag";"profile"]else[];OASISString.nsplit(ocamlbuildflags())' ';Array.to_listextra_argv;](** Run 'ocamlbuild -clean' if not already done *)letrun_clean~ctxtextra_argv=letextra_cli=String.concat" "(Array.to_listextra_argv)in(* Run if never called with these args *)ifnot(BaseLog.exists~ctxtocamlbuild_clean_evextra_cli)thenbeginOASISExec.run~ctxt(ocamlbuild())(fix_args["-clean"]extra_argv);BaseLog.register~ctxtocamlbuild_clean_evextra_cli;at_exit(fun()->tryBaseLog.unregister~ctxtocamlbuild_clean_evextra_cliwith_->())end(** Run ocamlbuild, unregister all clean events *)letrun_ocamlbuild~ctxtargsextra_argv=(* TODO: enforce that target in args must be UNIX encoded i.e. toto/index.html
*)OASISExec.run~ctxt(ocamlbuild())(fix_argsargsextra_argv);(* Remove any clean event, we must run it again *)List.iter(fun(e,d)->BaseLog.unregister~ctxted)(BaseLog.filter~ctxt[ocamlbuild_clean_ev])(** Determine real build directory *)letbuild_dirextra_argv=letrecsearch_argsdir=function|"-build-dir"::dir::tl->search_argsdirtl|_::tl->search_argsdirtl|[]->dirinsearch_args"_build"(fix_args[]extra_argv)(* END EXPORT *)openOASISValuesletfix_build_toolstoolpkg=letfix_build_tools'_bs=ifnot(List.memtoolbs.bs_build_tools)then{bswithbs_build_tools=tool::bs.bs_build_tools}elsebsinletsections=List.fold_left(funaccsct->letsct=matchsctwith|Executable(cs,bs,exec)->letbs=fix_build_tools'sctbsinExecutable(cs,bs,exec)|Library(cs,bs,lib)->letbs=fix_build_tools'sctbsinLibrary(cs,bs,lib)|Object(cs,bs,obj)->letbs=fix_build_tools'sctbsinObject(cs,bs,obj)|Flag_|SrcRepo_|Test_|Doc_assct->sctinsct::acc)[]pkg.sectionsin{pkgwithsections=List.revsections}moduleTag=struct(** [filename_concat fn1 fn2] Concat filename, using semantic of _tags
[fn1] must be a real filename whereas fn2 can contains wildcards.
*)letfilename_concatfn1fn2=OASISUnixPath.concat(OASISUnixPath.reducefn1)fn2end(** Check OCaml version constraint defined in _oasis. *)letcheck_ocaml_versionversionpkg=OASISVersion.StringVersion.comparator_geversionpkg.ocaml_versionletocamlbuild_more_args=OASISFeatures.create"ocamlbuild_more_args"OASISFeatures.alpha(fun()->s_"Allow to pass arguments to ocamlbuild.")letocamlbuild_supports_ocamlfind=check_ocaml_version"3.12.1"letocamlbuild_supports_plugin_tags=check_ocaml_version"4.01"typeocamlbuild_common={plugin_tags:stringoption;extra_args:stringlist;}letocamlbuild_common_generatorpivot_dataschmid=letnew_fieldnm=OASISSchema.new_fieldschmidnminletplugin_tags=new_field"PluginTags"~default:None~feature:ocamlbuild_more_args(optstring_not_empty)(fun()->s_"Gives the plugin tags to ocambuild through \
'-plugin-tags' (OCaml >= 4.01 only)")pivot_data(fun_t->t.plugin_tags)inletextra_args=new_field"ExtraArgs"~default:[]~feature:ocamlbuild_more_argscommand_line_options(fun()->s_"Gives extra arguments to ocamlbuild")pivot_data(fun_t->t.extra_args)infundata->{extra_args=extra_argsdata;plugin_tags=plugin_tagsdata;}letextra_args_ocamlbuild_commonctxtpkgt=letextra_args,ctxt=ift.plugin_tags<>Nonethenbegint.extra_args,OASISPlugin.set_error(not(ocamlbuild_supports_plugin_tagspkg))(s_"'XOCamlbuildPluginTags' in only available for OCaml >= 4.01. \
Please restrict your requirements with 'OCamlVersion: >= 4.01'")ctxtendelsebeginletextra_args=matcht.plugin_tagswith|Sometags->"-plugin-tags"::("'"^tags^"'")::t.extra_args|None->t.extra_argsinextra_args,ctxtendinletextra_args=ifocamlbuild_supports_ocamlfindpkgthen"-use-ocamlfind"::extra_argselseextra_argsinextra_args,ctxt