diff --git a/docs/commands/README.md b/docs/commands/README.md index 071a1249edb22ee2d0d430276e28a8f1ca7d1601..84e7caf15247f928fb2ad2b77e4e9fe21fe079ba 100644 --- a/docs/commands/README.md +++ b/docs/commands/README.md @@ -18,3 +18,4 @@ Running `zigmod` with no commands will print this list. - [`aq add`](aq_add.md) - [`aq showjson`](aq_showjson.md) - [`aq install`](aq_install.md) +- [`aq update`](aq_update.md) diff --git a/docs/commands/aq.md b/docs/commands/aq.md index c1ff96c031adc6af34b4aaf6f7cdc2161e10cefc..aa513934f180115c4ec8bf1b3567ba17afb2ed5a 100644 --- a/docs/commands/aq.md +++ b/docs/commands/aq.md @@ -15,3 +15,4 @@ The subcommands available are: - [`modfile`](aq_modfile.md) - [`showjson`](aq_showjson.md) - [`install`](aq_install.md) +- [`update`](aq_update.md) diff --git a/docs/commands/aq_update.md b/docs/commands/aq_update.md new file mode 100644 index 0000000000000000000000000000000000000000..ccb155206c7dd8bfa225d45f7a9cf5d6263822e6 --- /dev/null +++ b/docs/commands/aq_update.md @@ -0,0 +1,10 @@ +## `aq update` command +``` +zigmod aq update +``` + +This command takes zero arguments and updates all programs installed with [`zigmod aq install`](./aq_install.md). + +Adding `~/.zigmod/bin` to your `$PATH` will allow you to reference the commands by name instead of by absolute path. + +The directory `~/.cache/zigmod` is a cache directory and may be deleted at any time. diff --git a/src/cmd/aq.zig b/src/cmd/aq.zig index d8816c1bf079f9939f90ce621c0cf9a5a79a3f63..0350da9944d6a9ed8420916fdeccf3bf88feeec8 100644 --- a/src/cmd/aq.zig +++ b/src/cmd/aq.zig @@ -13,6 +13,7 @@ pub const commands = struct { pub const add = @import("./aquila/add.zig"); pub const showjson = @import("./aquila/showjson.zig"); pub const install = @import("./aquila/install.zig"); + pub const update = @import("./aquila/update.zig"); }; pub const server_root = "https://aquila.red"; diff --git a/src/cmd/aquila/update.zig b/src/cmd/aquila/update.zig new file mode 100644 index 0000000000000000000000000000000000000000..e19c7381d501ae266590f8b888acb09cd43c50cf --- /dev/null +++ b/src/cmd/aquila/update.zig @@ -0,0 +1,62 @@ +const std = @import("std"); +const string = []const u8; +const gpa = std.heap.c_allocator; +const knownfolders = @import("known-folders"); + +const zigmod = @import("../../lib.zig"); +const u = @import("./../../util/index.zig"); +const common = @import("./../../common.zig"); + +pub fn execute(args: [][]u8) !void { + const home = try knownfolders.getPath(gpa, .home); + const homepath = home.?; + const homedir = try std.fs.cwd().openDir(homepath, .{}); + + if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { + const f = try homedir.createFile("zigmod.yml", .{}); + defer f.close(); + const w = f.writer(); + const init = @import("../init.zig"); + try init.writeExeManifest(w, try u.random_string(gpa, 48), "zigmod_installation", null, null); + } + u.assert(args.len == 0, "zigmod aq update accepts no parameters", .{}); + + // get modfile and dep + const m = try zigmod.ModFile.from_dir(gpa, homedir); + for (m.rootdeps) |dep| { + // + const cache = try knownfolders.getPath(gpa, .cache); + const cachepath = try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "deps" }); + + // fetch singular pkg + var fetchoptions = common.CollectOptions{ + .log = true, + .update = false, + .alloc = gpa, + }; + try fetchoptions.init(); + const modpath = try common.get_modpath(cachepath, dep, &fetchoptions); + const moddir = try std.fs.cwd().openDir(modpath, .{}); + std.log.info("{s}", .{dep.path}); + + // zigmod ci + const ci = @import("../ci.zig"); + try ci.do(gpa, modpath, moddir); + + // zig build + const argv: []const string = &.{ + "zig", "build", + "--prefix", try std.fs.path.join(gpa, &.{ homepath, ".zigmod" }), + "--cache-dir", try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "zig" }), + }; + const proc = try std.ChildProcess.init(argv, gpa); + proc.cwd = modpath; + const term = try proc.spawnAndWait(); + switch (term) { + .Exited => |v| u.assert(v == 0, "zig build failed with exit code: {d}", .{v}), + .Signal => |v| std.log.info("zig build was interrupted with signal: {d}", .{v}), + .Stopped => |v| std.log.info("zig build was stopped with code: {d}", .{v}), + .Unknown => |v| std.log.info("zig build encountered unknown: {d}", .{v}), + } + } +}