123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132(*
* 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.
*)openAstringtypet={config_file:Fpath.t;name:string;project_name:string;output:stringoption;keys:Key.Set.t;runtime_args:Runtime_arg.Set.t;context:Context.t;packages:Package.tString.Map.t;opam:extra_repo:(string*string)list->install:Install.t->opam_name:string->Opam.t;}letnamet=t.nameletproject_namet=t.project_nameletconfig_filet=t.config_fileletmaint=letmain=matcht.outputwithNone->"main"|Somef->finFpath.v(main^".ml")letgettk=Key.gett.contextkletopamt=t.opamletoutputt=t.outputletwith_outputtoutput={twithoutput=Someoutput}letlibrariesps=letlibsp=ifPackage.build_dependencypthenString.Set.emptyelseString.Set.of_list(Package.librariesp)inString.Set.elements(List.fold_leftString.Set.unionString.Set.empty(List.maplibsps))letpackagest=List.mapsnd(String.Map.bindingst.packages)letlibrariest=libraries(packagest)letpinspackages=List.fold_left(funaccp->matchPackage.pinpwithNone->acc|Someu->u::acc)[]packagesletkeyst=Key.Set.elementst.keysletruntime_argst=Runtime_arg.Set.elementst.runtime_argsletcontextt=t.contextletv?(config_file=Fpath.v"config.ml")~packages~keys~runtime_args~context?configure_cmd?pre_build_cmd?lock_location~build_cmd~src~project_namename=letkeys=Key.Set.of_listkeysinletruntime_args=Runtime_arg.Set.of_listruntime_argsinletopam~extra_repo~install~opam_name=Opam.v~depends:packages~install~pins:(pinspackages)~extra_repo?configure:configure_cmd?pre_build:pre_build_cmd?lock_location~build:build_cmd~src~opam_namenameinletpackages=List.fold_left(funmp->letn=Package.namepinmatchString.Map.findnmwith|None->String.Map.addnpm|Somep'->(matchPackage.mergepp'with|Somep->String.Map.addnpm|None->m))String.Map.emptypackagesin{config_file;name;project_name;keys;runtime_args;packages;context;output=None;opam;}letpp_packages?(surround="")?sepppft=letpkgs=packagestinFmt.pfppf"%a"(Fmt.iter?sepList.iter(Package.pp~surround))pkgsletppverboseppf({name;keys;context;output;_}ast)=letshow?(newline=true)name=Fmt.pfppf("@[<2>%-10s@ %a@]"^^ifnewlinethen"@,"else"")nameinletlist=Fmt.iter~sep:(Fmt.any",@ ")List.iterFmt.stringinshow"Name"Fmt.stringname;show"Keys"~newline:(verbose||output<>None)(Key.ppscontext)keys;let()=matchoutputwith|None->()|Someo->show"Output"~newline:verboseFmt.(string)oinifverbosethenshow"Libraries "list(librariest);ifverbosethenshow"Packages"~newline:false(pp_packages?surround:None~sep:(Fmt.any",@ "))tlett=leti=v~config_file:(Fpath.v"config.ml")~packages:[]~keys:[]~runtime_args:[]~build_cmd:(fun_->"dummy")~context:Context.empty~src:`None"dummy"~project_name:"dummy"inType.vi