123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051(**************************************************************************)(* *)(* Copyright 2020 OCamlPro & Origin Labs *)(* *)(* 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. *)(* *)(**************************************************************************)openEzcmd.TYPESletcmd_name="install"letaction~args()=ifMisc.vendor_packages()<>[]thenError.raise"Cannot install project if the project has vendors/ packages";let_p=Build.build~args()inletpackages=Misc.list_opam_packages"."in(* (1) uninstall formerly install packages *)List.iter(funpackage->matchOpam.run["uninstall"]["-y";package]with|exceptionError.Error_->()|()->())packages;(* (2) pin packages of this directory as they are *)Opam.run["pin"]["-y";"--no-action";"-k";"path";"."];(* (3) install packages *)letexn=matchOpam.run["install"]("-y"::packages)with|()->None|exceptionexn->Someexnin(* (4) unpin packages to clean the state
List.iter
(fun package -> Opam.run ~error:(ref None) [ "unpin" ] [ "-n"; package ])
packages; *)matchexnwith|None->Printf.eprintf"\nInstallation OK\n%!"|Someexn->raiseexnletcmd=letargs,specs=Build.build_args()in{cmd_name;cmd_action=(fun()->action~args());cmd_args=[]@specs;cmd_man=[];cmd_doc="Build & install the project in the project opam switch"}