瀏覽代碼

refactor(manifest): centralize build directory creation logic

Automatically create build directories for all commands that need them,
including build, install, autoprovides, and test. This removes duplicate
code and ensures consistent behavior across commands. The test command
now also supports automatic temporary directory creation when no build
path is provided.
clanker 1 月之前
父節點
當前提交
449717d503
共有 1 個文件被更改,包括 63 次插入5 次删除
  1. 63 5
      src/cli/Manifest.vala

+ 63 - 5
src/cli/Manifest.vala

@@ -44,11 +44,8 @@ public static int manifest_main(string[] args) {
         return 253;
     }
 
-    if(verb == "build") {
-        return build();
-    }
-
-    if(verb == "install" || verb == "autoprovides") {
+    // Automatically create a temporary directory for these commands if one was not provided.
+    if(verb == "install" || verb == "autoprovides" || verb == "test") {
         if(build_path == null) {
             var dir = File.new_build_filename("/tmp", Uuid.string_random());
             try {
@@ -62,6 +59,25 @@ public static int manifest_main(string[] args) {
         }
     }
 
+    // Automatically create the specified directory for these commands if it doesn't exist
+    if(verb == "install" || verb == "autoprovides" || verb == "test" || verb == "build") {
+        var build_dir = File.new_for_path(build_path);
+        if(!build_dir.query_exists()) {
+            printerr(@"Creating build directory: $build_path\n");
+            try {
+                build_dir.make_directory_with_parents();
+            }
+            catch(Error e) {
+                printerr(@"Could not create build directory: $(e.message)\n");
+                return 255;
+            }
+        }
+    }
+
+    if(verb == "build") {
+        return build();
+    }
+
     if(verb == "install") {
         return install();
     }
@@ -96,6 +112,9 @@ private void manifest_usage() {
 
 
 private int build() {
+    // Create build directory if it doesn't exist
+
+
     var missing_management_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());
     var missing_build_deps = manifest.dependencies.build.where(d => !d.is_satisfied());
 
@@ -131,6 +150,19 @@ private int build() {
 }
 
 private int install() {
+    // Create build directory if it doesn't exist
+    var build_dir = File.new_for_path(build_path);
+    if(!build_dir.query_exists()) {
+        printerr(@"Creating build directory: $build_path\n");
+        try {
+            build_dir.make_directory_with_parents();
+        }
+        catch(Error e) {
+            printerr(@"Could not create build directory: $(e.message)\n");
+            return 255;
+        }
+    }
+
     var missing_management_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());
     var missing_build_deps = manifest.dependencies.build.where(d => !d.is_satisfied());
     var missing_runtime_deps = manifest.dependencies.runtime.where(d => !d.is_satisfied());
@@ -346,6 +378,19 @@ private int package() {
 }
 
 private int autoprovides() {
+    // Create build directory if it doesn't exist
+    var build_dir = File.new_for_path(build_path);
+    if(!build_dir.query_exists()) {
+        printerr(@"Creating build directory: $build_path\n");
+        try {
+            build_dir.make_directory_with_parents();
+        }
+        catch(Error e) {
+            printerr(@"Could not create build directory: $(e.message)\n");
+            return 255;
+        }
+    }
+
     var missing_management_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());
     var missing_build_deps = manifest.dependencies.build.where(d => !d.is_satisfied());
     var missing_runtime_deps = manifest.dependencies.runtime.where(d => !d.is_satisfied());
@@ -608,6 +653,19 @@ private int test() {
             return 255;
         }
         build_path = dir.get_path();
+    } else {
+        // Create build directory if it doesn't exist
+        var build_dir = File.new_for_path(build_path);
+        if(!build_dir.query_exists()) {
+            printerr(@"Creating build directory: $build_path\n");
+            try {
+                build_dir.make_directory_with_parents();
+            }
+            catch(Error e) {
+                printerr(@"Could not create build directory: $(e.message)\n");
+                return 255;
+            }
+        }
     }
 
     var missing_management_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());