Skip to content

Commit 8ed3112

Browse files
committed
Fixed master path detection and added error for default compiler not
installed
1 parent a4f6cdf commit 8ed3112

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

zigup.zig

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ fn listCompilers(allocator: Allocator) !void {
464464
const master_dir = try getMasterDir(allocator, &install_dir);
465465
defer if (master_dir) |master| allocator.free(master);
466466

467+
var found_default = false;
468+
467469
const stdout = std.io.getStdOut().writer();
468470
{
469471
var it = install_dir.iterate();
@@ -475,22 +477,25 @@ fn listCompilers(allocator: Allocator) !void {
475477

476478
try stdout.print("{s}", .{entry.name});
477479

478-
const is_master = if (master_dir) |master|
479-
(if (mem.eql(u8, master, entry.name)) true else false)
480-
else false;
481-
482-
if (is_master) {
480+
if (master_dir != null and mem.eql(u8, master_dir.?, entry.name)) {
483481
try stdout.writeAll(" -> master");
484482
}
485483

486484
if (default_compiler) |default| {
487-
if (mem.eql(u8, default, entry.name) or (is_master and mem.eql(u8, default, "master"))) {
485+
if (mem.eql(u8, default, entry.name)) {
488486
try stdout.writeAll(" (default)");
487+
found_default = true;
489488
}
490489
}
491490

492491
try stdout.writeByte('\n');
493492
}
493+
494+
if (default_compiler) |default| {
495+
if (!found_default) {
496+
std.log.err("default compiler '{s}' is not among the installed compilers", .{default});
497+
}
498+
}
494499
}
495500
}
496501

@@ -627,26 +632,24 @@ fn printDefaultCompiler(allocator: Allocator) !void {
627632
defer if (default_compiler_opt) |default_compiler| allocator.free(default_compiler);
628633
const stdout = std.io.getStdOut().writer();
629634
if (default_compiler_opt) |default_compiler| {
630-
if (mem.eql(u8, default_compiler, "master")) {
631-
const install_dir_string = try getInstallDir(allocator, .{ .create = false });
632-
defer allocator.free(install_dir_string);
635+
const install_dir_string = try getInstallDir(allocator, .{ .create = false });
636+
defer allocator.free(install_dir_string);
633637

634-
var install_dir = std.fs.openDirAbsolute(install_dir_string, .{ .iterate = true }) catch |e| switch (e) {
635-
error.FileNotFound => return,
636-
else => return e,
637-
};
638-
defer install_dir.close();
638+
var install_dir = std.fs.openDirAbsolute(install_dir_string, .{ .iterate = true }) catch |e| switch (e) {
639+
error.FileNotFound => return,
640+
else => return e,
641+
};
642+
defer install_dir.close();
639643

640-
const master_dir = try getMasterDir(allocator, &install_dir);
641-
defer if (master_dir) |master| allocator.free(master);
644+
const master_dir = try getMasterDir(allocator, &install_dir);
645+
defer if (master_dir) |master| allocator.free(master);
642646

643-
if (master_dir) |master| {
644-
try stdout.print("master -> {s}\n", .{master});
647+
if (master_dir) |master| {
648+
if (mem.eql(u8, master, default_compiler)) {
649+
try stdout.print("master -> ", .{});
645650
}
646651
}
647-
else {
648-
try stdout.print("{s}\n", .{default_compiler});
649-
}
652+
try stdout.print("{s}\n", .{default_compiler});
650653
} else {
651654
try stdout.writeAll("<no-default>\n");
652655
}

0 commit comments

Comments
 (0)