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