diff options
| -rw-r--r-- | build.zig | 51 | ||||
| m--------- | libs/clap | 0 | ||||
| -rw-r--r-- | src/Installation.zig | 4 | ||||
| -rw-r--r-- | src/install.zig | 4 | ||||
| -rw-r--r-- | src/list.zig | 13 | ||||
| -rw-r--r-- | src/main.zig | 14 | ||||
| -rw-r--r-- | src/remove.zig | 4 | ||||
| -rw-r--r-- | src/subcommand.zig | 6 | ||||
| -rw-r--r-- | src/switch.zig | 2 | ||||
| -rw-r--r-- | src/update.zig | 2 |
10 files changed, 54 insertions, 46 deletions
| @@ -1,25 +1,38 @@ | |||
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | const Builder = std.build.Builder; | 4 | const Build = std.Build; |
| 5 | const SemanticVersion = std.SemanticVersion; | 5 | const SemanticVersion = std.SemanticVersion; |
| 6 | const Version = std.builtin.Version; | ||
| 6 | 7 | ||
| 7 | pub fn build(b: *Builder) void { | 8 | pub fn build(b: *Build) void { |
| 8 | const target = b.standardTargetOptions(.{}); | 9 | const target = b.standardTargetOptions(.{}); |
| 9 | const mode = b.standardReleaseOptions(); | 10 | const optimize = b.standardOptimizeOption(.{}); |
| 11 | |||
| 12 | const semanticVersion = getSemanticVersion(b); | ||
| 13 | const version = Version{ | ||
| 14 | .major = @intCast(u32, semanticVersion.major), | ||
| 15 | .minor = @intCast(u32, semanticVersion.minor), | ||
| 16 | .patch = @intCast(u32, semanticVersion.patch), | ||
| 17 | }; | ||
| 10 | 18 | ||
| 11 | const config = b.addOptions(); | 19 | const config = b.addOptions(); |
| 12 | config.addOption(SemanticVersion, "version", getVersion(b)); | 20 | config.addOption(SemanticVersion, "version", semanticVersion); |
| 13 | 21 | ||
| 14 | const exe = b.addExecutable("zup", "src/main.zig"); | 22 | const exe = b.addExecutable(.{ |
| 15 | exe.setTarget(target); | 23 | .name = "zup", |
| 16 | exe.setBuildMode(mode); | 24 | .version = version, |
| 25 | .root_source_file = .{ .path = "src/main.zig" }, | ||
| 26 | .target = target, | ||
| 27 | .optimize = optimize, | ||
| 28 | }); | ||
| 17 | exe.addOptions("zup-config", config); | 29 | exe.addOptions("zup-config", config); |
| 18 | exe.addPackagePath("clap", "libs/clap/clap.zig"); | 30 | exe.addModule("clap", b.createModule(.{ .source_file = .{ .path = "libs/clap/clap.zig" }})); |
| 19 | exe.addPackagePath("curl", "libs/curl/curl.zig"); | 31 | exe.addModule("curl", b.createModule(.{ .source_file = .{ .path = "libs/curl/curl.zig" }})); |
| 20 | exe.addPackagePath("libarchive", "libs/libarchive/libarchive.zig"); | 32 | exe.addModule("libarchive", b.createModule(.{ |
| 21 | exe.addPackagePath("xdg", "libs/xdg/xdg.zig"); | 33 | .source_file = .{ .path = "libs/libarchive/libarchive.zig" }, |
| 22 | exe.addPackagePath("zup", "src/main.zig"); | 34 | })); |
| 35 | exe.addModule("xdg", b.createModule(.{ .source_file = .{ .path = "libs/xdg/xdg.zig" }})); | ||
| 23 | exe.linkLibC(); | 36 | exe.linkLibC(); |
| 24 | exe.linkSystemLibrary("libarchive"); | 37 | exe.linkSystemLibrary("libarchive"); |
| 25 | exe.linkSystemLibrary("libcurl"); | 38 | exe.linkSystemLibrary("libcurl"); |
| @@ -34,9 +47,11 @@ pub fn build(b: *Builder) void { | |||
| 34 | const run_step = b.step("run", "Run the app"); | 47 | const run_step = b.step("run", "Run the app"); |
| 35 | run_step.dependOn(&run_cmd.step); | 48 | run_step.dependOn(&run_cmd.step); |
| 36 | 49 | ||
| 37 | const exe_tests = b.addTest("src/main.zig"); | 50 | const exe_tests = b.addTest(.{ |
| 38 | exe_tests.setTarget(target); | 51 | .root_source_file = .{ .path = "src/main.zig" }, |
| 39 | exe_tests.setBuildMode(mode); | 52 | .target = target, |
| 53 | .optimize = optimize, | ||
| 54 | }); | ||
| 40 | 55 | ||
| 41 | const test_step = b.step("test", "Run unit tests"); | 56 | const test_step = b.step("test", "Run unit tests"); |
| 42 | test_step.dependOn(&exe_tests.step); | 57 | test_step.dependOn(&exe_tests.step); |
| @@ -44,15 +59,15 @@ pub fn build(b: *Builder) void { | |||
| 44 | 59 | ||
| 45 | const default_version = SemanticVersion.parse("0.2.1") catch unreachable; | 60 | const default_version = SemanticVersion.parse("0.2.1") catch unreachable; |
| 46 | 61 | ||
| 47 | fn getVersion(b: *Builder) SemanticVersion { | 62 | fn getSemanticVersion(b: *Build) SemanticVersion { |
| 48 | var out_code: u8 = undefined; | 63 | var out_code: u8 = undefined; |
| 49 | const untrimmed = b.execAllowFail( | 64 | const untrimmed = b.execAllowFail( |
| 50 | &.{ "git", "-C", b.build_root, "describe", "--tags" }, | 65 | &.{ "git", "-C", b.build_root.path.?, "describe", "--tags" }, |
| 51 | &out_code, | 66 | &out_code, |
| 52 | .Ignore, | 67 | .Ignore, |
| 53 | ) catch return default_version; | 68 | ) catch return default_version; |
| 54 | 69 | ||
| 55 | const git_desc = std.mem.trim(u8, untrimmed, &std.ascii.spaces); | 70 | const git_desc = std.mem.trim(u8, untrimmed, &std.ascii.whitespace); |
| 56 | // Turn something like 0.0.1-1-g85f815d into 0.0.1-1+g85f815d | 71 | // Turn something like 0.0.1-1-g85f815d into 0.0.1-1+g85f815d |
| 57 | const ver_str = switch (std.mem.count(u8, git_desc, "-")) { | 72 | const ver_str = switch (std.mem.count(u8, git_desc, "-")) { |
| 58 | 0 => git_desc, | 73 | 0 => git_desc, |
diff --git a/libs/clap b/libs/clap | |||
| Subproject dbc6b8e54ad753b0605feaeecc8e79dba3572ed | Subproject ab69ef2db44b6c4b7f00283d52d38fbe71d16c4 | ||
diff --git a/src/Installation.zig b/src/Installation.zig index 4f7a48d..3ff65ea 100644 --- a/src/Installation.zig +++ b/src/Installation.zig | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | const curl = @import("curl"); | 1 | const curl = @import("curl"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | const xdg = @import("xdg"); | 3 | const xdg = @import("xdg"); |
| 4 | const zup = @import("zup"); | 4 | const zup = @import("root"); |
| 5 | 5 | ||
| 6 | const Allocator = std.mem.Allocator; | 6 | const Allocator = std.mem.Allocator; |
| 7 | const Config = zup.Config; | 7 | const Config = zup.Config; |
| @@ -109,7 +109,7 @@ pub fn getInstalledList(allocator: Allocator) !Installations { | |||
| 109 | continue; | 109 | continue; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | const trimmed_ver_str = std.mem.trim(u8, res.stdout, &std.ascii.spaces); | 112 | const trimmed_ver_str = std.mem.trim(u8, res.stdout, &std.ascii.whitespace); |
| 113 | const version = try SemanticVersion.parse(trimmed_ver_str); | 113 | const version = try SemanticVersion.parse(trimmed_ver_str); |
| 114 | const name = try allocator.dupe(u8, item.name); | 114 | const name = try allocator.dupe(u8, item.name); |
| 115 | 115 | ||
diff --git a/src/install.zig b/src/install.zig index 27db4bb..2e3efab 100644 --- a/src/install.zig +++ b/src/install.zig | |||
| @@ -2,7 +2,7 @@ const libarchive = @import("libarchive"); | |||
| 2 | const curl = @import("curl"); | 2 | const curl = @import("curl"); |
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const xdg = @import("xdg"); | 4 | const xdg = @import("xdg"); |
| 5 | const zup = @import("zup"); | 5 | const zup = @import("root"); |
| 6 | 6 | ||
| 7 | const Allocator = std.mem.Allocator; | 7 | const Allocator = std.mem.Allocator; |
| 8 | const Config = zup.Config; | 8 | const Config = zup.Config; |
| @@ -24,7 +24,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { | |||
| 24 | var available = try Installation.getAvailableList(config); | 24 | var available = try Installation.getAvailableList(config); |
| 25 | defer Installation.deinitMap(allocator, &available); | 25 | defer Installation.deinitMap(allocator, &available); |
| 26 | 26 | ||
| 27 | return perform(allocator, res.positionals[0], res.args.force, available); | 27 | return perform(allocator, res.positionals[0], res.args.force != 0, available); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: Installations) !void { | 30 | pub fn perform(allocator: Allocator, name: []const u8, force: bool, available: Installations) !void { |
diff --git a/src/list.zig b/src/list.zig index bf95c2c..0a0fee9 100644 --- a/src/list.zig +++ b/src/list.zig | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const zup = @import("zup"); | 2 | const zup = @import("root"); |
| 3 | 3 | ||
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | const ArrayList = std.ArrayList; | 5 | const ArrayList = std.ArrayList; |
| @@ -20,11 +20,11 @@ pub const max_args = 0; | |||
| 20 | pub fn main(comptime Result: type, config: Config, res: Result) !void { | 20 | pub fn main(comptime Result: type, config: Config, res: Result) !void { |
| 21 | const allocator = config.allocator; | 21 | const allocator = config.allocator; |
| 22 | 22 | ||
| 23 | var list_active = res.args.active; | 23 | var list_active = res.args.active != 0; |
| 24 | var list_available = res.args.available; | 24 | var list_available = res.args.available != 0; |
| 25 | var list_installed = res.args.installed; | 25 | var list_installed = res.args.installed != 0; |
| 26 | 26 | ||
| 27 | if (res.args.all) { | 27 | if (res.args.all != 0) { |
| 28 | list_active = true; | 28 | list_active = true; |
| 29 | list_available = true; | 29 | list_available = true; |
| 30 | list_installed = true; | 30 | list_installed = true; |
| @@ -36,8 +36,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { | |||
| 36 | if (list_active) { | 36 | if (list_active) { |
| 37 | const active = try Installation.getActiveName(allocator); | 37 | const active = try Installation.getActiveName(allocator); |
| 38 | defer if (active) |s| allocator.free(s); | 38 | defer if (active) |s| allocator.free(s); |
| 39 | // TODO: zig-bug should I really need to do this? | 39 | try printActive(active); |
| 40 | try printActive(if (active) |a| a else null); | ||
| 41 | } | 40 | } |
| 42 | 41 | ||
| 43 | if (list_installed) { | 42 | if (list_installed) { |
diff --git a/src/main.zig b/src/main.zig index 197a224..93356d6 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -73,25 +73,19 @@ fn dispatch( | |||
| 73 | comptime default_fn: anytype, | 73 | comptime default_fn: anytype, |
| 74 | args: anytype, | 74 | args: anytype, |
| 75 | ) !void { | 75 | ) !void { |
| 76 | // TODO: This can still be improved, currently we're looping through all possible values, it could be somehow made | 76 | // TODO: This can still be improved, currently we're looping through all |
| 77 | // into a switch. | 77 | // possible values, it could be somehow made into a switch. |
| 78 | const cmd_enum = CommandMap.get(cmd) orelse return @call(.{}, default_fn, args); | 78 | const cmd_enum = CommandMap.get(cmd) orelse return @call(.auto, default_fn, args); |
| 79 | const commands = @typeInfo(Command).Enum.fields; | 79 | const commands = @typeInfo(Command).Enum.fields; |
| 80 | inline for (commands) |command| { | 80 | inline for (commands) |command| { |
| 81 | if (@enumToInt(cmd_enum) == command.value) { | 81 | if (@enumToInt(cmd_enum) == command.value) { |
| 82 | // TODO: zig-bug it cries about modifying a constant if | ||
| 83 | // I just write `return @call(.{}, fun, args);` | ||
| 84 | const fun = @field(@field(@This(), command.name), fn_name); | 82 | const fun = @field(@field(@This(), command.name), fn_name); |
| 85 | return call(fun, args); | 83 | return @call(.auto, fun, args); |
| 86 | } | 84 | } |
| 87 | } | 85 | } |
| 88 | unreachable; | 86 | unreachable; |
| 89 | } | 87 | } |
| 90 | 88 | ||
| 91 | inline fn call(fun: anytype, args: anytype) !void { | ||
| 92 | return @call(.{}, fun, args); | ||
| 93 | } | ||
| 94 | |||
| 95 | fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { | 89 | fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { |
| 96 | std.log.err("Unknown subcommand: {s}", .{cmd}); | 90 | std.log.err("Unknown subcommand: {s}", .{cmd}); |
| 97 | return error.ArgError; | 91 | return error.ArgError; |
diff --git a/src/remove.zig b/src/remove.zig index f795df7..2d868fb 100644 --- a/src/remove.zig +++ b/src/remove.zig | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const xdg = @import("xdg"); | 2 | const xdg = @import("xdg"); |
| 3 | const zup = @import("zup"); | 3 | const zup = @import("root"); |
| 4 | 4 | ||
| 5 | const Config = zup.Config; | 5 | const Config = zup.Config; |
| 6 | const Installation = zup.Installation; | 6 | const Installation = zup.Installation; |
| @@ -25,7 +25,7 @@ pub fn main(comptime Result: type, config: Config, res: Result) !void { | |||
| 25 | 25 | ||
| 26 | const is_active = try Installation.isActive(allocator, name); | 26 | const is_active = try Installation.isActive(allocator, name); |
| 27 | 27 | ||
| 28 | if (is_active and !res.args.force) { | 28 | if (is_active and res.args.force == 0) { |
| 29 | std.log.err("{s} is the active installation, not removing without --force!", .{name}); | 29 | std.log.err("{s} is the active installation, not removing without --force!", .{name}); |
| 30 | return error.CantRemove; | 30 | return error.CantRemove; |
| 31 | } | 31 | } |
diff --git a/src/subcommand.zig b/src/subcommand.zig index d750e94..09f1b4f 100644 --- a/src/subcommand.zig +++ b/src/subcommand.zig | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | const clap = @import("clap"); | 1 | const clap = @import("clap"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | const zup = @import("zup"); | 3 | const zup = @import("root"); |
| 4 | 4 | ||
| 5 | const ArgIterator = std.process.ArgIterator; | 5 | const ArgIterator = std.process.ArgIterator; |
| 6 | const Config = zup.Config; | 6 | const Config = zup.Config; |
| @@ -49,11 +49,11 @@ pub fn SubCommand(comptime template: type) type { | |||
| 49 | }; | 49 | }; |
| 50 | defer res.deinit(); | 50 | defer res.deinit(); |
| 51 | 51 | ||
| 52 | if (res.args.help) { | 52 | if (res.args.help != 0) { |
| 53 | return help(name); | 53 | return help(name); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | if (res.args.version) { | 56 | if (res.args.version != 0) { |
| 57 | return zup.printVersion(); | 57 | return zup.printVersion(); |
| 58 | } | 58 | } |
| 59 | 59 | ||
diff --git a/src/switch.zig b/src/switch.zig index e5d243f..f90f7d7 100644 --- a/src/switch.zig +++ b/src/switch.zig | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const xdg = @import("xdg"); | 2 | const xdg = @import("xdg"); |
| 3 | const zup = @import("zup"); | 3 | const zup = @import("root"); |
| 4 | 4 | ||
| 5 | const Config = zup.Config; | 5 | const Config = zup.Config; |
| 6 | const Installation = zup.Installation; | 6 | const Installation = zup.Installation; |
diff --git a/src/update.zig b/src/update.zig index 3451d90..55e6847 100644 --- a/src/update.zig +++ b/src/update.zig | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const zup = @import("zup"); | 2 | const zup = @import("root"); |
| 3 | 3 | ||
| 4 | const Config = zup.Config; | 4 | const Config = zup.Config; |
| 5 | const Installation = zup.Installation; | 5 | const Installation = zup.Installation; |