123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127openDune_site_privateletpath_sep=path_sepmoduleLocation=structtypet=stringendletdirs:(string*Dune_section.t,string)Hashtbl.t=Hashtbl.create10(* multi-bindings first is the one with least priority *)let()=matchSys.getenv_optdune_dir_locations_env_varwith|None->()|Somes->(matchdecode_dune_dir_locationsswith|None->invalid_arg(Printf.sprintf"Invalid value %s=%S"dune_dir_locations_env_vars)|Someentries->List.iter(fun{package;section;dir}->Hashtbl.adddirs(package,section)dir)entries);;(* Parse the replacement format described in [artifact_substitution.ml]. *)letevals=letlen=String.lengthsinifs.[0]='='then(letcolon_pos=String.index_froms1':'inletvlen=int_of_string(String.subs1(colon_pos-1))in(* This [min] is because the value might have been truncated if it was too
large *)letvlen=minvlen(len-colon_pos-1)inSome(String.subs(colon_pos+1)vlen))elseNone[@@inlinenever];;letget_dir~package~section=Hashtbl.find_alldirs(package,section)moduleHardcoded_ocaml_path=structtypet=|None|Relocatable|Hardcodedofstringlist|Findlib_configofstringlett=lazy(matchevalDune_site_data.hardcoded_ocamlpathwith|None->None|Some"relocatable"->Relocatable|Somes->letl=String.split_on_char'\000'sin(matchlwith|"hardcoded"::l->Hardcodedl|["findlibconfig";p]->Findlib_configp|_->invalid_arg"dune error: hardcoded_ocamlpath parsing error"));;endletrelocatable=lazy(matchLazy.forceHardcoded_ocaml_path.twith|Relocatable->true|_->false);;letprefix=lazy(letpath=Sys.executable_nameinletbin=Filename.dirnamepathinletprefix=Filename.dirnamebininprefix);;letrelocate_if_neededpath=ifLazy.forcerelocatablethenFilename.concat(Lazy.forceprefix)pathelsepath;;letsite~package~section~suffix~encoded=letdirs=get_dir~package~sectioninletdirs=matchevalencodedwith|None->dirs|Somed->relocate_if_neededd::dirsinList.rev_map(fundir->Filename.concatdirsuffix)dirs[@@inlinenever];;letsourcerootlocal=matchevallocalwith|Some""->None|Some_asx->x|None->(* None if the binary is executed from _build but not by dune, which should
not happen *)Sys.getenv_optdune_sourceroot_env_var;;letocamlpath=lazy(letenv=matchSys.getenv_opt"OCAMLPATH"with|None->[]|Somex->String.split_on_charpath_sepxinletstatic=matchLazy.forceHardcoded_ocaml_path.twith|Hardcoded_ocaml_path.None->String.split_on_charpath_sep(Sys.getenvdune_ocaml_hardcoded_env_var)|Hardcoded_ocaml_path.Relocatable->[Filename.concat(Lazy.forceprefix)"lib"]|Hardcoded_ocaml_path.Hardcodedl->l|Hardcoded_ocaml_path.Findlib_config_->assertfalseinenv@static);;letstdlib=lazy(matchevalDune_site_data.stdlib_dirwith|None->Sys.getenvdune_ocaml_stdlib_env_var|Somes->s);;