123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121(************************************************************************)(* * 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) *)(************************************************************************)modulePath=structtypet=stringletrelative=Filename.concatletto_stringx=xletexistsx=Sys.file_existsxend(* For now just a pointer to coq/lib (for .vo) and rocq-runtime/lib (for plugins) *)typet={core:Path.t;lib:Path.t}(* fatal error *)letfail_msg="cannot guess a path for Rocq libraries; please use -coqlib option \
or ensure you have installed the package containing Rocq's prelude (rocq-core in OPAM) \
If you intend to use Rocq without prelude, the -boot -noinit options must be used."letfails=Format.eprintf"%s@\n%!"fail_msg;exit1(* This code needs to be refactored, for now it is just what used to be in envvars *)lettheories_dir="theories"letplugins_dir="plugins"letprelude=Filename.concattheories_dir"Init/Prelude.vo"letguess_coqlib()=matchUtil.getenv_rocq"LIB"with|Somev->v|None->Util.check_file_else~dir:Coq_config.coqlibsuffix~file:prelude(fun()->ifSys.file_exists(Filename.concatCoq_config.coqlibprelude)thenCoq_config.coqlibelsefail())(* Build layout uses coqlib = coqcorelib *)letguess_coqcoreliblib=ifSys.file_exists(Path.relativelibplugins_dir)thenlibelsePath.relativelib"../rocq-runtime"letfail_liblib=letopenPrintfineprintf"File not found: %s\n"lib;eprintf"The path for Rocq libraries is wrong.\n";eprintf"Rocq prelude is shipped in the rocq-core package.\n";eprintf"Please check the ROCQLIB env variable or the -coqlib option.\n";exit1letfail_coreplugin=letopenPrintfineprintf"File not found: %s\n"plugin;eprintf"The path for Rocq plugins is wrong.\n";eprintf"Rocq plugins are shipped in the rocq-runtime package.\n";eprintf"Please check the ROCQRUNTIMELIB env variable.\n";exit1letvalidate_env({core;lib}asenv)=letlib=Filename.concatlibpreludeinifnot(Sys.file_existslib)thenfail_liblib;letplugin=Filename.concatcoreplugins_dirinifnot(Sys.file_existsplugin)thenfail_coreplugin;env(* Should we fail on double initialization? That seems a way to avoid
mis-use for example when we pass command line arguments *)letinit()=letlib=guess_coqlib()inletcore=matchUtil.getenv_rocq_gen~rocq:"ROCQRUNTIMELIB"~coq:"COQCORELIB"with|Somev->v|None->guess_coqcoreliblibinvalidate_env{core;lib}letenv_ref=refNoneletinit()=match!env_refwith|None->letenv=init()inenv_ref:=Someenv;env|Someenv->envletset_coqliblib=letenv=validate_env{lib;core=guess_coqcoreliblib}inenv_ref:=Someenvletcoqlib{lib;_}=libletcorelib{core;_}=coreletplugins{core;_}=Path.relativecoreplugins_dirletstdlib{lib;_}=Path.relativelibtheories_dirletuser_contrib{lib;_}=Path.relativelib"user-contrib"lettool{core;_}tool=Path.(relative(relativecore"tools")tool)letrevision{core;_}=Path.relativecore"revision"letnative_cmi{core;_}lib=letinstall_path=Path.relativecorelibinifSys.file_existsinstall_paththeninstall_pathelse(* Dune build layout, we need to improve this *)letobj_dir=Format.asprintf".%s.objs"libinFilename.(concat(concat(concatcorelib)obj_dir)"byte")