123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167(**************************************************************************)(* *)(* Copyright 2016-2019 OCamlPro *)(* *)(* 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. *)(* *)(**************************************************************************)openOpamTypesletrepository_url={OpamUrl.transport="https";path="opam.ocaml.org";hash=None;backend=`http;}letdefault_compiler=OpamFormula.ors[OpamFormula.Atom(OpamPackage.Name.of_string"ocaml-system",OpamFormula.Empty);OpamFormula.Atom(OpamPackage.Name.of_string"ocaml-base-compiler",OpamFormula.Empty);]letdefault_invariant=OpamFormula.Atom(OpamPackage.Name.of_string"ocaml",OpamFormula.Atom(`Geq,OpamPackage.Version.of_string"4.05.0"))leteval_variables=[OpamVariable.of_string"sys-ocaml-version",["ocamlc";"-vnum"],"OCaml version present on your system independently of opam, if any";OpamVariable.of_string"sys-ocaml-arch",["sh";"-c";"ocamlc -config 2>/dev/null | tr -d '\\r' | grep '^architecture: ' | sed -e 's/.*: //' -e 's/i386/i686/' -e 's/amd64/x86_64/'"],"Target architecture of the OCaml compiler present on your system";OpamVariable.of_string"sys-ocaml-cc",["sh";"-c";"ocamlc -config 2>/dev/null | tr -d '\\r' | grep '^ccomp_type: ' | sed -e 's/.*: //'"],"Host C Compiler type of the OCaml compiler present on your system";OpamVariable.of_string"sys-ocaml-libc",["sh";"-c";"ocamlc -config 2>/dev/null | tr -d '\\r' | grep '^os_type: ' | sed -e 's/.*: //' -e 's/Win32/msvc/' -e '/^msvc$/!s/.*/libc/'"],"Host C Runtime Library type of the OCaml compiler present on your system";]letos_filteros=FOp(FIdent([],OpamVariable.of_string"os",None),`Eq,FStringos)letlinux_filter=os_filter"linux"letmacos_filter=os_filter"macos"letopenbsd_filter=os_filter"openbsd"letfreebsd_filter=os_filter"freebsd"letnot_open_free_bsd_filter=FNot(FOr(openbsd_filter,freebsd_filter))letwin32_filter=os_filter"win32"letsandbox_filter=FOr(linux_filter,macos_filter)letgpatch_filter=FOr(openbsd_filter,freebsd_filter)letpatch_filter=FNotgpatch_filterletgtar_filter=openbsd_filterlettar_filter=FNotgtar_filterletgetconf_filter=FNot(FOr(win32_filter,freebsd_filter))letsandbox_wrappers=letcmdt=[CString"%{hooks}%/sandbox.sh",None;CStringt,None;]in[`build[cmd"build",Somesandbox_filter];`install[cmd"install",Somesandbox_filter];`remove[cmd"remove",Somesandbox_filter];]letwrappers~sandboxing()=letw=OpamFile.Wrappers.emptyinifsandboxingthenList.fold_leftOpamFile.Wrappers.(funw->function|`buildwrap_build->{wwithwrap_build}|`installwrap_install->{wwithwrap_install}|`removewrap_remove->{wwithwrap_remove})OpamFile.Wrappers.emptysandbox_wrapperselsewletbwrap_cmd="bwrap"letbwrap_filter=linux_filterletbwrap_string()=Printf.sprintf"Sandboxing tool %s was not found. You should install 'bubblewrap'. \
See https://opam.ocaml.org/doc/FAQ.html#Why-does-opam-require-bwrap."bwrap_cmdletreq_dl_tools()=letmsg=Some"A download tool is required, check env variables OPAMCURL or OPAMFETCH"inletdefault=[["curl";"wget"],msg,Somenot_open_free_bsd_filter;["fetch"],msg,Somefreebsd_filter;["ftp"],msg,Someopenbsd_filter]inletopenOpamStd.Option.Opinletcmd=(OpamRepositoryConfig.E.fetch()>>=funs->matchOpamStd.String.splits' 'with|c::_->Somec|_->None)>>+fun()->OpamRepositoryConfig.E.curl()inmatchcmdwith|Somecmd->[[cmd],Some"Custom download tool, check OPAMCURL or OPAMFETCH",None]|None->defaultletdl_tool()=letopenOpamStd.Option.Opin(OpamRepositoryConfig.E.fetch()>>+fun()->OpamRepositoryConfig.E.curl())>>|funcmd->[(CStringcmd),None]letrecommended_tools()=letmake=OpamStateConfig.(Lazy.force!r.makecmd)in[[make],None,None;["cc"],None,None;]letrequired_tools~sandboxing()=req_dl_tools()@[["diff"],None,None;["patch"],None,Somepatch_filter;["gpatch"],None,Somegpatch_filter;["tar"],None,Sometar_filter;["gtar"],None,Somegtar_filter;["unzip"],None,None;["getconf"],None,Somegetconf_filter;]@ifsandboxingthen[[bwrap_cmd],Some(bwrap_string()),Somebwrap_filter;["sandbox-exec"],None,Somemacos_filter;]else[]letinit_scripts()=[("sandbox.sh",OpamScript.bwrap),Somebwrap_filter;("sandbox.sh",OpamScript.sandbox_exec),Somemacos_filter;]moduleI=OpamFile.InitConfiglet(@|)gf=OpamStd.Op.(g@*f)()letinit_config?(sandboxing=true)()=I.empty|>I.with_repositories[OpamRepositoryName.of_string"default",(repository_url,None)]|>I.with_default_compilerdefault_compiler|>I.with_default_invariantdefault_invariant|>I.with_eval_variableseval_variables|>I.with_wrappers@|wrappers~sandboxing|>I.with_recommended_tools@|recommended_tools|>I.with_required_tools@|required_tools~sandboxing|>I.with_init_scripts@|init_scripts|>I.with_dl_tool@|dl_tool