Преглед изворни кода

feat(cli): add --replace flag to autoprovides command

Add new --replace flag to autoprovides command that updates the manifest's
provides property instead of just printing the generated provides. When used,
the command replaces the existing provides in MANIFEST.usm with the newly
generated ones.

Also includes:
- Updated libc dependency specification to lib:libc.so.6 in scaffolding
- Improved JSON formatting in manifest file generation with pretty printing
- Optimized manifest serialization for as-expected file references
clanker пре 1 месец
родитељ
комит
94bb06f0b7
3 измењених фајлова са 64 додато и 8 уклоњено
  1. 46 4
      src/cli/Manifest.vala
  2. 9 3
      src/cli/Scaffold.vala
  3. 9 1
      src/lib/Manifest.vala

+ 46 - 4
src/cli/Manifest.vala

@@ -1,5 +1,6 @@
 Usm.Manifest manifest = null;
 string? build_path = null;
+bool replace_provides = false;
 
 
 public static int manifest_main(string[] args) {
@@ -11,8 +12,17 @@ public static int manifest_main(string[] args) {
     }
 
     var verb = args[1];
-
-    if(verb != "remove" && verb != "acquire" && verb != "install" && verb != "package" && verb != "autoprovides") {
+    
+    // Check for --replace flag for autoprovides
+    if(verb == "autoprovides") {
+        for(int i = 2; i < args.length; i++) {
+            if(args[i] == "--replace") {
+                replace_provides = true;
+            } else if(build_path == null) {
+                build_path = args[i];
+            }
+        }
+    } else if(verb != "remove" && verb != "acquire" && verb != "install" && verb != "package") {
         if(args.length < 3) {
             manifest_usage();
             return 255;
@@ -78,7 +88,7 @@ public static int manifest_main(string[] args) {
 }
 
 private void manifest_usage() {
-    printerr("USAGE:\n\tusm manifest build <build path>\n\tusm manifest install <build path>\n\tusm manifest remove\nusm manifest acquire\n");
+    printerr("USAGE:\n\tusm manifest build <build path>\n\tusm manifest install <build path>\n\tusm manifest remove\nusm manifest acquire\nusm manifest autoprovides [--replace] [build path]\n");
 }
 
 
@@ -404,8 +414,40 @@ private int autoprovides() {
         if(provides.any()) {
             json = json.substring(0, json.length - 2);
         }
+        json += "\n}";
 
-        print(@"$json\n}\n");
+        if(replace_provides) {
+            try {
+                // Update the manifest's provides property
+                var new_provides = new Invercargill.DataStructures.Dictionary<Usm.ResourceRef, Usm.ManifestFile>();
+                foreach (var item in provides) {
+                    new_provides[new Usm.ResourceRef(item)] = new Usm.ManifestFile.from_string("as-expected");
+                }
+                manifest.provides = new_provides;
+                
+                // Serialize the updated manifest back to JSON
+                var mapper = Usm.Manifest.get_mapper();
+                var properties = mapper.map_from(manifest);
+                var json_element = new InvercargillJson.JsonElement.from_properties(properties);
+                var json_string = json_element.stringify(true);
+                
+                // Write the updated manifest to file
+                var file = File.new_for_path("MANIFEST.usm");
+                var data_stream = new DataOutputStream(file.replace(null, false, FileCreateFlags.REPLACE_DESTINATION));
+                data_stream.put_string(json_string);
+                
+                printerr("Successfully updated 'provides' property in MANIFEST.usm\n");
+            }
+            catch(Error e) {
+                printerr(@"Error updating MANIFEST.usm: $(e.message)\n");
+                printerr("Original file left unchanged. Generated provides:\n");
+                print(@"$json\n");
+                return 249;
+            }
+        } else {
+            print(@"$json\n");
+        }
+        
         return 0;
     }
     catch(Error e) {

+ 9 - 3
src/cli/Scaffold.vala

@@ -98,14 +98,14 @@ private Usm.Manifest create_manifest(string name, string template, HashSet<strin
         manifest.dependencies.build.add(new Usm.ResourceRef("bin:valac"));
         manifest.dependencies.build.add(new Usm.ResourceRef("pc:glib-2.0.pc"));
         manifest.dependencies.build.add(new Usm.ResourceRef("pc:gobject-2.0.pc"));
-        manifest.dependencies.runtime.add(new Usm.ResourceRef("lib:libc.so"));
+        manifest.dependencies.runtime.add(new Usm.ResourceRef("lib:libc.so.6"));
         manifest.dependencies.runtime.add(new Usm.ResourceRef("lib:libglib-2.0.so"));
         manifest.dependencies.runtime.add(new Usm.ResourceRef("lib:libgobject-2.0.so"));
     }
     
     if(attributes.contains("c")) {
         manifest.dependencies.build.add(new Usm.ResourceRef("bin:gcc"));
-        manifest.dependencies.runtime.add(new Usm.ResourceRef("lib:libc.so"));
+        manifest.dependencies.runtime.add(new Usm.ResourceRef("lib:libc.so.6"));
     }
     
     if(attributes.contains("acquire")) {
@@ -124,7 +124,13 @@ private void write_manifest_file(Usm.Manifest manifest) throws Error {
     var properties = mapper.map_from(manifest);
     var json_element = new InvercargillJson.JsonElement.from_properties(properties);
     
-    json_element.write_to_file("MANIFEST.usm");
+    // Create pretty JSON string
+    var json_string = json_element.stringify(true);
+    
+    // Write to file manually
+    var file = File.new_for_path("MANIFEST.usm");
+    var data_stream = new DataOutputStream(file.replace(null, false, FileCreateFlags.NONE));
+    data_stream.put_string(json_string);
 }
 
 private void create_scripts(string template, HashSet<string> attributes) throws Error {

+ 9 - 1
src/lib/Manifest.vala

@@ -127,7 +127,15 @@ namespace Usm {
             var mapper = ManifestFile.get_mapper();
             foreach (var pair in provides) {
                 try {
-                    dict.set_native<Properties>(pair.key.to_string(), mapper.map_from(pair.value));
+                    // Handle special case: when pathBase is as-expected, path is empty, and type is reg
+                    // output string "as-expected" instead of full JSON object
+                    if(pair.value.path_base == ManifestFilePathBase.AS_EXPECTED &&
+                       pair.value.path == "" &&
+                       pair.value.file_type == ManifestFileType.REGULAR) {
+                        dict.set_native<string>(pair.key.to_string(), "as-expected");
+                    } else {
+                        dict.set_native<Properties>(pair.key.to_string(), mapper.map_from(pair.value));
+                    }
                 }
                 catch(Error e) {
                     assert_not_reached();