| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const gpa = std.heap.c_allocator; |
| 4 | const knownfolders = @import("known-folders"); |
| 5 | |
| 6 | const zigmod = @import("../../lib.zig"); |
| 7 | const u = @import("./../../util/index.zig"); |
| 8 | const common = @import("./../../common.zig"); |
| 9 | |
| 10 | pub fn execute(args: [][]u8) !void { |
| 11 | const home = try knownfolders.getPath(gpa, .home); |
| 12 | const homepath = home.?; |
| 13 | const homedir = try std.fs.cwd().openDir(homepath, .{}); |
| 14 | |
| 15 | if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { |
| 16 | const f = try homedir.createFile("zigmod.yml", .{}); |
| 17 | defer f.close(); |
| 18 | const w = f.writer(); |
| 19 | const init = @import("../init.zig"); |
| 20 | try init.writeExeManifest(w, try u.random_string(gpa, 48), "zigmod_installation", null, null); |
| 21 | } |
| 22 | u.assert(args.len == 0, "zigmod aq update accepts no parameters", .{}); |
| 23 | |
| 24 | // get modfile and dep |
| 25 | const m = try zigmod.ModFile.from_dir(gpa, homedir); |
| 26 | for (m.rootdeps) |dep| { |
| 27 | // |
| 28 | const cache = try knownfolders.getPath(gpa, .cache); |
| 29 | const cachepath = try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "deps" }); |
| 30 | |
| 31 | // fetch singular pkg |
| 32 | var fetchoptions = common.CollectOptions{ |
| 33 | .log = true, |
| 34 | .update = false, |
| 35 | .alloc = gpa, |
| 36 | }; |
| 37 | try fetchoptions.init(); |
| 38 | const modpath = try common.get_modpath(cachepath, dep, &fetchoptions); |
| 39 | const moddir = try std.fs.cwd().openDir(modpath, .{}); |
| 40 | std.log.info("{s}", .{dep.path}); |
| 41 | |
| 42 | // zigmod ci |
| 43 | const ci = @import("../ci.zig"); |
| 44 | try ci.do(gpa, modpath, moddir); |
| 45 | |
| 46 | // zig build |
| 47 | const argv: []const string = &.{ |
| 48 | "zig", "build", |
| 49 | "--prefix", try std.fs.path.join(gpa, &.{ homepath, ".zigmod" }), |
| 50 | "--cache-dir", try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "zig" }), |
| 51 | }; |
| 52 | const proc = try std.ChildProcess.init(argv, gpa); |
| 53 | proc.cwd = modpath; |
| 54 | const term = try proc.spawnAndWait(); |
| 55 | switch (term) { |
| 56 | .Exited => |v| u.assert(v == 0, "zig build failed with exit code: {d}", .{v}), |
| 57 | .Signal => |v| std.log.info("zig build was interrupted with signal: {d}", .{v}), |
| 58 | .Stopped => |v| std.log.info("zig build was stopped with code: {d}", .{v}), |
| 59 | .Unknown => |v| std.log.info("zig build encountered unknown: {d}", .{v}), |
| 60 | } |
| 61 | } |
| 62 | } |