nitpm: keep going if a package is already installed
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 3 Mar 2018 13:27:03 +0000 (08:27 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 28 Mar 2018 13:14:04 +0000 (09:14 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/picnit.nit

index 365bcb8..8875896 100644 (file)
@@ -58,6 +58,9 @@ class CommandInstall
        redef fun usage do return "picnit install [package0[=version] [package1 ...]]"
        redef fun description do return "Install packages by name, Git repository address or from the local package.ini"
 
+       # Packages installed in this run (identified by the full path)
+       private var installed = new Array[String]
+
        redef fun apply(args)
        do
                if args.not_empty then
@@ -160,28 +163,36 @@ class CommandInstall
 
                var target_dir = picnit_lib_dir / name
                if version != null then target_dir += "=" + version
-               if target_dir.file_exists then
-                       print_error "Already installed"
-                       exit 1
+               if installed.has(target_dir) then
+                       # Ignore packages installed in this run
+                       return
                end
+               installed.add target_dir
 
-               var cmd_branch = ""
-               if version != null then cmd_branch = "--branch '{version}'"
+               if target_dir.file_exists then
+                       # Warn about packages previously installed,
+                       # install dependencies anyway in case of a previous error.
+                       print_error "Package '{name}' is already installed"
+               else
+                       # Actually install it
+                       var cmd_branch = ""
+                       if version != null then cmd_branch = "--branch '{version}'"
 
-               var cmd = "git clone --depth 1 {cmd_branch} {git_repo.escape_to_sh} {target_dir.escape_to_sh}"
-               if verbose then print "+ {cmd}"
+                       var cmd = "git clone --depth 1 {cmd_branch} {git_repo.escape_to_sh} {target_dir.escape_to_sh}"
+                       if verbose then print "+ {cmd}"
 
-               if "NIT_TESTING".environ == "true" then
-                       # Silence git output when testing
-                       cmd += " 2> /dev/null"
-               end
+                       if "NIT_TESTING".environ == "true" then
+                               # Silence git output when testing
+                               cmd += " 2> /dev/null"
+                       end
 
-               var proc = new Process("sh", "-c", cmd)
-               proc.wait
+                       var proc = new Process("sh", "-c", cmd)
+                       proc.wait
 
-               if proc.status != 0 then
-                       print_error "Install of '{name}' failed"
-                       exit 1
+                       if proc.status != 0 then
+                               print_error "Install of '{name}' failed"
+                               exit 1
+                       end
                end
 
                # Recursive install