12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(************************************************************************)(* * 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) *)(************************************************************************)letparse_env_linel=tryScanf.sscanfl"%[^=]=%S"(funnamevalue->Some(name,value))withScanf.Scan_failure_|End_of_file->Noneletwith_icfilef=letic=open_infileintryletrc=ficinclose_inic;rcwithe->close_inic;raiseeletgetenv_from_filename=letbase=Filename.dirnameSys.executable_nameintrywith_ic(base^"/coq_environment.txt")(funic->letrecfind()=letl=input_lineicinmatchparse_env_linelwith|Some(n,v)whenn=name->Somev|_->find()infind())with|Sys_errors->None|End_of_file->Noneletgetenv_optname=matchSys.getenv_optnamewith|Some_asv->v|None->getenv_from_filenameletwarn_deprecated_coq_var=ref(fun~rocq~coq->Printf.eprintf"Deprecated environment variable %s, use %s instead.\n%!"coqrocq)letset_warn_deprecated_coq_varf=warn_deprecated_coq_var:=fletwarn_deprecated_coq_var~rocq~coq=!warn_deprecated_coq_var~rocq~coqletgetenv_rocq_gen~rocq~coq=matchgetenv_optrocqwith|Some_asv->v|None->matchgetenv_optcoqwith|Some_asv->warn_deprecated_coq_var~rocq~coq;v|None->Noneletgetenv_rocqname=getenv_rocq_gen~rocq:("ROCQ"^name)~coq:("COQ"^name)(** Add a local installation suffix (unless the suffix is itself
absolute in which case the prefix does not matter) *)letuse_suffixprefixsuffix=ifString.lengthsuffix>0&&suffix.[0]='/'thensuffixelseFilename.concatprefixsuffixletcanonical_path_namep=letcurrent=Sys.getcwd()intrySys.chdirp;letp'=Sys.getcwd()inSys.chdircurrent;p'withSys_error_->(* We give up to find a canonical name and just simplify it... *)Filename.concatcurrentpletcoqbin=canonical_path_name(Filename.dirnameSys.executable_name)(** The following only makes sense when executables are running from
source tree (e.g. during build or in local mode). *)letcoqroot=Filename.dirnamecoqbin(** [check_file_else ~dir ~file oth] checks if [file] exists in
the installation directory [dir] given relatively to [coqroot],
which maybe has been relocated.
If the check fails, then [oth ()] is evaluated.
Using file system equality seems well enough for this heuristic *)letcheck_file_else~dir~fileoth=letpath=use_suffixcoqrootdirinifSys.file_exists(Filename.concatpathfile)thenpathelseoth()