authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-06 17:55:58 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-06 17:55:58 -08:00
log80e9328e7e341a7221e63240c52b38981d5916b0
tree231f0eafed4167fb9d198e7e01c0d30d6b2084c7
parent79a8b81546898b2a3608f3e3313b13ec81b69e8b

add `zigmod aq update` command


5 files changed, 75 insertions(+), 0 deletions(-)

docs/commands/README.md+1
......@@ -18,3 +18,4 @@ Running `zigmod` with no commands will print this list.
1818- [`aq add`](aq_add.md)
1919- [`aq showjson`](aq_showjson.md)
2020- [`aq install`](aq_install.md)
21- [`aq update`](aq_update.md)
docs/commands/aq.md+1
......@@ -15,3 +15,4 @@ The subcommands available are:
1515- [`modfile`](aq_modfile.md)
1616- [`showjson`](aq_showjson.md)
1717- [`install`](aq_install.md)
18- [`update`](aq_update.md)
docs/commands/aq_update.md created+10
......@@ -0,0 +1,10 @@
1## `aq update` command
2```
3zigmod aq update
4```
5
6This command takes zero arguments and updates all programs installed with [`zigmod aq install`](./aq_install.md).
7
8Adding `~/.zigmod/bin` to your `$PATH` will allow you to reference the commands by name instead of by absolute path.
9
10The directory `~/.cache/zigmod` is a cache directory and may be deleted at any time.
src/cmd/aq.zig+1
......@@ -13,6 +13,7 @@ pub const commands = struct {
1313 pub const add = @import("./aquila/add.zig");
1414 pub const showjson = @import("./aquila/showjson.zig");
1515 pub const install = @import("./aquila/install.zig");
16 pub const update = @import("./aquila/update.zig");
1617};
1718
1819pub const server_root = "https://aquila.red";
src/cmd/aquila/update.zig created+62
......@@ -0,0 +1,62 @@
1const std = @import("std");
2const string = []const u8;
3const gpa = std.heap.c_allocator;
4const knownfolders = @import("known-folders");
5
6const zigmod = @import("../../lib.zig");
7const u = @import("./../../util/index.zig");
8const common = @import("./../../common.zig");
9
10pub 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}