Skip to content

Commit

Permalink
finish implementing "default master"
Browse files Browse the repository at this point in the history
  • Loading branch information
marler8997 committed Jan 6, 2022
1 parent 3af4e46 commit b4b7d2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub fn main() !void {
defer allocator_store.deinit();
const allocator = allocator_store.allocator();

{
const result = try runCaptureOuts(allocator, ".", zigup_args ++ &[_][]const u8 {"default", "master"});
defer { allocator.free(result.stdout); allocator.free(result.stderr); }
try testing.expect(std.mem.containsAtLeast(u8, result.stderr, 1, "master has not been fetched"));
}
{
const result = try runCaptureOuts(allocator, ".", zigup_args ++ &[_][]const u8 {"-h"});
defer { allocator.free(result.stdout); allocator.free(result.stderr); }
Expand Down
24 changes: 21 additions & 3 deletions zigup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,27 @@ pub fn main2() !u8 {
}
if (args.len == 2) {
const version_string = args[1];
const install_dir = try getInstallDir(allocator, .{ .create = true });
defer allocator.free(install_dir);
const compiler_dir = try std.fs.path.join(allocator, &[_][]const u8{ install_dir, version_string });
const install_dir_string = try getInstallDir(allocator, .{ .create = true });
defer allocator.free(install_dir_string);
const resolved_version_string = init_resolved: {
if (!std.mem.eql(u8, version_string, "master"))
break :init_resolved version_string;

var optional_master_dir: ?[]const u8 = blk: {
var install_dir = std.fs.openDirAbsolute(install_dir_string, .{ .iterate = true }) catch |e| switch (e) {
error.FileNotFound => break :blk null,
else => return e,
};
defer install_dir.close();
break :blk try getMasterDir(allocator, &install_dir);
};
// no need to free master_dir, this is a short lived program
break :init_resolved optional_master_dir orelse {
std.debug.print("Error: master has not been fetched\n", .{});
return 1;
};
};
const compiler_dir = try std.fs.path.join(allocator, &[_][]const u8{ install_dir_string, resolved_version_string });
defer allocator.free(compiler_dir);
try setDefaultCompiler(allocator, compiler_dir, .verify_existence);
return 0;
Expand Down

0 comments on commit b4b7d2a

Please sign in to comment.