Bläddra i källkod

Incomplete changes

Billy Barrow 6 månader sedan
förälder
incheckning
1b7ac988c2
8 ändrade filer med 112 tillägg och 39 borttagningar
  1. 9 8
      MANIFEST.usm
  2. 10 0
      scripts/install.sh
  3. 31 26
      src/cli/Manifest.vala
  4. 1 0
      src/lib/File.vala
  5. 37 3
      src/lib/Manifest.vala
  6. 21 0
      src/lib/Paths.vala
  7. 1 1
      src/lib/State/State.vala
  8. 2 1
      src/lib/Transaction.vala

+ 9 - 8
MANIFEST.usm

@@ -4,13 +4,13 @@
   "summary": "Universal Source Manifest",
   "licences": [ {"name": "GPLv3", "category": "libre", "text": "src/LICENSE"} ],
   "provides": {
-    "bin:usm": "build:cli/usm",
-    "lib:libusm.so": "build:lib/libusm.so",
-    "inc:usm.h": "build:lib/usm.h",
-    "vapi:usm.vapi": "build:lib/usm.vapi",
-    "typelib:usm-1.0.typelib": "build:lib/usm-1.0.typelib",
-    "gir:usm-1.0.gir": "build:lib/usm-1.0.gir",
-    "pc:usm.pc": "build:meson-private/usm.pc"
+    "bin:usm": "as-expected",
+    "lib:libusm.so": "as-expected",
+    "inc:usm.h": "as-expected",
+    "vapi:usm.vapi": "as-expected",
+    "typelib:usm-1.0.typelib": "as-expected",
+    "gir:usm-1.0.gir": "as-expected",
+    "pc:usm.pc": "as-expected"
   },
   "depends": {
     "runtime": [
@@ -49,6 +49,7 @@
   },
   "execs": {
     "build": "scripts/build.sh",
-    "acquire": "scripts/acquire.sh"
+    "acquire": "scripts/acquire.sh",
+    "install": "scripts/install.sh"
   }
 }

+ 10 - 0
scripts/install.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+
+src_dir=$(pwd)
+build_dir=$1
+install_dir=$2
+
+cd ${build_dir}
+
+meson install --destdir ${install_dir}

+ 31 - 26
src/cli/Manifest.vala

@@ -130,7 +130,7 @@ private int install() {
     }
     if(missing_runtime_deps.any()) {
         sane = false;
-        foreach (var item in missing_build_deps) {
+        foreach (var item in missing_runtime_deps) {
             printerr(@"Missing runtime dependency \"$item\".\n");
         }
     }
@@ -149,44 +149,49 @@ private int install() {
         return 251;
     }
 
-    foreach (var resource in manifest.provides) {
-        var path = paths.get_suggested_path(resource.key);
-        printerr(@"Installing $(resource.key) to $path...");
+    var install_dir = File.new_build_filename("/tmp", Uuid.string_random());
+    if(manifest.executables.install != null) {
         try {
-            if(resource.value.file_type == Usm.ManifestFileType.REGULAR) {
-                var src = File.new_build_filename(build_path, resource.value.path);
-                var dest = File.new_for_path(path);
-                src.copy(dest, FileCopyFlags.OVERWRITE);
-            }
-            else if(resource.value.file_type == Usm.ManifestFileType.DIRECTORY) {
-                var dest = File.new_for_path(path);
-                dest.make_directory();
-            }
-            else if(resource.value.file_type == Usm.ManifestFileType.SYMBOLIC_LINK) {
-                var dest = File.new_for_path(path);
-                dest.make_symbolic_link(resource.value.path);
-            }
-            else {
-                printerr(@" File type not implemented\n");
-                return 250;
-            }
+            install_dir.make_directory();
         }
         catch(Error e) {
-            printerr(@" $(e.message)\n");
+            printerr(@"Could not create temporary install directory: $(e.message)\n");
             return 250;
         }
-        printerr(" done\n");
+
+        try {
+            manifest.run_install(build_path, install_dir.get_path(), paths, Usm.InstallType.FRESH, SubprocessFlags.INHERIT_FDS).wait_check();
+        }
+        catch(Error e) {
+            printerr(@"Error running install exec: $(e.message)\n");
+            return 249;
+        }
+    }
+    else {
+        install_dir = null;
     }
 
     try {
-        var proc = manifest.run_install(build_path, Usm.InstallType.FRESH, SubprocessFlags.INHERIT_FDS);
+        manifest.install_resources(Environment.get_current_dir(), build_path, install_dir?.get_path(), paths, (r, c, t, f) => {
+            if(f == 0.0f) {
+                printerr(@"Installing resource $(c+1)/$t: \"$(r)\"\n");
+            }
+        });
+    }
+    catch(Error e) {
+        printerr(@"Error installing manifest resources: $(e.message)\n");
+        return 248;
+    }
+
+    try {
+        var proc = manifest.run_post_install(build_path, Usm.InstallType.FRESH, SubprocessFlags.INHERIT_FDS);
         if(proc != null) {
             proc.wait_check();
         }
     }
     catch(Error e) {
-        printerr(@"Error running install exec: $(e.message)\n");
-        return 249;
+        printerr(@"Error running post install exec: $(e.message)\n");
+        return 247;
     }
 
     return 0;

+ 1 - 0
src/lib/File.vala

@@ -28,6 +28,7 @@ namespace Usm {
             path_base = ManifestFilePathBase.from_string(parts[0]);
             file_type = ManifestFileType.REGULAR;
             if(path_base == ManifestFilePathBase.AS_EXPECTED) {
+                path = "";
                 return;
             }
             if(parts.length != 2) {

+ 37 - 3
src/lib/Manifest.vala

@@ -13,6 +13,7 @@ namespace Usm {
         INVALID_PACKAGE,
         INVALID_PATH_BASE,
         INVALID_FILE_PATH,
+        INVALID_FLAG
     }
 
     public class Manifest {
@@ -23,6 +24,7 @@ namespace Usm {
         public Dictionary<ResourceRef, ManifestFile> provides { get; set; }
         public Dependencies dependencies { get; set; }
         public Executables executables { get; set; }
+        public Vector<ManifestFlag> flags { get; set; }
 
         public string? markdown_path { get; set; }
         public string? url { get; set; }
@@ -141,17 +143,22 @@ namespace Usm {
             return proc;
         }
 
-        public Subprocess? run_install(string build_path, string install_path, InstallType type, SubprocessFlags flags) throws Error {
+        public Subprocess? run_install(string build_path, string install_path, Paths paths, InstallType type, SubprocessFlags flags) throws Error {
             if(executables.install == null) {
                 return null;
             }
             var path = Path.build_filename(Environment.get_current_dir(), executables.install);
+
+            // Override destination environment variable
+            var new_paths = paths.clone();
+            new_paths.destination = install_path;
+            new_paths.set_envs();
             var proc = new Subprocess.newv(new string[] { path, build_path, install_path, type.to_string() }, flags);
             return proc;
         }
 
         public Subprocess? run_post_install(string build_path, InstallType type, SubprocessFlags flags) throws Error {
-            if(executables.install == null) {
+            if(executables.post_install == null) {
                 return null;
             }
             var path = Path.build_filename(Environment.get_current_dir(), executables.post_install);
@@ -212,7 +219,7 @@ namespace Usm {
                         default:
                             assert_not_reached();                            
                     }
-                    var src = File.new_build_filename(build_path, resource.value.path);
+                    var src = File.new_build_filename(base_path, resource.value.path);
                     var dest = File.new_for_path(path);
 
                     if(!src.query_exists()) {
@@ -346,4 +353,31 @@ namespace Usm {
             }
         }
     }
+
+    public enum ManifestFlag {
+        BUILD_IN_SOURCE_TREE,
+        SET_MANIFEST_PROPERTY_ENVS;
+
+        public string to_string() {
+            switch (this) {
+                case ManifestFlag.BUILD_IN_SOURCE_TREE:
+                    return "buildInSourceTree";
+                case ManifestFlag.SET_MANIFEST_PROPERTY_ENVS:
+                    return "setManifestPropertyEnvs";
+                default:
+                    assert_not_reached();
+            }
+        }
+
+        public static ManifestFlag from_string(string str) throws ManifestError {
+            switch (str) {
+                case "buildInSourceTree":
+                    return ManifestFlag.BUILD_IN_SOURCE_TREE;
+                case "setManifestPropertyEnvs":
+                    return ManifestFlag.SET_MANIFEST_PROPERTY_ENVS;
+                default:
+                    throw new ManifestError.INVALID_FLAG(@"Unknown flag \"$str\".");
+            }
+        }
+    }
 }

+ 21 - 0
src/lib/Paths.vala

@@ -139,6 +139,27 @@ namespace Usm {
 
             usm_config_dir = Environment.get_variable("USM_CONFIGDIR") ?? defaults.usm_config_dir;
         }
+
+        public Paths clone() {
+            return new Paths() {
+                destination = destination,
+                prefix = prefix,
+                bin = bin,
+                include = include,
+                data = data,
+                info = info,
+                lib = lib,
+                man = man,
+                libexec = libexec,
+                locale = locale,
+                local_state = local_state,
+                sbin = sbin,
+                shared_state = shared_state,
+                sys_config = sys_config,
+                tags = tags,
+                usm_config_dir = usm_config_dir,
+            };
+        }
     }
 
 }

+ 1 - 1
src/lib/State/State.vala

@@ -48,7 +48,7 @@ namespace Usm {
             var latest = directory(list_path)
                 .where(f => f.has_suffix(".usml"))
                 .contextualised_select<DateTime>(f => new DateTime.from_iso8601(f.replace(".usml", ""), null))
-                .sort((a, b) => a.result.compare(b.result))
+                .sort((a, b) => b.result.compare(a.result))
                 .first_or_default();
 
             var stream = new DataInputStream(File.new_build_filename(list_path, latest.origin).read());

+ 2 - 1
src/lib/Transaction.vala

@@ -241,7 +241,7 @@ namespace Usm {
             // Run install process if present
             if(manifest.executables.install != null) {
                 install_dir = package.create_install_directory();
-                var install_proc = manifest.run_install(build_dir, install_dir, InstallType.FRESH, SubprocessFlags.STDOUT_SILENCE);
+                var install_proc = manifest.run_install(build_dir, install_dir, paths, InstallType.FRESH, SubprocessFlags.STDOUT_SILENCE);
                 install_proc.wait_check();
             }
 
@@ -249,6 +249,7 @@ namespace Usm {
             manifest.install_resources(source_dir, build_dir, install_dir, paths, (r, cr, tr, f) => report_progress(TransactionTask.INSTALLING, ((float)cr + (float)f) / (float)tr));
 
             // Run post install process if present
+            report_progress(TransactionTask.INSTALLING, 1.0f);
             var post_install_proc = manifest.run_post_install(build_dir, InstallType.FRESH, SubprocessFlags.STDOUT_SILENCE);
             if(post_install_proc != null)
             post_install_proc.wait_check();