123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124(**************************************************************************)(* *)(* Copyright 2012-2019 OCamlPro *)(* Copyright 2012 INRIA *)(* *)(* All rights reserved. This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1, with the special *)(* exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)includeOpamStd.AbstractStringtypevariable=ttypevariable_contents=|Bofbool|Sofstring|Lofstringlistletstring_of_variable_contents=function|Bb->string_of_boolb|Ss->s|Ll->String.concat" "lletstringstr=Sstrletboolb=Bbletinti=string(string_of_inti)letdirnamedir=string(OpamFilename.Dir.to_stringdir)moduleFull=structtypescope=|Global|Self|PackageofOpamPackage.Name.ttypet={scope:scope;variable:variable;}letvariablet=t.variableletscopet=t.scopeletpackage?selft=matcht.scopewith|Packagep->Somep|Self->self|Global->Noneletcreatepackagevariable=letscope=ifOpamPackage.Name.to_stringpackage="_"thenSelfelsePackagepackagein{scope;variable}(* Read the variables overridden through the environment *)letread_from_envv=letvar_str=to_string(variablev)inletundash=OpamStd.String.map(function'-'->'_'|c->c)inletvar_hook=matchpackagevwith|Somen->Printf.sprintf"%s_%s"(undash(OpamPackage.Name.to_stringn))(undashvar_str)|None->undashvar_strintrymatchOpamStd.Env.get("OPAMVAR_"^var_hook)with|"true"|"1"->Some(booltrue)|"false"|"0"->Some(boolfalse)|s->Some(strings)withNot_found->Noneletglobalvariable={scope=Global;variable}letselfvariable={scope=Self;variable}letis_globalvariable=matchvariable.scopewith|Global->true|Self|Package_->falseletof_strings=matchOpamStd.String.rcut_ats':'with|None->global(of_strings)|Some("_",v)->{scope=Self;variable=of_stringv}|Some(p,v)->create(OpamPackage.Name.of_stringp)(of_stringv)letto_stringt=letprefix=matcht.scopewith|Global->""|Self->"_:"|Packagep->OpamPackage.Name.to_stringp^":"inprefix^to_stringt.variableletto_jsonx=`String(to_stringx)letof_json=function|`Strings->(trySome(of_strings)with_->None)|_->NonemoduleO=structtypetmp=ttypet=tmpletcompare=compareletto_string=to_stringletto_json=to_jsonletof_json=of_jsonendmoduleSet=OpamStd.Set.Make(O)moduleMap=OpamStd.Map.Make(O)end