123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490(******************************************************************************)(* 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 *)(******************************************************************************)(** Generate custom configure/build/doc/test/install system
@author
*)openBaseEnvopenOASISGettextopenOASISTypestypet={cmd_main:command_lineconditional;cmd_clean:(command_lineoption)conditional;cmd_distclean:(command_lineoption)conditional;}letrun=BaseCustom.runletmain~ctxt:_t_extra_args=letcmd,args=var_choose~name:(s_"main command")t.cmd_maininruncmdargsextra_argsletclean~ctxt:_t_extra_args=matchvar_chooset.cmd_cleanwith|Some(cmd,args)->runcmdargsextra_args|_->()letdistclean~ctxt:_t_extra_args=matchvar_chooset.cmd_distcleanwith|Some(cmd,args)->runcmdargsextra_args|_->()moduleBuild=structletmain~ctxttpkgextra_args=main~ctxttpkgextra_args;List.iter(funsct->letevs=matchsctwith|Library(cs,bs,lib)whenvar_choosebs.bs_build->beginletevs,_=BaseBuilt.of_libraryOASISHostPath.of_unix(cs,bs,lib)inevsend|Executable(cs,bs,exec)whenvar_choosebs.bs_build->beginletevs,_,_=BaseBuilt.of_executableOASISHostPath.of_unix(cs,bs,exec)inevsend|_->[]inList.iter(fun(bt,bnm,lst)->BaseBuilt.register~ctxtbtbnmlst)evs)pkg.sectionsletclean~ctxttpkgextra_args=clean~ctxttpkgextra_args;(* TODO: this seems to be pretty generic (at least wrt to ocamlbuild
* considering moving this to BaseSetup?
*)List.iter(function|Library(cs,_,_)->BaseBuilt.unregister~ctxtBaseBuilt.BLibcs.cs_name|Executable(cs,_,_)->BaseBuilt.unregister~ctxtBaseBuilt.BExeccs.cs_name;BaseBuilt.unregister~ctxtBaseBuilt.BExecLibcs.cs_name|_->())pkg.sectionsletdistclean~ctxttpkgextra_args=distclean~ctxttpkgextra_argsendmoduleTest=structletmain~ctxttpkg(cs,_)extra_args=trymain~ctxttpkgextra_args;0.0withFailures->BaseMessage.warning(f_"Test '%s' fails: %s")cs.cs_names;1.0letclean~ctxttpkg_extra_args=clean~ctxttpkgextra_argsletdistclean~ctxttpkg_extra_args=distclean~ctxttpkgextra_argsendmoduleDoc=structletmain~ctxttpkg(cs,_)extra_args=main~ctxttpkgextra_args;BaseBuilt.register~ctxtBaseBuilt.BDoccs.cs_name[]letclean~ctxttpkg(cs,_)extra_args=clean~ctxttpkgextra_args;BaseBuilt.unregister~ctxtBaseBuilt.BDoccs.cs_nameletdistclean~ctxttpkg_extra_args=distclean~ctxttpkgextra_argsend(* END EXPORT *)moduleBuildRuntime=BuildmoduleTestRuntime=TestmoduleDocRuntime=DocopenOASISGettextopenOASISTypesopenOASISValuesopenOASISPluginopenOASISSchemaletnm,ver="Custom",SomeOASISConf.version_shortletconf_plugin=`Configure,nm,verletconf_data=data_new_propertyconf_pluginletbuild_plugin=`Build,nm,verletbuild_data=data_new_propertybuild_pluginletinstall_plugin=`Install,nm,verletinstall_data=data_new_propertyinstall_pluginletuninstall_data=data_new_property~purpose:`Uninstallinstall_pluginlettest_plugin=`Test,nm,verlettest_data=data_new_propertytest_pluginletdoc_plugin=`Doc,nm,verletdoc_data=data_new_propertydoc_plugin(** Add standard fields
*)letadd_fields~schemaiddatanmhlphlp_cleanhlp_distclean=letcmd_main=new_field_conditionalschemaidnmcommand_line(* TODO: remove when fun () -> s_ be replaced *)(fun()->s_hlp)data(fun_t->t.cmd_main)inletcmd_clean=new_field_conditionalschemaid(nm^"Clean")~default:None(optcommand_line)(* TODO: remove when fun () -> s_ be replaced *)(fun()->s_hlp_clean)data(fun_t->t.cmd_clean)inletcmd_distclean=new_field_conditionalschemaid(nm^"Distclean")~default:None(optcommand_line)(* TODO: remove when fun () -> s_ be replaced *)(fun()->s_hlp_distclean)data(fun_t->t.cmd_distclean)inletgeneratordata={cmd_main=cmd_maindata;cmd_clean=cmd_cleandata;cmd_distclean=cmd_distcleandata;}incmd_main,cmd_clean,cmd_distclean,generatorletodn_of_tv=letopenOASISDataNotationinREC("CustomPlugin",[("cmd_main",(odn_of_conditionalodn_of_command_linev.cmd_main));("cmd_clean",(odn_of_conditional(of_optionodn_of_command_line)v.cmd_clean));("cmd_distclean",(odn_of_conditional(of_optionodn_of_command_line)v.cmd_distclean))])(** Standard custom handling. *)letstdiddatanmhlphlp_cleanhlp_distclean=let_,_,_,generator=add_fields~schema:OASISPackage.schemaiddatanmhlphlp_cleanhlp_distcleaningenerator,funplugin_ctxtpkg->lett=generatorpkg.schema_datainplugin_ctxt,{OASISPlugin.chng_moduls=[CustomData.customsys_ml];chng_main=OASISDataNotation.func_with_arg_ctxtmain("CustomPlugin.main")todn_of_t;chng_clean=Some(OASISDataNotation.func_with_arg_ctxtclean("CustomPlugin.clean")todn_of_t);chng_distclean=Some(OASISDataNotation.func_with_arg_ctxtdistclean("CustomPlugin.distclean")todn_of_t);}(* Configure plugin *)letconf_init()=letself_id,id=Configure.createconf_plugininletgenerator,doit=stdid(* TODO: test if replacing conf_data -> build_data generates an error *)conf_data"Conf"(ns_"Run command to configure.")(ns_"Run command to clean configure step.")(ns_"Run command to distclean configure step.")inConfigure.register_actself_iddoit;register_generator_packageidconf_datagenerator(* Build plugin *)letbuild_init()=letself_id,id=Build.createbuild_plugininlet_,_,_,generator=add_fieldsidbuild_data~schema:OASISPackage.schema"Build"(ns_"Run command to build.")(ns_"Run command to clean build step.")(ns_"Run command to distclean build step.")inletdoitplugin_ctxtpkg=lett=generatorpkg.schema_datainplugin_ctxt,{OASISPlugin.chng_moduls=[CustomData.customsys_ml];chng_main=OASISDataNotation.func_with_arg_ctxtBuildRuntime.main("CustomPlugin.Build.main")todn_of_t;chng_clean=Some(OASISDataNotation.func_with_arg_ctxtBuildRuntime.clean("CustomPlugin.Build.clean")todn_of_t);chng_distclean=Some(OASISDataNotation.func_with_arg_ctxtBuildRuntime.distclean("CustomPlugin.Build.distclean")todn_of_t);}inBuild.register_actself_iddoit;register_generator_packageidbuild_datagenerator(* Install plugin *)letinstall_init()=letself_id,id=Install.createinstall_plugininletgenerate_install,doit_install=stdidinstall_data"Install"(ns_"Run command to install.")(ns_"Run command to clean install step.")(ns_"Run command to distclean install step.")inletgenerate_uninstall,doit_uninstall=stdiduninstall_data"Uninstall"(ns_"Run command to uninstall.")(ns_"Run command to clean uninstall step.")(ns_"Run command to distclean uninstall step.")inInstall.register_actself_id(doit_install,doit_uninstall);register_generator_packageidinstall_datagenerate_install;register_generator_packageiduninstall_datagenerate_uninstall(* Document plugin *)letdoc_init()=letself_id,id=Doc.createdoc_plugininlet_,_,_,generator=add_fields~schema:OASISDocument.schemaidbuild_data""(ns_"Run command to build documentation.")(ns_"Run command to clean build documentation step.")(ns_"Run command to distclean build documentation step.")inletdoitplugin_ctxt_(cs,_)=lett=generatorcs.cs_datainplugin_ctxt,{OASISPlugin.chng_moduls=[CustomData.customsys_ml];chng_main=OASISDataNotation.func_with_arg_ctxtDocRuntime.main("CustomPlugin.Doc.main")todn_of_t;chng_clean=Some(OASISDataNotation.func_with_arg_ctxtDocRuntime.clean("CustomPlugin.Doc.clean")todn_of_t);chng_distclean=Some(OASISDataNotation.func_with_arg_ctxtDocRuntime.distclean("CustomPlugin.Doc.distclean")todn_of_t);}inDoc.register_actself_iddoit;register_generator_packageiddoc_datagenerator(* Test plugin *)lettest_init()=letself_id,id=Test.createtest_plugininlettest_clean=new_field_conditionalOASISTest.schemaid"Clean"~default:None(optcommand_line)(fun()->s_"Run command to clean test step.")test_data(fun_t->t.cmd_clean)inlettest_distclean=new_field_conditionalOASISTest.schemaid"Distclean"~default:None(optcommand_line)(fun()->s_"Run command to distclean test step.")test_data(fun_t->t.cmd_distclean)inletgeneratordata={cmd_main=[OASISExpr.EBooltrue,("false",[])];cmd_clean=test_cleandata;cmd_distclean=test_distcleandata;}inletdoitplugin_ctxt_(cs,test)=lett={(generatorcs.cs_data)withcmd_main=test.test_command}inplugin_ctxt,{OASISPlugin.chng_moduls=[CustomData.customsys_ml];chng_main=OASISDataNotation.func_with_arg_ctxtTestRuntime.main("CustomPlugin.Test.main")todn_of_t;chng_clean=Some(OASISDataNotation.func_with_arg_ctxtTestRuntime.clean("CustomPlugin.Test.clean")todn_of_t);chng_distclean=Some(OASISDataNotation.func_with_arg_ctxtTestRuntime.distclean("CustomPlugin.Test.distclean")todn_of_t);}inTest.register_actself_iddoit;register_generator_packageidtest_datageneratorletinit()=register_helpconf_plugin(help_defaultCustomData.readme_template_mkd);conf_init();build_init();install_init();doc_init();test_init()