123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383(******************************************************************************)(* 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 *)(******************************************************************************)(** META generator
@author Sylvain Le Gall
*)openOASISGettextopenOASISTypesopenOASISValuesopenOASISFindlibopenOASISFileTemplateopenOASISPluginopenOASISSchemaopenFormattypemeta_type=|METALibrary|METASyntaxtypet={enable:bool;description:stringoption;meta_type:meta_type;requires:(stringlist)option;extra_lines:stringlist;}letplugin=`Extra,"META",SomeOASISConf.version_shortletself_id,all_id=Extra.createpluginletfeature_extra_lines=OASISFeatures.create"extra_lines"~plugin(OASISFeatures.since_version"0.3")(fun()->s_"Allow to add extra lines to the generated META.")letpivot_data=data_new_propertypluginletgenerator=letnew_fieldnm=new_fieldOASISLibrary.schemaall_idnminletenable=new_field"Enable"~default:trueboolean(fun()->s_"Enable META generation")pivot_data(fun_t->t.enable)inletdescription=new_field"Description"~default:None(optstring_not_empty)(fun()->s_"META package description")pivot_data(fun_t->t.description)inletmeta_type=new_field"Type"~default:METALibrary(choices(fun()->s_"META type")["library",METALibrary;"syntax",METASyntax;])(fun()->s_"Type of META package, set default predicates for archive")pivot_data(fun_t->t.meta_type)inletextra_lines=new_field"ExtraLines"~default:[]~feature:feature_extra_lines(newline_separatedstring_not_empty)(fun()->s_"Extra lines to add to the META")pivot_data(fun_t->t.extra_lines)inletrequires=new_field"Requires"~default:None(opt(comma_separatedstring))(fun()->s_"Requires field for META package")pivot_data(fun_t->t.requires)infundata->{enable=enabledata;description=descriptiondata;meta_type=meta_typedata;requires=requiresdata;extra_lines=extra_linesdata;}letpp_print_metapkgroot_tfindlib_name_of_library_namefmtgrp=letmayf=function|Somex->fx|None->()inletreplace_charss=OASISString.replace_chars(func->ifOASISString.is_whitespacecthen' 'elsec)sinletpp_print_fieldfmt(var,preds,vl)=fprintffmt"@,@[%s(%s) =@ %S@]"var(String.concat", "preds)(replace_charsvl)inletpp_print_sfieldfmt(var,vl)=fprintffmt"@,@[%s =@ %S@]"var(replace_charsvl)inletdefault_synopsis=matchroot_t.descriptionwith|Sometxt->txt|None->pkg.synopsisinletrecpp_print_libraryfmt(cs,bs,contents,children)=letname=cs.cs_nameinletarchive_byte,archive_byte_plugin,archive_native,archive_native_plugin=matchcontentswith|`Library_->name^".cma",Some(name^".cma"),name^".cmxa",Some(name^".cmxs")|`Object{obj_modules=[m]}->letdir=OASISHostPath.of_unixbs.bs_pathinletexistsfnext=letpath=Filename.concatdir(fn^ext)inOASISFileUtil.file_exists_casepathinletm=List.find(funm->existsm".mli"||existsm".ml")[OASISString.uncapitalize_asciim;OASISString.capitalize_asciim]inm^".cmo",None,m^".cmx",None|`Object_->name^".cmo",None,name^".cmx",Noneinlett=generatorcs.cs_datainpp_print_sfieldfmt("version",(OASISVersion.string_of_versionpkg.version));beginlettxt=matcht.descriptionwith|Sometxt->txt|None->default_synopsisinpp_print_sfieldfmt("description",txt)end;beginletdirectory=matchcontentswith|`Libraryl->l.lib_findlib_directory|`Objecto->o.obj_findlib_directoryinmatchdirectorywith|Somedir->pp_print_sfieldfmt("directory",dir)|None->()end;beginletrequires=matcht.requireswith|Somelst->lst|None->List.map(function|InternalLibrarynm->findlib_name_of_library_namenm|FindlibPackage(fndlb_nm,_)->fndlb_nm)bs.bs_build_dependsinifrequires<>[]thenpp_print_sfieldfmt("requires",String.concat" "requires)end;beginmatcht.meta_typewith|METALibrary->pp_print_fieldfmt("archive",["byte"],archive_byte);may(funx->pp_print_fieldfmt("archive",["byte";"plugin"],x))archive_byte_plugin;beginmatchbs.bs_compiled_objectwith|Best|Native->pp_print_fieldfmt("archive",["native"],archive_native);may(funx->pp_print_fieldfmt("archive",["native";"plugin"],x))archive_native_plugin;|Byte->()end|METASyntax->pp_print_fieldfmt("archive",["syntax";"preprocessor"],archive_byte);pp_print_fieldfmt("archive",["syntax";"toploop"],archive_byte);beginmatchbs.bs_compiled_objectwith|Best|Native->pp_print_fieldfmt("archive",["syntax";"preprocessor";"native"],archive_native);may(funx->pp_print_fieldfmt("archive",["syntax";"preprocessor";"native";"plugin"],x))archive_native_plugin;|Byte->()endend;List.iter(fprintffmt"@,%s")t.extra_lines;pp_print_sfieldfmt("exists_if",ifbs.bs_compiled_object=Nativethenarchive_nativeelsearchive_byte);FormatExt.pp_print_listpp_print_group"@,"fmtchildrenandpp_print_groupfmt=function|Container(fndlb_nm,children)->fprintffmt"@,@[<v1>@[package %S (@]%a%a@]@,)"fndlb_nmpp_print_sfield("description","Virtual container")(FormatExt.pp_print_listpp_print_group"")children|Package(fndlb_nm,lib_cs,lib_bs,lib,_,children)->lett=generatorlib_cs.cs_datainift.enablethenfprintffmt"@,@[<v1>@[package %S (@]%a@]@,)"fndlb_nmpp_print_library(lib_cs,lib_bs,lib,children)inassert(root_t.enable);pp_open_vboxfmt0;fprintffmt"# OASIS_START";beginmatchgrpwith|Container(_,children)->FormatExt.pp_print_listpp_print_group""fmtchildren|Package(_,lib_cs,lib_bs,lib,_,children)->pp_print_libraryfmt(lib_cs,lib_bs,lib,children)end;fprintffmt"@,# OASIS_STOP@,";pp_close_boxfmt();pp_print_flushfmt()letmainctxtpkg=letgroup_libs,findlib_name_of_library_name,_=findlib_mappingpkginletmeta_created=Hashtbl.create3inList.fold_left(functxtgrp->letroot_cs,root_bs,_=root_of_groupgrpinletroot_t=generatorroot_cs.cs_datainifroot_t.enablethenbeginletmeta_fn=OASISUnixPath.concatroot_bs.bs_path"META"inletbuff=Buffer.create13inifHashtbl.memmeta_createdmeta_fnthenOASISUtils.failwithf(f_"The file '%s' generated for the library '%s' is \
already used for the library '%s'. You can make \
one a child of the other to solve this \
(field `FindlibParent:`).")meta_fnroot_cs.cs_name(Hashtbl.findmeta_createdmeta_fn);Hashtbl.addmeta_createdmeta_fnroot_cs.cs_name;pp_print_metapkgroot_tfindlib_name_of_library_name(Format.formatter_of_bufferbuff)grp;OASISPlugin.add_file(template_of_string_list~ctxt:ctxt.OASISPlugin.ctxt~template:truemeta_fncomment_meta(OASISString.split_newline~do_trim:false(Buffer.contentsbuff)))ctxtendelsectxt)ctxtgroup_libsletinit()=register_helpplugin{(help_defaultMETAData.readme_template_mkd)withhelp_order=40};Extra.register_actself_idmain;register_generator_section`Libraryall_idpivot_datagenerator