123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160(**************************************************************************)(* *)(* Copyright 2017 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. *)(* *)(**************************************************************************)openOpamCompatopenOpamStd.Option.Opletcommand_outputc=matchList.filter(funs->String.trims<>"")(OpamSystem.read_command_outputc)with|[""]->None|[s]->Somes|_->None|exception(OpamSystem.Process_error_|OpamSystem.Command_not_found_)->Noneletnorms=ifs=""thenNoneelseSome(String.lowercase_asciis)letnormalise_archraw=matchString.lowercase_asciirawwith|"x86"|"i386"|"i586"|"i686"->"x86_32"|"x86_64"|"amd64"->"x86_64"|"powerpc"|"ppc"|"ppcle"->"ppc32"|"ppc64"|"ppc64le"->"ppc64"|"aarch64_be"|"aarch64"|"armv8b"|"armv8l"->"arm64"|awhenList.exists(funprefix->OpamStd.String.starts_with~prefixa)["armv5";"armv6";"earmv6";"armv7";"earmv7"]->"arm32"|s->sletarch_lazy=lazy(letraw=matchSys.os_typewith|"Unix"|"Cygwin"->OpamStd.Sys.uname"-m"|"Win32"->ifSys.word_size=32&¬(OpamStubs.isWoW64())thenSome"i686"elseSome"x86_64"|_->Noneinmatchrawwith|None|Some""->None|Somea->Some(normalise_archa))letarch()=Lazy.forcearch_lazyletnormalise_osraw=matchString.lowercase_asciirawwith|"darwin"|"osx"->"macos"|s->sletos_lazy=lazy(letraw=matchSys.os_typewith|"Unix"->OpamStd.Sys.uname"-s"|s->normsinmatchrawwith|None|Some""->None|Somes->Some(normalise_oss))letos()=Lazy.forceos_lazyletos_release_field=letos_release_file=lazy(List.findSys.file_exists["/etc/os-release";"/usr/lib/os-release"]|>OpamProcess.read_lines|>OpamStd.List.filter_map(funs->tryScanf.sscanfs"%s@= %s"(funxv->letcontents=tryScanf.sscanfv"\"%s@\""(funs->s)withScanf.Scan_failure_|End_of_file->vinSome(x,contents))withScanf.Scan_failure_|End_of_file->None))infunf->trySome(List.assocf(Lazy.forceos_release_file))withNot_found->Noneletis_android,android_release=letprop=lazy(command_output["getprop";"ro.build.version.release"])in(fun()->Lazy.forceprop<>None),(fun()->Lazy.forceprop)letos_distribution_lazy=lazy(matchos()with|Some"macos"asmacos->ifOpamSystem.resolve_command"brew"<>NonethenSome"homebrew"elseifOpamSystem.resolve_command"port"<>NonethenSome"macports"elsemacos|Some"linux"aslinux->(ifis_android()thenSome"android"elseos_release_field"ID">>=norm>>+fun()->command_output["lsb_release";"-i";"-s"]>>=norm>>+fun()->tryList.findSys.file_exists["/etc/redhat-release";"/etc/centos-release";"/etc/gentoo-release";"/etc/issue"]|>funs->Scanf.sscanfs" %s "normwithNot_found->linux)|os->os)letos_distribution()=Lazy.forceos_distribution_lazyletos_version_lazy=lazy(matchos()with|Some"linux"->android_release()>>=norm>>+fun()->command_output["lsb_release";"-s";"-r"]>>=norm>>+fun()->os_release_field"VERSION_ID">>=norm|Some"macos"->command_output["sw_vers";"-productVersion"]>>=norm|Some"win32"->let(major,minor,build,_)=OpamStubs.getWindowsVersion()inOpamStd.Option.some@@Printf.sprintf"%d.%d.%d"majorminorbuild|Some"cygwin"->(trycommand_output["cmd";"/C";"ver"]>>=funs->Scanf.sscanfs"%_s@[ Version %s@]"normwithScanf.Scan_failure_|End_of_file->None)|Some"freebsd"->OpamStd.Sys.uname"-U">>=norm|_->OpamStd.Sys.uname"-r">>=norm)letos_version()=Lazy.forceos_version_lazyletos_family_lazy=lazy(matchos()with|Some"linux"->(os_release_field"ID_LIKE">>=funs->Scanf.sscanfs" %s"norm(* first word *))>>+os_distribution|Some("freebsd"|"openbsd"|"netbsd"|"dragonfly")->Some"bsd"|Some("win32"|"cygwin")->Some"windows"|_->os_distribution())letos_family()=Lazy.forceos_family_lazyletvariables=List.map(fun(n,v)->OpamVariable.of_stringn,lazy(Lazy.forcev>>|funv->OpamTypes.Sv))["arch",arch_lazy;"os",os_lazy;"os-distribution",os_distribution_lazy;"os-version",os_version_lazy;"os-family",os_family_lazy;]