|
@@ -1,6 +1,4 @@
|
|
|
-Usm.Manifest manifest = null;
|
|
|
Usm.Paths paths;
|
|
|
-string? build_path = null;
|
|
|
|
|
|
|
|
|
public static int main(string[] args) {
|
|
@@ -11,55 +9,12 @@ public static int main(string[] args) {
|
|
|
return 255;
|
|
|
}
|
|
|
|
|
|
- var verb = args[1];
|
|
|
-
|
|
|
- if(verb != "remove" && verb != "acquire" && verb != "install") {
|
|
|
- if(args.length < 3) {
|
|
|
- usage();
|
|
|
- return 255;
|
|
|
- }
|
|
|
- build_path = args[2];
|
|
|
- }
|
|
|
-
|
|
|
- if(!File.new_for_path("MANIFEST.usm").query_exists()) {
|
|
|
- printerr("No MANIFEST.usm file found in current directory.\n");
|
|
|
- return 254;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- var element = new InvercargillJson.JsonElement.from_file("MANIFEST.usm");
|
|
|
- manifest = Usm.Manifest.get_mapper().materialise(element.as<Invercargill.Properties>());
|
|
|
- }
|
|
|
- catch (Error e) {
|
|
|
- printerr(@"Could not read MANIFEST.usm: $(e.message)\n");
|
|
|
- return 253;
|
|
|
- }
|
|
|
-
|
|
|
- if(verb == "build") {
|
|
|
- return build();
|
|
|
- }
|
|
|
-
|
|
|
- if(verb == "install") {
|
|
|
- if(build_path == null) {
|
|
|
- var dir = File.new_build_filename("/tmp", Uuid.string_random());
|
|
|
- try {
|
|
|
- dir.make_directory();
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@"Could not create temporary build directory, try specifying one instead: $(e.message)\n");
|
|
|
- return 255;
|
|
|
- }
|
|
|
- build_path = dir.get_path();
|
|
|
- }
|
|
|
- return install();
|
|
|
- }
|
|
|
-
|
|
|
- if(verb == "acquire") {
|
|
|
- return acquire();
|
|
|
- }
|
|
|
-
|
|
|
- if(verb == "remove") {
|
|
|
- return uininstall();
|
|
|
+ var command = args[1];
|
|
|
+ if(command == "manifest") {
|
|
|
+ var m_args = new Invercargill.Vector<string>();
|
|
|
+ m_args.add_all(Invercargill.Convert.ate(args));
|
|
|
+ m_args.remove(1);
|
|
|
+ return manifest_main(m_args.to_array());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -68,223 +23,5 @@ public static int main(string[] args) {
|
|
|
}
|
|
|
|
|
|
private void usage() {
|
|
|
- printerr("USAGE:\n\tusm build <build path>\n\tusm install <build path>\n\tusm remove\nusm acquire\n");
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-private int build() {
|
|
|
- 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 sane = true;
|
|
|
- if(missing_management_deps.any()) {
|
|
|
- sane = false;
|
|
|
- foreach (var item in missing_management_deps) {
|
|
|
- printerr(@"Missing management dependency \"$item\".\n");
|
|
|
- }
|
|
|
- }
|
|
|
- if(missing_build_deps.any()) {
|
|
|
- sane = false;
|
|
|
- foreach (var item in missing_build_deps) {
|
|
|
- printerr(@"Missing build dependency \"$item\".\n");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!sane) {
|
|
|
- printerr("Could not build manifest, missing dependencies\n");
|
|
|
- return 252;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- var proc = manifest.run_build(build_path, paths, SubprocessFlags.INHERIT_FDS);
|
|
|
- proc.wait_check();
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@"Error running build exec: $(e.message)\n");
|
|
|
- return 251;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-private int install() {
|
|
|
- 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());
|
|
|
-
|
|
|
- var sane = true;
|
|
|
- if(missing_management_deps.any()) {
|
|
|
- sane = false;
|
|
|
- foreach (var item in missing_management_deps) {
|
|
|
- printerr(@"Missing management dependency \"$item\".\n");
|
|
|
- }
|
|
|
- }
|
|
|
- if(missing_build_deps.any()) {
|
|
|
- sane = false;
|
|
|
- foreach (var item in missing_build_deps) {
|
|
|
- printerr(@"Missing build dependency \"$item\".\n");
|
|
|
- }
|
|
|
- }
|
|
|
- if(missing_runtime_deps.any()) {
|
|
|
- sane = false;
|
|
|
- foreach (var item in missing_build_deps) {
|
|
|
- printerr(@"Missing runtime dependency \"$item\".\n");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!sane) {
|
|
|
- printerr("Could not install manifest, missing dependencies\n");
|
|
|
- return 252;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- var proc = manifest.run_build(build_path, paths, SubprocessFlags.INHERIT_FDS);
|
|
|
- proc.wait_check();
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@"Error running build exec: $(e.message)\n");
|
|
|
- return 251;
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var resource in manifest.provides) {
|
|
|
- var path = paths.get_suggested_path(resource.key);
|
|
|
- printerr(@"Installing $(resource.key) to $path...");
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@" $(e.message)\n");
|
|
|
- return 250;
|
|
|
- }
|
|
|
- printerr(" done\n");
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- var proc = manifest.run_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;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
+ printerr("USAGE:\n\tusm manifest\n");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-private int acquire() {
|
|
|
- if(manifest.executables.acquire == null) {
|
|
|
- printerr(@"Manifest does not reference an acquire script\n");
|
|
|
- return 248;
|
|
|
- }
|
|
|
-
|
|
|
- if(manifest.dependencies.acquire != null) {
|
|
|
- var missing_acquire_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());
|
|
|
- if(missing_acquire_deps.any()) {
|
|
|
- foreach (var item in missing_acquire_deps) {
|
|
|
- printerr(@"Missing acquire dependency \"$item\".\n");
|
|
|
- }
|
|
|
- printerr("Could not build manifest, missing dependencies\n");
|
|
|
- return 247;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- var proc = manifest.run_acquire(SubprocessFlags.INHERIT_FDS);
|
|
|
- proc.wait_check();
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@"Error running build exec: $(e.message)\n");
|
|
|
- return 251;
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-private int uininstall() {
|
|
|
- var missing_management_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());
|
|
|
-
|
|
|
- if(missing_management_deps.any()) {
|
|
|
- foreach (var item in missing_management_deps) {
|
|
|
- printerr(@"Missing management dependency \"$item\".\n");
|
|
|
- }
|
|
|
-
|
|
|
- printerr("Could not remove manifest, missing dependencies\n");
|
|
|
- return 252;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- var proc = manifest.run_remove(Usm.RemoveType.FINAL, SubprocessFlags.INHERIT_FDS);
|
|
|
- if(proc != null) {
|
|
|
- proc.wait_check();
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@"Error running remove exec: $(e.message)\n");
|
|
|
- return 249;
|
|
|
- }
|
|
|
-
|
|
|
- // Do files and symlinks first
|
|
|
- foreach (var resource in manifest.provides.where(r => r.value.file_type != Usm.ManifestFileType.DIRECTORY)) {
|
|
|
- var path = paths.get_suggested_path(resource.key);
|
|
|
- printerr(@"Deleting resource $(resource.key) from $path...");
|
|
|
- try {
|
|
|
- var file = File.new_for_path(path);
|
|
|
- if(file.query_exists()) {
|
|
|
- file.delete();
|
|
|
- printerr(" done\n");
|
|
|
- }
|
|
|
- else {
|
|
|
- printerr(" file missing\n");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@" $(e.message)\n");
|
|
|
- return 250;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Do directories last
|
|
|
- foreach (var resource in manifest.provides.where(r => r.value.file_type == Usm.ManifestFileType.DIRECTORY)) {
|
|
|
- var path = paths.get_suggested_path(resource.key);
|
|
|
- printerr(@"Deleting resource $(resource.key) from $path...");
|
|
|
- try {
|
|
|
- var file = File.new_for_path(path);
|
|
|
- if(file.query_exists()) {
|
|
|
- file.delete();
|
|
|
- printerr(" done\n");
|
|
|
- }
|
|
|
- else {
|
|
|
- printerr(" file missing\n");
|
|
|
- }
|
|
|
- }
|
|
|
- catch(IOError.NOT_EMPTY e) {
|
|
|
- printerr(" directory not empty\n");
|
|
|
- }
|
|
|
- catch(Error e) {
|
|
|
- printerr(@" $(e.message)\n");
|
|
|
- return 250;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|