Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file opam.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256(*
* Copyright (c) 2013-2020 Thomas Gazagnaire <thomas@gazagnaire.org>
* Copyright (c) 2013-2020 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2015-2020 Gabriel Radanne <drupyog@zoho.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openAction.Syntaxletfind_git()=letis_gitp=Action.is_dirFpath.(p/".git")inletapp_optpd=matchpwithNone->d|Somep->Fpath.(d//p)inletrecfindppath=ifFpath.is_rootpthenAction.okNoneelselet*has_git=is_gitpinifhas_gitthenAction.ok(Somepath)elsefind(Fpath.parentp)(Some(app_optpath(Fpath.basep)))inlet*cwd=Action.pwd()in(* this is invoked from within the mirage subdirectory *)let*cwd=find(Fpath.parentcwd)Noneinmatchcwdwith|None->Action.okNone|Somesubdir->letgit_branch=Bos.Cmd.(v"git"%"rev-parse"%"--abbrev-ref"%"HEAD")inlet*branch=Action.(run_cmd_out~err:`Nullgit_branch)inletgit_remote=Bos.Cmd.(v"git"%"remote"%"get-url"%"origin")inlet+git_url=Action.(run_cmd_out~err:`Nullgit_remote)inSome(subdir,branch,git_url)moduleEndpoint=structtypet={scheme:[`SSHofstring|`Git|`HTTP|`HTTPS|`Schemeofstring];port:intoption;path:string;hostname:string;}letof_stringstr=letopenRresultinletparse_sshstr=letlen=String.lengthstrinEmile.of_string_raw~off:0~lenstr|>R.reword_error(R.msgf"%a"Emile.pp_error)>>=fun(consumed,m)->matchAstring.String.cut~sep:":"(String.substrconsumed(len-consumed))with|Some("",path)->letlocal=List.map(function`Atomx->x|`Stringx->Fmt.str"%S"x)m.Emile.localinletuser=String.concat"."localinlethostname=matchfstm.Emile.domainwith|`Domainvs->String.concat"."vs|`Literalv->v|`Addr(Emile.IPv4v)->Ipaddr.V4.to_stringv|`Addr(Emile.IPv6v)->Ipaddr.V6.to_stringv|`Addr(Emile.Ext(k,v))->Fmt.str"%s:%s"kvinR.ok{scheme=`SSHuser;path;port=None;hostname}|_->R.error_msg"Invalid SSH pattern"inletparse_uristr=leturi=Uri.of_stringstrinletpath=Uri.pathuriinmatch(Uri.schemeuri,Uri.hosturi,Uri.porturi)with|Some"git",Somehostname,port->R.ok{scheme=`Git;path;port;hostname}|Some"http",Somehostname,port->R.ok{scheme=`HTTP;path;port;hostname}|Some"https",Somehostname,port->R.ok{scheme=`HTTPS;path;port;hostname}|Somescheme,Somehostname,port->R.ok{scheme=`Schemescheme;path;port;hostname}|_->R.error_msgf"Invalid uri: %a"Uri.ppuriinmatch(parse_sshstr,parse_uristr)with|Okv,_->Okv|_,Okv->Okv|Error_,Error_->R.error_msgf"Invalid endpoint: %s"strendletguess_src()=letgit_info=matchAction.run@@find_git()with|Error_|OkNone->None|Ok(Some(subdir,branch,git_url))->Some(subdir,branch,git_url)inmatchgit_infowith|None->(None,None)|Some(subdir,branch,origin)->(* TODO is there a library for git urls anywhere? *)letpublic=matchEndpoint.of_stringoriginwith|Ok{Endpoint.scheme=`Schemescheme;port=None;path;hostname;_}->Fmt.str"%s://%s/%s"schemehostnamepath|Ok{Endpoint.scheme=`Schemescheme;port=Someport;path;hostname;_;}->Fmt.str"%s://%s:%d/%s"schemehostnameportpath|Ok{Endpoint.port=None;path;hostname;_}->Fmt.str"git+https://%s/%s"hostnamepath|Ok{Endpoint.port=Someport;path;hostname;_}->Fmt.str"git+https://%s:%d/%s"hostnameportpath|_->"git+https://invalid/endpoint"in(subdir,Some(Fmt.str"%s#%s"publicbranch))typet={name:string;depends:Package.tlist;configure:stringoption;pre_build:(Fpath.toption->string)option;lock_location:(Fpath.toption->string->string)option;build:(Fpath.toption->string)option;install:Install.t;extra_repo:(string*string)list;pins:(string*string)list;src:stringoption;subdir:Fpath.toption;opam_name:string;}letv?configure?pre_build?lock_location?build?(install=Install.empty)?(extra_repo=[])?(depends=[])?(pins=[])?subdir~src~opam_namename=letsubdir,src=matchsrcwith|`Auto->letsubdir',src=guess_src()in((matchsubdirwithNone->subdir'|Some_ass->s),src)|`None->(subdir,None)|`Somed->(subdir,Somed)in{name;depends;configure;pre_build;lock_location;build;install;extra_repo;pins;src;subdir;opam_name;}letpp_packagesppfpackages=Fmt.pfppf"\n %a\n"Fmt.(list~sep:(any"\n ")(Package.pp~surround:"\""))packagesletpp_pinsppf=function|[]->()|pins->letpp_pinppf(package,url)=Fmt.pfppf"[\"%s\" %S]"packageurlinFmt.pfppf"@.pin-depends: [ @[<hv>%a@]@ ]@."Fmt.(list~sep:(any"@ ")pp_pin)pinsletpp_srcppf=function|None->()|Somesrc->Fmt.pfppf{|@.url { src: %S }|}srcletpp_switch_packageppfs=Fmt.pfppf"%S"sletppppft=letpp_cmd=function|None->""|Somecmd->Fmt.str{|"sh" "-exc" "%a%s"|}Fmt.(option~none:(any"")(any"cd "++Fpath.pp++any" && "))t.subdircmdinletpp_with_subppf=function|None->()|Somef->Fmt.stringppf(ft.subdir)inletpp_repo=Fmt.(list~sep:(any"\n")(brackets(pair~sep:(any" ")(quotestring)(quotestring))))inletswitch_packages=List.filter_map(funp->matchPackage.scopepwith|`Switch->Some(Package.namep)|`Monorepo->None)t.dependsinFmt.pfppf{|opam-version: "2.0"
maintainer: "dummy"
authors: "dummy"
homepage: "dummy"
bug-reports: "dummy"
dev-repo: "git://dummy"
synopsis: "Unikernel %s - switch dependencies"
description: """
It assumes that local dependencies are already
fetched.
"""
build: [%a]
install: [%a]
depends: [%a]
x-mirage-opam-lock-location: %S
x-mirage-configure: [%s]
x-mirage-pre-build: [%a]
x-mirage-extra-repo: [%a]
x-opam-monorepo-opam-provided: [%a]
%a%a|}t.namepp_with_subt.build(Install.pp_opam?subdir:t.subdir())t.installpp_packagest.depends(Option.fold~none:""~some:(funl->lt.subdirt.opam_name)t.lock_location)(pp_cmdt.configure)pp_with_subt.pre_buildpp_repot.extra_repo(Fmt.list~sep:(Fmt.any" ")pp_switch_package)switch_packagespp_srct.srcpp_pinst.pins