Kaynağa Gözat

fix: rebuild uses per-stage task types (unpack/rebuild/test/install); add --clean flag to rebuild for from-scratch compilation; clean_build_cache method

clanker 1 hafta önce
ebeveyn
işleme
e229592d80

+ 31 - 5
src/cli/Rebuild.vala

@@ -1,16 +1,37 @@
 /**
- * `usm rebuild <package>` — rebuild an installed package from its
- * cached sources through {@link Usm.Transaction.rebuild_package}, the
+ * `usm rebuild <package> [--clean]` — rebuild an installed package from
+ * its cached sources through {@link Usm.Transaction.rebuild_package}, the
  * standard pipeline with build-cache restore and a clean retry on
  * failure, then reinstall its resources. Non-destructive (same version,
  * same state directory), so no confirmation is needed.
+ *
+ * `--clean` discards the build cache (build directory + build.tar.xz)
+ * before rebuilding, forcing a from-scratch compilation.
  */
 private int rebuild_main(string[] args) {
 
-    if(args.length != 3 || args[2].has_prefix("-")) {
+    bool clean_build = false;
+    string? package_name = null;
+
+    for(int i = 2; i < args.length; i++) {
+        var arg = args[i];
+        if(arg == "--clean") {
+            clean_build = true;
+        }
+        else if(arg.has_prefix("-")) {
+            return rebuild_usage();
+        }
+        else if(package_name == null) {
+            package_name = arg;
+        }
+        else {
+            return rebuild_usage();
+        }
+    }
+
+    if(package_name == null) {
         return rebuild_usage();
     }
-    var package_name = args[2];
 
     var progress = new Usm.Cli.ProgressBar();
 
@@ -30,6 +51,11 @@ private int rebuild_main(string[] args) {
             return 254;
         }
 
+        if(clean_build) {
+            target.clean_build_cache();
+            print("Cleared build cache for %s\n", target.package_name);
+        }
+
         var transaction = new Usm.Transaction() {
             paths = paths,
             resource_finder = new Usm.ResourceFinder(paths),
@@ -51,6 +77,6 @@ private int rebuild_main(string[] args) {
 }
 
 private int rebuild_usage() {
-    printerr("USAGE:\n\tusm rebuild <package>\n");
+    printerr("USAGE:\n\tusm rebuild <package> [--clean]\n");
     return 255;
 }

+ 13 - 0
src/lib/State/CachedPackage.vala

@@ -118,6 +118,19 @@ namespace Usm {
             }
         }
 
+        /**
+         * Removes the build directory AND the build.tar.xz archive,
+         * forcing the next build to compile from scratch.
+         */
+        public void clean_build_cache() throws Error {
+            clean_build_directory();
+            var archive = build_archive_path();
+            var archive_file = File.new_for_path(archive);
+            if(archive_file.query_exists()) {
+                archive_file.delete();
+            }
+        }
+
         public string get_source_directory() throws Error {
             var path = source_directory_path();
             if(File.new_for_path(path).query_exists()) {

+ 3 - 3
src/lib/Transaction.vala

@@ -170,10 +170,10 @@ namespace Usm {
             try {
                 journal.begin();
 
-                do_for(packages, unpack_package, TransactionTask.REBUILDING);
+                do_for(packages, unpack_package, TransactionTask.UNPACKING);
                 do_for(packages, build_package, TransactionTask.REBUILDING);
-                do_for(packages, test_package, TransactionTask.REBUILDING);
-                do_for(packages, install_package, TransactionTask.REBUILDING);
+                do_for(packages, test_package, TransactionTask.TESTING);
+                do_for(packages, install_package, TransactionTask.INSTALLING);
                 do_for(packages, cleanup_package, TransactionTask.CLEANING_UP);
 
                 journal.finish();