mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 22:13:11 -05:00
build: restore compatibility support
Commit 0d56ba3 (build: restore the exercise chain) broke the compatibility support for old compilers, due to the use of the multi-object for loop syntax. Use the normal for loop syntax; the change still keep the code readable. Use the variable `n`, instead of `i`, when referring to the exercise number; this will improve the readability. Closes #227
This commit is contained in:
parent
647a24afae
commit
be782af7a3
1 changed files with 11 additions and 8 deletions
19
build.zig
19
build.zig
|
@ -559,13 +559,13 @@ pub fn build(b: *Build) !void {
|
||||||
|
|
||||||
const header_step = PrintStep.create(b, logo, std.io.getStdErr());
|
const header_step = PrintStep.create(b, logo, std.io.getStdErr());
|
||||||
|
|
||||||
if (exno) |i| {
|
if (exno) |n| {
|
||||||
if (i == 0 or i > exercises.len - 1) {
|
if (n == 0 or n > exercises.len - 1) {
|
||||||
print("unknown exercise number: {}\n", .{i});
|
print("unknown exercise number: {}\n", .{n});
|
||||||
std.os.exit(1);
|
std.os.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ex = exercises[i - 1];
|
const ex = exercises[n - 1];
|
||||||
const base_name = ex.baseName();
|
const base_name = ex.baseName();
|
||||||
const file_path = std.fs.path.join(b.allocator, &[_][]const u8{
|
const file_path = std.fs.path.join(b.allocator, &[_][]const u8{
|
||||||
if (use_healed) "patches/healed" else "exercises", ex.main_file,
|
if (use_healed) "patches/healed" else "exercises", ex.main_file,
|
||||||
|
@ -603,8 +603,8 @@ pub fn build(b: *Build) !void {
|
||||||
|
|
||||||
var prev_step = verify_step;
|
var prev_step = verify_step;
|
||||||
for (exercises) |exn| {
|
for (exercises) |exn| {
|
||||||
const n = exn.number();
|
const nth = exn.number();
|
||||||
if (n > i) {
|
if (nth > n) {
|
||||||
const verify_stepn = ZiglingStep.create(b, exn, use_healed);
|
const verify_stepn = ZiglingStep.create(b, exn, use_healed);
|
||||||
verify_stepn.step.dependOn(&prev_step.step);
|
verify_stepn.step.dependOn(&prev_step.step);
|
||||||
|
|
||||||
|
@ -646,8 +646,11 @@ pub fn build(b: *Build) !void {
|
||||||
ziglings_step.dependOn(&header_step.step);
|
ziglings_step.dependOn(&header_step.step);
|
||||||
b.default_step = ziglings_step;
|
b.default_step = ziglings_step;
|
||||||
|
|
||||||
|
// Don't use the "multi-object for loop" syntax, in order to avoid a syntax
|
||||||
|
// error with old Zig compilers.
|
||||||
var prev_step: *Step = undefined;
|
var prev_step: *Step = undefined;
|
||||||
for (exercises, 0..) |ex, i| {
|
for (exercises) |ex| {
|
||||||
|
const n = ex.number();
|
||||||
const base_name = ex.baseName();
|
const base_name = ex.baseName();
|
||||||
const file_path = std.fs.path.join(b.allocator, &[_][]const u8{
|
const file_path = std.fs.path.join(b.allocator, &[_][]const u8{
|
||||||
"exercises", ex.main_file,
|
"exercises", ex.main_file,
|
||||||
|
@ -657,7 +660,7 @@ pub fn build(b: *Build) !void {
|
||||||
build_step.install();
|
build_step.install();
|
||||||
|
|
||||||
const verify_stepn = ZiglingStep.create(b, ex, use_healed);
|
const verify_stepn = ZiglingStep.create(b, ex, use_healed);
|
||||||
if (i == 0) {
|
if (n == 1) {
|
||||||
prev_step = &verify_stepn.step;
|
prev_step = &verify_stepn.step;
|
||||||
} else {
|
} else {
|
||||||
verify_stepn.step.dependOn(prev_step);
|
verify_stepn.step.dependOn(prev_step);
|
||||||
|
|
Loading…
Reference in a new issue