123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104(************************************************************************)(* * The Rocq Prover / The Rocq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openFile_utilletcoqc_predicates=["native"]moduleFl_internals=struct(** Functions not exported by findlib (XXX there is a copy in mltop, we should share them) *)(* Fl_split.in_words is not exported *)letfl_split_in_wordss=(* splits s in words separated by commas and/or whitespace *)letl=String.lengthsinletrecsplitij=ifj<lthenmatchs.[j]with|(' '|'\t'|'\n'|'\r'|',')->ifi<jthen(String.subsi(j-i))::(split(j+1)(j+1))elsesplit(j+1)(j+1)|_->spliti(j+1)elseifi<jthen[String.subsi(j-i)]else[]insplit00(* simulate what fl_dynload does *)letfl_find_pluginslib=letbase=Findlib.package_directorylibinletarchive=tryFindlib.package_propertycoqc_predicateslib"plugin"withNot_found->tryfst(Findlib.package_property_2("plugin"::coqc_predicates)lib"archive")withNot_found->""infl_split_in_wordsarchive|>List.map(Findlib.resolve_path~base)(* first string is the v file which triggered the error, rest is Fl_package_base.No_such_package *)exceptionNo_such_packageofstring*string*stringlet()=CErrors.register_handlerPp.(function|No_such_package(vfile,p,msg)->letpaths=Findlib.search_path()inSome(hov0(str"In file"++spc()++strvfile++spc()++str"findlib error: "++strp++str" not found in:"++cut()++v0(prlist_with_sepcutstrpaths)++fnl()++strmsg))|_->None)endletrelative_if_dunepath=(* relativize the path if inside the current dune workspace
if we relativize paths outside the dune workspace it fails so make sure to avoid it *)matchSys.getenv_opt"DUNE_SOURCEROOT"with|SomedunewhenCString.is_prefixdunepath->normalize_path(to_relative_pathpath)|_->normalize_pathpathletfindlib_resolve~package=letmeta_file=Findlib.package_meta_filepackageinletcmxss=Fl_internals.fl_find_pluginspackageinletmeta_file=relative_if_dunemeta_fileinletcmxs_file=List.maprelative_if_dunecmxssin(meta_file,cmxs_file)letstatic_libs=CString.Set.of_listStatic_toplevel_libs.static_toplevel_libsletfindlib_deep_resolve~package=letpackages=Findlib.package_deep_ancestorscoqc_predicates[package]inletpackages=CList.filter(funpackage->not(CString.Set.mempackagestatic_libs))packagesinList.fold_left(fun(metas,cmxss)package->letmeta,cmxss'=findlib_resolve~packageinmeta::metas,cmxss'@cmxss)([],[])packagesletfindlib_deep_resolve~file~package=tryfindlib_deep_resolve~packagewithFl_package_base.No_such_package(p,m)->raise(Fl_internals.No_such_package(file,p,m))moduleInternal=structletget_worker_path()=lettop="rocqworker"inletdir=Findlib.package_directory"rocq-runtime"inletexe=ifSys.(os_type="Win32"||os_type="Cygwin")then".exe"else""inletfile=Filename.concatdir(top^exe)inmatchSys.getenv_opt"DUNE_SOURCEROOT"with|SomedunewhenCString.is_prefixdunefile->normalize_path(to_relative_pathfile)|_->normalize_pathfileend