Skip to content

Commit 6bb1293

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

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

zigup.zig

Lines changed: 18 additions & 11 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

@@ -626,8 +631,9 @@ fn printDefaultCompiler(allocator: Allocator) !void {
626631
const default_compiler_opt = try getDefaultCompiler(allocator);
627632
defer if (default_compiler_opt) |default_compiler| allocator.free(default_compiler);
628633
const stdout = std.io.getStdOut().writer();
634+
var found_master = false;
629635
if (default_compiler_opt) |default_compiler| {
630-
if (mem.eql(u8, default_compiler, "master")) {
636+
if (!found_master) {
631637
const install_dir_string = try getInstallDir(allocator, .{ .create = false });
632638
defer allocator.free(install_dir_string);
633639

@@ -641,12 +647,13 @@ fn printDefaultCompiler(allocator: Allocator) !void {
641647
defer if (master_dir) |master| allocator.free(master);
642648

643649
if (master_dir) |master| {
644-
try stdout.print("master -> {s}\n", .{master});
650+
if (mem.eql(u8, master, default_compiler)) {
651+
try stdout.print("master -> ", .{});
652+
found_master = true;
653+
}
645654
}
646655
}
647-
else {
648-
try stdout.print("{s}\n", .{default_compiler});
649-
}
656+
try stdout.print("{s}\n", .{default_compiler});
650657
} else {
651658
try stdout.writeAll("<no-default>\n");
652659
}

0 commit comments

Comments
 (0)