From 4563f6b4242957971d619aa23263938fdcb442d3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Feb 2019 18:10:40 -0500 Subject: [PATCH] add builder.addFmt API and use it to test stage1 zig fmt closes #1968 --- CMakeLists.txt | 1 + build.zig | 7 +++++++ std/build.zig | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab69a0d081..830a3456cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -448,6 +448,7 @@ set(ZIG_STD_FILES "buf_set.zig" "buffer.zig" "build.zig" + "build/fmt.zig" "c/darwin.zig" "c/freebsd.zig" "c/index.zig" diff --git a/build.zig b/build.zig index 71bbfd0b23..756ec53708 100644 --- a/build.zig +++ b/build.zig @@ -55,6 +55,8 @@ pub fn build(b: *Builder) !void { var test_stage2 = b.addTest("src-self-hosted/test.zig"); test_stage2.setBuildMode(builtin.Mode.Debug); + const fmt_build_zig = b.addFmt([][]const u8{"build.zig"}); + var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); exe.setBuildMode(mode); @@ -106,6 +108,11 @@ pub fn build(b: *Builder) !void { } const modes = chosen_modes[0..chosen_mode_index]; + // run stage1 `zig fmt` on this build.zig file just to make sure it works + test_step.dependOn(&fmt_build_zig.step); + const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works"); + fmt_step.dependOn(&fmt_build_zig.step); + test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes)); test_step.dependOn(tests.addPkgTests(b, test_filter, "std/index.zig", "std", "Run the standard library tests", modes)); diff --git a/std/build.zig b/std/build.zig index e90d827602..e3fdfbccee 100644 --- a/std/build.zig +++ b/std/build.zig @@ -15,6 +15,8 @@ const BufSet = std.BufSet; const BufMap = std.BufMap; const fmt_lib = std.fmt; +pub const FmtStep = @import("build/fmt.zig").FmtStep; + pub const Builder = struct { uninstall_tls: TopLevelStep, install_tls: TopLevelStep, @@ -205,6 +207,10 @@ pub const Builder = struct { return remove_dir_step; } + pub fn addFmt(self: *Builder, paths: []const []const u8) *FmtStep { + return FmtStep.create(self, paths); + } + pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) Version { return Version{ .major = major,