2017-04-19 18:00:12 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const debug = std.debug;
|
2017-10-31 08:47:55 +00:00
|
|
|
const warn = debug.warn;
|
2017-04-19 18:00:12 +00:00
|
|
|
const build = std.build;
|
2019-08-20 18:40:57 +00:00
|
|
|
pub const Target = build.Target;
|
|
|
|
pub const CrossTarget = build.CrossTarget;
|
2017-05-04 18:05:06 +00:00
|
|
|
const Buffer = std.Buffer;
|
2017-04-19 18:00:12 +00:00
|
|
|
const io = std.io;
|
2019-05-26 17:17:34 +00:00
|
|
|
const fs = std.fs;
|
2017-04-19 18:00:12 +00:00
|
|
|
const mem = std.mem;
|
|
|
|
const fmt = std.fmt;
|
2017-05-04 18:05:06 +00:00
|
|
|
const ArrayList = std.ArrayList;
|
2017-08-30 18:55:26 +00:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
const Mode = builtin.Mode;
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const LibExeObjStep = build.LibExeObjStep;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 20:59:20 +00:00
|
|
|
const compare_output = @import("compare_output.zig");
|
2019-07-16 16:15:46 +00:00
|
|
|
const standalone = @import("standalone.zig");
|
2019-09-03 14:08:39 +00:00
|
|
|
const stack_traces = @import("stack_traces.zig");
|
2017-04-19 20:59:20 +00:00
|
|
|
const compile_errors = @import("compile_errors.zig");
|
|
|
|
const assemble_and_link = @import("assemble_and_link.zig");
|
2018-01-25 06:46:12 +00:00
|
|
|
const runtime_safety = @import("runtime_safety.zig");
|
2017-11-24 19:56:05 +00:00
|
|
|
const translate_c = @import("translate_c.zig");
|
2018-01-23 03:24:07 +00:00
|
|
|
const gen_h = @import("gen_h.zig");
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
const TestTarget = struct {
|
|
|
|
target: Target = .Native,
|
|
|
|
mode: builtin.Mode = .Debug,
|
|
|
|
link_libc: bool = false,
|
|
|
|
single_threaded: bool = false,
|
2019-09-22 18:40:54 +00:00
|
|
|
disable_native: bool = false,
|
2019-09-22 03:55:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const test_targets = [_]TestTarget{
|
|
|
|
TestTarget{},
|
|
|
|
TestTarget{
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
|
|
|
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .x86_64,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .x86_64,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .x86_64,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
2017-08-31 15:41:58 +00:00
|
|
|
},
|
2019-09-22 03:55:56 +00:00
|
|
|
|
2019-11-30 15:13:33 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .i386,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .i386,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
|
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-25 19:57:13 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
|
|
|
|
.abi = .musleabihf,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-09-22 03:55:56 +00:00
|
|
|
// TODO https://github.com/ziglang/zig/issues/3287
|
|
|
|
//TestTarget{
|
|
|
|
// .target = Target{
|
|
|
|
// .Cross = CrossTarget{
|
|
|
|
// .os = .linux,
|
|
|
|
// .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },
|
|
|
|
// .abi = .gnueabihf,
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// .link_libc = true,
|
|
|
|
//},
|
|
|
|
|
2019-09-21 21:00:36 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .mipsel,
|
|
|
|
.abi = .none,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-27 16:20:17 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .linux,
|
|
|
|
.arch = .mipsel,
|
|
|
|
.abi = .musl,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-09-21 21:00:36 +00:00
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .macosx,
|
|
|
|
.arch = .x86_64,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
},
|
2019-09-22 18:40:54 +00:00
|
|
|
// TODO https://github.com/ziglang/zig/issues/3295
|
|
|
|
.disable_native = true,
|
2019-09-22 03:55:56 +00:00
|
|
|
},
|
|
|
|
|
2019-10-11 17:13:59 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .windows,
|
|
|
|
.arch = .i386,
|
|
|
|
.abi = .msvc,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .windows,
|
|
|
|
.arch = .x86_64,
|
|
|
|
.abi = .msvc,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-10-09 20:49:33 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .windows,
|
|
|
|
.arch = .i386,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
|
|
|
|
2019-09-22 23:11:41 +00:00
|
|
|
TestTarget{
|
|
|
|
.target = Target{
|
|
|
|
.Cross = CrossTarget{
|
|
|
|
.os = .windows,
|
|
|
|
.arch = .x86_64,
|
|
|
|
.abi = .gnu,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.link_libc = true,
|
|
|
|
},
|
2019-09-22 18:41:47 +00:00
|
|
|
|
|
|
|
// Do the release tests last because they take a long time
|
|
|
|
TestTarget{
|
|
|
|
.mode = .ReleaseFast,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.link_libc = true,
|
|
|
|
.mode = .ReleaseFast,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.mode = .ReleaseFast,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
|
|
|
|
|
|
|
TestTarget{
|
|
|
|
.mode = .ReleaseSafe,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.link_libc = true,
|
|
|
|
.mode = .ReleaseSafe,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.mode = .ReleaseSafe,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
|
|
|
|
|
|
|
TestTarget{
|
|
|
|
.mode = .ReleaseSmall,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.link_libc = true,
|
|
|
|
.mode = .ReleaseSmall,
|
|
|
|
},
|
|
|
|
TestTarget{
|
|
|
|
.mode = .ReleaseSmall,
|
|
|
|
.single_threaded = true,
|
|
|
|
},
|
2017-08-30 18:55:26 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 08:47:55 +00:00
|
|
|
const max_stdout_size = 1 * 1024 * 1024; // 1 MB
|
|
|
|
|
2018-07-11 23:38:01 +00:00
|
|
|
pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 18:00:12 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-compare-output", "Run the compare output tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-11 23:38:01 +00:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
compare_output.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2019-09-03 14:08:39 +00:00
|
|
|
pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
|
|
|
const cases = b.allocator.create(StackTracesContext) catch unreachable;
|
|
|
|
cases.* = StackTracesContext{
|
2019-05-28 00:07:05 +00:00
|
|
|
.b = b,
|
2019-09-03 14:08:39 +00:00
|
|
|
.step = b.step("test-stack-traces", "Run the stack trace tests"),
|
2019-05-28 00:07:05 +00:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
.modes = modes,
|
|
|
|
};
|
|
|
|
|
2019-09-03 14:08:39 +00:00
|
|
|
stack_traces.addCases(cases);
|
2019-05-28 00:07:05 +00:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-07-11 23:38:01 +00:00
|
|
|
pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 18:41:59 +00:00
|
|
|
.b = b,
|
2018-01-25 06:46:12 +00:00
|
|
|
.step = b.step("test-runtime-safety", "Run the runtime safety tests"),
|
2017-04-19 18:41:59 +00:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-11 23:38:01 +00:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:41:59 +00:00
|
|
|
|
2018-01-25 06:46:12 +00:00
|
|
|
runtime_safety.addCases(cases);
|
2017-04-19 18:41:59 +00:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-07-11 23:38:01 +00:00
|
|
|
pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(CompileErrorContext) catch unreachable;
|
|
|
|
cases.* = CompileErrorContext{
|
2017-04-19 18:00:12 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-compile-errors", "Run the compile error tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-11 23:38:01 +00:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
compile_errors.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
|
|
|
const cases = b.allocator.create(StandaloneContext) catch unreachable;
|
|
|
|
cases.* = StandaloneContext{
|
2017-04-19 18:00:12 +00:00
|
|
|
.b = b,
|
2019-07-16 16:15:46 +00:00
|
|
|
.step = b.step("test-standalone", "Run the standalone tests"),
|
2017-04-19 18:00:12 +00:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-18 08:28:14 +00:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
standalone.addCases(cases);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-09-17 21:08:56 +00:00
|
|
|
pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
|
|
|
const step = b.step("test-cli", "Test the command line interface");
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test-cli", "test/cli.zig");
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const run_cmd = exe.run();
|
2019-11-27 08:30:39 +00:00
|
|
|
run_cmd.addArgs(&[_][]const u8{
|
2019-05-26 17:37:34 +00:00
|
|
|
fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
|
2018-09-17 21:08:56 +00:00
|
|
|
b.pathFromRoot(b.cache_root),
|
|
|
|
});
|
|
|
|
|
|
|
|
step.dependOn(&run_cmd.step);
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2018-07-11 23:38:01 +00:00
|
|
|
pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
|
|
|
cases.* = CompareOutputContext{
|
2017-04-19 18:00:12 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-asm-link", "Run the assemble and link tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2018-07-11 23:38:01 +00:00
|
|
|
.modes = modes,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
assemble_and_link.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(TranslateCContext) catch unreachable;
|
|
|
|
cases.* = TranslateCContext{
|
2017-04-19 20:59:20 +00:00
|
|
|
.b = b,
|
2018-01-23 03:24:07 +00:00
|
|
|
.step = b.step("test-translate-c", "Run the C transation tests"),
|
2017-04-19 20:59:20 +00:00
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2017-11-24 19:56:05 +00:00
|
|
|
translate_c.addCases(cases);
|
2017-04-19 20:59:20 +00:00
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step {
|
2019-02-03 21:13:28 +00:00
|
|
|
const cases = b.allocator.create(GenHContext) catch unreachable;
|
|
|
|
cases.* = GenHContext{
|
2018-01-23 03:24:07 +00:00
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-gen-h", "Run the C header file generation tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-01-23 03:24:07 +00:00
|
|
|
|
|
|
|
gen_h.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2019-05-15 01:21:59 +00:00
|
|
|
pub fn addPkgTests(
|
|
|
|
b: *build.Builder,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
root_src: []const u8,
|
|
|
|
name: []const u8,
|
|
|
|
desc: []const u8,
|
|
|
|
modes: []const Mode,
|
2019-09-22 03:55:56 +00:00
|
|
|
skip_single_threaded: bool,
|
2019-05-15 01:21:59 +00:00
|
|
|
skip_non_native: bool,
|
2019-09-22 03:55:56 +00:00
|
|
|
skip_libc: bool,
|
|
|
|
is_wine_enabled: bool,
|
|
|
|
is_qemu_enabled: bool,
|
|
|
|
glibc_dir: ?[]const u8,
|
2019-05-15 01:21:59 +00:00
|
|
|
) *build.Step {
|
2019-12-09 03:53:51 +00:00
|
|
|
const step = b.step(b.fmt("test-{}", .{name}), desc);
|
2019-09-09 21:57:32 +00:00
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
for (test_targets) |test_target| {
|
|
|
|
if (skip_non_native and test_target.target != .Native)
|
|
|
|
continue;
|
2019-09-09 21:57:32 +00:00
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
if (skip_libc and test_target.link_libc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (test_target.link_libc and test_target.target.osRequiresLibC()) {
|
|
|
|
// This would be a redundant test.
|
2019-05-15 01:21:59 +00:00
|
|
|
continue;
|
2017-04-20 06:26:36 +00:00
|
|
|
}
|
2019-09-22 03:55:56 +00:00
|
|
|
|
|
|
|
if (skip_single_threaded and test_target.single_threaded)
|
|
|
|
continue;
|
|
|
|
|
2019-09-22 18:40:54 +00:00
|
|
|
const ArchTag = @TagType(builtin.Arch);
|
|
|
|
if (test_target.disable_native and
|
|
|
|
test_target.target.getOs() == builtin.os and
|
2019-11-27 08:30:39 +00:00
|
|
|
@as(ArchTag, test_target.target.getArch()) == @as(ArchTag, builtin.arch))
|
2019-09-22 18:40:54 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-09-22 03:55:56 +00:00
|
|
|
const want_this_mode = for (modes) |m| {
|
|
|
|
if (m == test_target.mode) break true;
|
|
|
|
} else false;
|
|
|
|
if (!want_this_mode) continue;
|
|
|
|
|
|
|
|
const libc_prefix = if (test_target.target.osRequiresLibC())
|
|
|
|
""
|
|
|
|
else if (test_target.link_libc)
|
|
|
|
"c"
|
|
|
|
else
|
|
|
|
"bare";
|
|
|
|
|
|
|
|
const triple_prefix = if (test_target.target == .Native)
|
2019-11-27 08:30:39 +00:00
|
|
|
@as([]const u8, "native")
|
2019-09-22 03:55:56 +00:00
|
|
|
else
|
|
|
|
test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
|
|
|
|
|
|
|
|
const these_tests = b.addTest(root_src);
|
2019-12-09 03:53:51 +00:00
|
|
|
const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
|
|
|
|
these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", .{
|
2019-09-22 03:55:56 +00:00
|
|
|
name,
|
|
|
|
triple_prefix,
|
|
|
|
@tagName(test_target.mode),
|
|
|
|
libc_prefix,
|
2019-12-09 03:53:51 +00:00
|
|
|
single_threaded_txt,
|
|
|
|
}));
|
2019-09-22 03:55:56 +00:00
|
|
|
these_tests.single_threaded = test_target.single_threaded;
|
|
|
|
these_tests.setFilter(test_filter);
|
|
|
|
these_tests.setBuildMode(test_target.mode);
|
|
|
|
these_tests.setTheTarget(test_target.target);
|
|
|
|
if (test_target.link_libc) {
|
|
|
|
these_tests.linkSystemLibrary("c");
|
|
|
|
}
|
2019-09-26 03:57:47 +00:00
|
|
|
these_tests.overrideZigLibDir("lib");
|
2019-09-22 03:55:56 +00:00
|
|
|
these_tests.enable_wine = is_wine_enabled;
|
|
|
|
these_tests.enable_qemu = is_qemu_enabled;
|
|
|
|
these_tests.glibc_multi_install_dir = glibc_dir;
|
|
|
|
|
|
|
|
step.dependOn(&these_tests.step);
|
2017-04-20 06:26:36 +00:00
|
|
|
}
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
pub const CompareOutputContext = struct {
|
2018-05-31 14:56:59 +00:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2017-04-19 18:00:12 +00:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
2018-07-11 23:38:01 +00:00
|
|
|
modes: []const Mode,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const Special = enum {
|
2017-04-19 18:41:59 +00:00
|
|
|
None,
|
|
|
|
Asm,
|
2018-01-25 06:46:12 +00:00
|
|
|
RuntimeSafety,
|
2017-04-19 18:41:59 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const TestCase = struct {
|
2017-04-19 18:00:12 +00:00
|
|
|
name: []const u8,
|
2017-05-04 18:05:06 +00:00
|
|
|
sources: ArrayList(SourceFile),
|
2017-04-19 18:00:12 +00:00
|
|
|
expected_output: []const u8,
|
|
|
|
link_libc: bool,
|
2017-04-19 18:41:59 +00:00
|
|
|
special: Special,
|
2017-12-06 23:12:05 +00:00
|
|
|
cli_args: []const []const u8,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const SourceFile = struct {
|
2017-04-19 18:00:12 +00:00
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
2018-11-13 13:08:37 +00:00
|
|
|
self.sources.append(SourceFile{
|
2017-04-19 18:00:12 +00:00
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
2018-01-09 05:07:01 +00:00
|
|
|
}) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
2017-12-06 23:12:05 +00:00
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn setCommandLineArgs(self: *TestCase, args: []const []const u8) void {
|
2017-12-06 23:12:05 +00:00
|
|
|
self.cli_args = args;
|
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const RunCompareOutputStep = struct {
|
2017-04-19 18:00:12 +00:00
|
|
|
step: build.Step,
|
2018-05-31 14:56:59 +00:00
|
|
|
context: *CompareOutputContext,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
exe: *LibExeObjStep,
|
2017-04-19 18:00:12 +00:00
|
|
|
name: []const u8,
|
|
|
|
expected_output: []const u8,
|
|
|
|
test_index: usize,
|
2017-12-06 23:12:05 +00:00
|
|
|
cli_args: []const []const u8,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
pub fn create(
|
|
|
|
context: *CompareOutputContext,
|
|
|
|
exe: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
expected_output: []const u8,
|
|
|
|
cli_args: []const []const u8,
|
|
|
|
) *RunCompareOutputStep {
|
2017-04-19 18:00:12 +00:00
|
|
|
const allocator = context.b.allocator;
|
2019-02-03 21:13:28 +00:00
|
|
|
const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
|
|
|
|
ptr.* = RunCompareOutputStep{
|
2017-04-19 18:00:12 +00:00
|
|
|
.context = context,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
.exe = exe,
|
2017-04-19 18:00:12 +00:00
|
|
|
.name = name,
|
|
|
|
.expected_output = expected_output,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.step = build.Step.init("RunCompareOutput", allocator, make),
|
2017-12-06 23:12:05 +00:00
|
|
|
.cli_args = cli_args,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
ptr.step.dependOn(&exe.step);
|
2017-04-19 18:00:12 +00:00
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
fn make(step: *build.Step) !void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const full_exe_path = self.exe.getOutputPath();
|
2017-12-06 23:12:05 +00:00
|
|
|
var args = ArrayList([]const u8).init(b.allocator);
|
|
|
|
defer args.deinit();
|
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
args.append(full_exe_path) catch unreachable;
|
2017-12-06 23:12:05 +00:00
|
|
|
for (self.cli_args) |arg| {
|
2018-01-09 05:07:01 +00:00
|
|
|
args.append(arg) catch unreachable;
|
2017-12-06 23:12:05 +00:00
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
|
2017-09-26 05:01:49 +00:00
|
|
|
defer child.deinit();
|
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Pipe;
|
|
|
|
child.stderr_behavior = .Pipe;
|
2018-10-15 22:23:47 +00:00
|
|
|
child.env_map = b.env_map;
|
2017-09-26 05:01:49 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-22 15:36:42 +00:00
|
|
|
var stdout = Buffer.initNull(b.allocator);
|
|
|
|
var stderr = Buffer.initNull(b.allocator);
|
|
|
|
|
2018-09-30 21:23:42 +00:00
|
|
|
var stdout_file_in_stream = child.stdout.?.inStream();
|
|
|
|
var stderr_file_in_stream = child.stderr.?.inStream();
|
2017-11-07 08:22:27 +00:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
|
|
|
|
stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
|
2017-04-22 15:36:42 +00:00
|
|
|
|
2018-01-07 22:28:20 +00:00
|
|
|
const term = child.wait() catch |err| {
|
2019-12-09 03:53:51 +00:00
|
|
|
debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
2017-04-19 18:00:12 +00:00
|
|
|
};
|
|
|
|
switch (term) {
|
2019-05-26 17:17:34 +00:00
|
|
|
.Exited => |code| {
|
2017-04-19 18:00:12 +00:00
|
|
|
if (code != 0) {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} exited with error code {}\n", .{ full_exe_path, code });
|
2019-03-15 21:47:47 +00:00
|
|
|
printInvocation(args.toSliceConst());
|
2017-04-19 18:00:12 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
else => {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} terminated unexpectedly\n", .{full_exe_path});
|
2019-03-15 21:47:47 +00:00
|
|
|
printInvocation(args.toSliceConst());
|
2017-04-19 18:00:12 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
2017-12-22 05:50:30 +00:00
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
|
2017-10-31 08:47:55 +00:00
|
|
|
warn(
|
2017-04-19 18:00:12 +00:00
|
|
|
\\
|
|
|
|
\\========= Expected this output: =========
|
|
|
|
\\{}
|
2019-05-25 11:43:52 +00:00
|
|
|
\\========= But found: ====================
|
2017-04-19 18:00:12 +00:00
|
|
|
\\{}
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{ self.expected_output, stdout.toSliceConst() });
|
2017-04-19 18:00:12 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("OK\n", .{});
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const RuntimeSafetyRunStep = struct {
|
2017-04-19 18:41:59 +00:00
|
|
|
step: build.Step,
|
2018-05-31 14:56:59 +00:00
|
|
|
context: *CompareOutputContext,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
exe: *LibExeObjStep,
|
2017-04-19 18:41:59 +00:00
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
pub fn create(context: *CompareOutputContext, exe: *LibExeObjStep, name: []const u8) *RuntimeSafetyRunStep {
|
2017-04-19 18:41:59 +00:00
|
|
|
const allocator = context.b.allocator;
|
2019-02-03 21:13:28 +00:00
|
|
|
const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
|
|
|
|
ptr.* = RuntimeSafetyRunStep{
|
2017-04-19 18:41:59 +00:00
|
|
|
.context = context,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
.exe = exe,
|
2017-04-19 18:41:59 +00:00
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
2018-01-25 06:46:12 +00:00
|
|
|
.step = build.Step.init("RuntimeSafetyRun", allocator, make),
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
ptr.step.dependOn(&exe.step);
|
2017-04-19 18:41:59 +00:00
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
fn make(step: *build.Step) !void {
|
2018-01-25 06:46:12 +00:00
|
|
|
const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
|
2017-04-19 18:41:59 +00:00
|
|
|
const b = self.context.b;
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const full_exe_path = self.exe.getOutputPath();
|
2017-04-19 18:41:59 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2017-04-19 18:41:59 +00:00
|
|
|
|
2019-11-27 08:30:39 +00:00
|
|
|
const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
|
2017-09-26 05:01:49 +00:00
|
|
|
defer child.deinit();
|
2017-04-19 18:41:59 +00:00
|
|
|
|
2018-10-15 22:23:47 +00:00
|
|
|
child.env_map = b.env_map;
|
2019-05-26 17:17:34 +00:00
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Ignore;
|
|
|
|
child.stderr_behavior = .Ignore;
|
2017-09-26 05:01:49 +00:00
|
|
|
|
2018-01-07 22:28:20 +00:00
|
|
|
const term = child.spawnAndWait() catch |err| {
|
2019-12-09 03:53:51 +00:00
|
|
|
debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
2017-04-19 18:41:59 +00:00
|
|
|
};
|
|
|
|
|
2019-05-27 03:35:26 +00:00
|
|
|
const expected_exit_code: u32 = 126;
|
2017-04-19 18:41:59 +00:00
|
|
|
switch (term) {
|
2019-05-26 17:17:34 +00:00
|
|
|
.Exited => |code| {
|
2017-10-16 04:20:51 +00:00
|
|
|
if (code != expected_exit_code) {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\nProgram expected to exit with code {} but exited with code {}\n", .{
|
|
|
|
expected_exit_code, code,
|
|
|
|
});
|
2017-04-19 18:41:59 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
2019-05-26 17:17:34 +00:00
|
|
|
.Signal => |sig| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\nProgram expected to exit with code {} but instead signaled {}\n", .{
|
|
|
|
expected_exit_code, sig,
|
|
|
|
});
|
2017-10-16 04:20:51 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
2017-04-19 18:41:59 +00:00
|
|
|
else => {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\nProgram expected to exit with code {} but exited in an unexpected way\n", .{
|
|
|
|
expected_exit_code,
|
|
|
|
});
|
2017-04-19 18:41:59 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("OK\n", .{});
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn createExtra(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8, special: Special) TestCase {
|
2018-11-13 13:08:37 +00:00
|
|
|
var tc = TestCase{
|
2017-04-19 18:00:12 +00:00
|
|
|
.name = name,
|
2017-05-04 18:05:06 +00:00
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
2017-04-19 18:00:12 +00:00
|
|
|
.expected_output = expected_output,
|
|
|
|
.link_libc = false,
|
2017-04-19 18:41:59 +00:00
|
|
|
.special = special,
|
2019-11-27 08:30:39 +00:00
|
|
|
.cli_args = &[_][]const u8{},
|
2017-04-19 18:00:12 +00:00
|
|
|
};
|
2017-04-19 18:41:59 +00:00
|
|
|
const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
|
2017-04-19 18:00:12 +00:00
|
|
|
tc.addSourceFile(root_src_name, source);
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn create(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) TestCase {
|
2017-04-19 18:41:59 +00:00
|
|
|
return createExtra(self, name, source, expected_output, Special.None);
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addC(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
var tc = self.create(name, source, expected_output);
|
|
|
|
tc.link_libc = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn add(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const tc = self.create(name, source, expected_output);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addAsm(self: *CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) void {
|
2017-04-19 18:41:59 +00:00
|
|
|
const tc = self.createExtra(name, source, expected_output, Special.Asm);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addRuntimeSafety(self: *CompareOutputContext, name: []const u8, source: []const u8) void {
|
2018-01-25 06:46:12 +00:00
|
|
|
const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
|
2017-04-19 18:00:12 +00:00
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-10-15 22:23:47 +00:00
|
|
|
pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const b = self.b;
|
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
const root_src = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, case.sources.items[0].filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
switch (case.special) {
|
|
|
|
Special.Asm => {
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", .{
|
|
|
|
case.name,
|
|
|
|
}) catch unreachable;
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-26 23:17:05 +00:00
|
|
|
const exe = b.addExecutable("test", null);
|
|
|
|
exe.addAssemblyFile(root_src);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2019-05-26 17:17:34 +00:00
|
|
|
const expanded_src_path = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, src_file.filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 18:41:59 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
2017-04-26 23:17:05 +00:00
|
|
|
exe.step.dependOn(&write_src.step);
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const run_and_cmp_output = RunCompareOutputStep.create(
|
|
|
|
self,
|
|
|
|
exe,
|
|
|
|
annotated_case_name,
|
|
|
|
case.expected_output,
|
|
|
|
case.cli_args,
|
|
|
|
);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
self.step.dependOn(&run_and_cmp_output.step);
|
|
|
|
},
|
|
|
|
Special.None => {
|
2018-07-11 23:38:01 +00:00
|
|
|
for (self.modes) |mode| {
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
|
|
|
|
"compare-output",
|
|
|
|
case.name,
|
|
|
|
@tagName(mode),
|
|
|
|
}) catch unreachable;
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
const exe = b.addExecutable("test", root_src);
|
2017-05-02 21:34:21 +00:00
|
|
|
exe.setBuildMode(mode);
|
2017-04-19 18:41:59 +00:00
|
|
|
if (case.link_libc) {
|
2017-04-21 05:56:12 +00:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2019-05-26 17:17:34 +00:00
|
|
|
const expanded_src_path = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, src_file.filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 18:41:59 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
exe.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const run_and_cmp_output = RunCompareOutputStep.create(
|
|
|
|
self,
|
|
|
|
exe,
|
|
|
|
annotated_case_name,
|
|
|
|
case.expected_output,
|
|
|
|
case.cli_args,
|
|
|
|
);
|
2017-04-19 18:41:59 +00:00
|
|
|
|
|
|
|
self.step.dependOn(&run_and_cmp_output.step);
|
|
|
|
}
|
|
|
|
},
|
2018-01-25 06:46:12 +00:00
|
|
|
Special.RuntimeSafety => {
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", .{case.name}) catch unreachable;
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test", root_src);
|
|
|
|
if (case.link_libc) {
|
2017-04-21 05:56:12 +00:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2019-05-26 17:17:34 +00:00
|
|
|
const expanded_src_path = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, src_file.filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
exe.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const run_and_cmp_output = RuntimeSafetyRunStep.create(self, exe, annotated_case_name);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
self.step.dependOn(&run_and_cmp_output.step);
|
2017-04-19 18:41:59 +00:00
|
|
|
},
|
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-03 14:08:39 +00:00
|
|
|
pub const StackTracesContext = struct {
|
2019-05-28 00:07:05 +00:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
modes: []const Mode,
|
|
|
|
|
|
|
|
const Expect = [@typeInfo(Mode).Enum.fields.len][]const u8;
|
|
|
|
|
|
|
|
pub fn addCase(
|
2019-09-03 14:08:39 +00:00
|
|
|
self: *StackTracesContext,
|
2019-05-28 00:07:05 +00:00
|
|
|
name: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
expect: Expect,
|
|
|
|
) void {
|
|
|
|
const b = self.b;
|
|
|
|
|
|
|
|
const source_pathname = fs.path.join(
|
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, "source.zig" },
|
2019-05-28 00:07:05 +00:00
|
|
|
) catch unreachable;
|
|
|
|
|
|
|
|
for (self.modes) |mode| {
|
|
|
|
const expect_for_mode = expect[@enumToInt(mode)];
|
|
|
|
if (expect_for_mode.len == 0) continue;
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", .{
|
|
|
|
"stack-trace",
|
|
|
|
name,
|
|
|
|
@tagName(mode),
|
|
|
|
}) catch unreachable;
|
2019-05-28 00:07:05 +00:00
|
|
|
if (self.test_filter) |filter| {
|
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test", source_pathname);
|
|
|
|
exe.setBuildMode(mode);
|
|
|
|
|
|
|
|
const write_source = b.addWriteFile(source_pathname, source);
|
|
|
|
exe.step.dependOn(&write_source.step);
|
|
|
|
|
|
|
|
const run_and_compare = RunAndCompareStep.create(
|
|
|
|
self,
|
|
|
|
exe,
|
|
|
|
annotated_case_name,
|
|
|
|
mode,
|
|
|
|
expect_for_mode,
|
|
|
|
);
|
|
|
|
|
|
|
|
self.step.dependOn(&run_and_compare.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const RunAndCompareStep = struct {
|
|
|
|
step: build.Step,
|
2019-09-03 14:08:39 +00:00
|
|
|
context: *StackTracesContext,
|
2019-05-28 00:07:05 +00:00
|
|
|
exe: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
mode: Mode,
|
|
|
|
expect_output: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
|
|
|
|
pub fn create(
|
2019-09-03 14:08:39 +00:00
|
|
|
context: *StackTracesContext,
|
2019-05-28 00:07:05 +00:00
|
|
|
exe: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
mode: Mode,
|
|
|
|
expect_output: []const u8,
|
|
|
|
) *RunAndCompareStep {
|
|
|
|
const allocator = context.b.allocator;
|
|
|
|
const ptr = allocator.create(RunAndCompareStep) catch unreachable;
|
|
|
|
ptr.* = RunAndCompareStep{
|
2019-09-03 14:05:19 +00:00
|
|
|
.step = build.Step.init("StackTraceCompareOutputStep", allocator, make),
|
2019-05-28 00:07:05 +00:00
|
|
|
.context = context,
|
|
|
|
.exe = exe,
|
|
|
|
.name = name,
|
|
|
|
.mode = mode,
|
|
|
|
.expect_output = expect_output,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
};
|
|
|
|
ptr.step.dependOn(&exe.step);
|
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: *build.Step) !void {
|
|
|
|
const self = @fieldParentPtr(RunAndCompareStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
|
|
|
const full_exe_path = self.exe.getOutputPath();
|
|
|
|
var args = ArrayList([]const u8).init(b.allocator);
|
|
|
|
defer args.deinit();
|
|
|
|
args.append(full_exe_path) catch unreachable;
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2019-05-28 00:07:05 +00:00
|
|
|
|
|
|
|
const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
|
|
|
|
defer child.deinit();
|
|
|
|
|
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Pipe;
|
|
|
|
child.stderr_behavior = .Pipe;
|
|
|
|
child.env_map = b.env_map;
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
2019-05-28 00:07:05 +00:00
|
|
|
|
|
|
|
var stdout = Buffer.initNull(b.allocator);
|
|
|
|
var stderr = Buffer.initNull(b.allocator);
|
|
|
|
|
|
|
|
var stdout_file_in_stream = child.stdout.?.inStream();
|
|
|
|
var stderr_file_in_stream = child.stderr.?.inStream();
|
|
|
|
|
|
|
|
stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
|
|
|
|
stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
|
|
|
|
|
|
|
|
const term = child.wait() catch |err| {
|
2019-12-09 03:53:51 +00:00
|
|
|
debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
|
2019-05-28 00:07:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
switch (term) {
|
|
|
|
.Exited => |code| {
|
|
|
|
const expect_code: u32 = 1;
|
|
|
|
if (code != expect_code) {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} exited with error code {} but expected code {}\n", .{
|
|
|
|
full_exe_path,
|
|
|
|
code,
|
|
|
|
expect_code,
|
|
|
|
});
|
2019-05-28 00:07:05 +00:00
|
|
|
printInvocation(args.toSliceConst());
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.Signal => |signum| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum });
|
2019-05-28 00:07:05 +00:00
|
|
|
printInvocation(args.toSliceConst());
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
.Stopped => |signum| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum });
|
2019-05-28 00:07:05 +00:00
|
|
|
printInvocation(args.toSliceConst());
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
.Unknown => |code| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code });
|
2019-05-28 00:07:05 +00:00
|
|
|
printInvocation(args.toSliceConst());
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// process result
|
|
|
|
// - keep only basename of source file path
|
|
|
|
// - replace address with symbolic string
|
|
|
|
// - skip empty lines
|
|
|
|
const got: []const u8 = got_result: {
|
|
|
|
var buf = try Buffer.initSize(b.allocator, 0);
|
|
|
|
defer buf.deinit();
|
|
|
|
var bytes = stderr.toSliceConst();
|
|
|
|
if (bytes.len != 0 and bytes[bytes.len - 1] == '\n') bytes = bytes[0 .. bytes.len - 1];
|
|
|
|
var it = mem.separate(bytes, "\n");
|
|
|
|
process_lines: while (it.next()) |line| {
|
|
|
|
if (line.len == 0) continue;
|
2019-09-03 14:05:19 +00:00
|
|
|
const delims = [_][]const u8{ ":", ":", ":", " in " };
|
|
|
|
var marks = [_]usize{0} ** 4;
|
2019-05-28 00:07:05 +00:00
|
|
|
// offset search past `[drive]:` on windows
|
|
|
|
var pos: usize = if (builtin.os == .windows) 2 else 0;
|
|
|
|
for (delims) |delim, i| {
|
|
|
|
marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
|
|
|
|
try buf.append(line);
|
|
|
|
try buf.append("\n");
|
|
|
|
continue :process_lines;
|
|
|
|
};
|
|
|
|
pos = marks[i] + delim.len;
|
|
|
|
}
|
|
|
|
pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse {
|
|
|
|
try buf.append(line);
|
|
|
|
try buf.append("\n");
|
|
|
|
continue :process_lines;
|
|
|
|
};
|
|
|
|
try buf.append(line[pos + 1 .. marks[2] + delims[2].len]);
|
|
|
|
try buf.append(" [address]");
|
|
|
|
try buf.append(line[marks[3]..]);
|
|
|
|
try buf.append("\n");
|
|
|
|
}
|
|
|
|
break :got_result buf.toOwnedSlice();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!mem.eql(u8, self.expect_output, got)) {
|
|
|
|
warn(
|
|
|
|
\\
|
|
|
|
\\========= Expected this output: =========
|
|
|
|
\\{}
|
|
|
|
\\================================================
|
|
|
|
\\{}
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{ self.expect_output, got });
|
2019-05-28 00:07:05 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("OK\n", .{});
|
2019-05-28 00:07:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
pub const CompileErrorContext = struct {
|
2018-05-31 14:56:59 +00:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2017-04-19 18:00:12 +00:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
2018-07-11 23:38:01 +00:00
|
|
|
modes: []const Mode,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const TestCase = struct {
|
2017-04-19 18:00:12 +00:00
|
|
|
name: []const u8,
|
2017-05-04 18:05:06 +00:00
|
|
|
sources: ArrayList(SourceFile),
|
|
|
|
expected_errors: ArrayList([]const u8),
|
2019-02-17 20:47:53 +00:00
|
|
|
expect_exact: bool,
|
2017-04-19 18:00:12 +00:00
|
|
|
link_libc: bool,
|
|
|
|
is_exe: bool,
|
2019-02-09 00:23:46 +00:00
|
|
|
is_test: bool,
|
2019-08-20 18:40:57 +00:00
|
|
|
target: Target = .Native,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const SourceFile = struct {
|
2017-04-19 18:00:12 +00:00
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
2018-11-13 13:08:37 +00:00
|
|
|
self.sources.append(SourceFile{
|
2017-04-19 18:00:12 +00:00
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
2018-01-09 05:07:01 +00:00
|
|
|
}) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addExpectedError(self: *TestCase, text: []const u8) void {
|
2018-01-09 05:07:01 +00:00
|
|
|
self.expected_errors.append(text) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const CompileCmpOutputStep = struct {
|
2017-04-19 18:00:12 +00:00
|
|
|
step: build.Step,
|
2018-05-31 14:56:59 +00:00
|
|
|
context: *CompileErrorContext,
|
2017-04-19 18:00:12 +00:00
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
2018-05-31 14:56:59 +00:00
|
|
|
case: *const TestCase,
|
2017-05-02 21:34:21 +00:00
|
|
|
build_mode: Mode,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-02-17 20:47:53 +00:00
|
|
|
const ErrLineIter = struct {
|
|
|
|
lines: mem.SplitIterator,
|
|
|
|
|
2019-03-01 20:35:29 +00:00
|
|
|
const source_file = "tmp.zig";
|
2019-02-17 20:47:53 +00:00
|
|
|
|
|
|
|
fn init(input: []const u8) ErrLineIter {
|
2019-02-18 17:56:17 +00:00
|
|
|
return ErrLineIter{ .lines = mem.separate(input, "\n") };
|
2019-02-17 20:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn next(self: *ErrLineIter) ?[]const u8 {
|
|
|
|
while (self.lines.next()) |line| {
|
|
|
|
if (mem.indexOf(u8, line, source_file) != null)
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep {
|
2017-04-19 18:00:12 +00:00
|
|
|
const allocator = context.b.allocator;
|
2019-02-03 21:13:28 +00:00
|
|
|
const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
|
|
|
|
ptr.* = CompileCmpOutputStep{
|
2017-04-19 18:00:12 +00:00
|
|
|
.step = build.Step.init("CompileCmpOutput", allocator, make),
|
|
|
|
.context = context,
|
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.case = case,
|
2017-05-02 21:34:21 +00:00
|
|
|
.build_mode = build_mode,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-06-20 15:40:21 +00:00
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
fn make(step: *build.Step) !void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
const root_src = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-05-04 18:05:06 +00:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append(b.zig_exe) catch unreachable;
|
2017-09-26 05:01:49 +00:00
|
|
|
|
2019-02-09 00:23:46 +00:00
|
|
|
if (self.case.is_exe) {
|
|
|
|
try zig_args.append("build-exe");
|
|
|
|
} else if (self.case.is_test) {
|
|
|
|
try zig_args.append("test");
|
|
|
|
} else {
|
|
|
|
try zig_args.append("build-obj");
|
|
|
|
}
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("--name") catch unreachable;
|
|
|
|
zig_args.append("test") catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
zig_args.append("--output-dir") catch unreachable;
|
|
|
|
zig_args.append(b.pathFromRoot(b.cache_root)) catch unreachable;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-08-20 18:40:57 +00:00
|
|
|
switch (self.case.target) {
|
|
|
|
.Native => {},
|
|
|
|
.Cross => {
|
|
|
|
try zig_args.append("-target");
|
|
|
|
try zig_args.append(try self.case.target.zigTriple(b.allocator));
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-02 21:34:21 +00:00
|
|
|
switch (self.build_mode) {
|
|
|
|
Mode.Debug => {},
|
2018-01-09 05:07:01 +00:00
|
|
|
Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
|
|
|
|
Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
|
2018-04-16 01:06:00 +00:00
|
|
|
Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
if (b.verbose) {
|
2017-10-15 20:03:32 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
|
2017-09-26 05:01:49 +00:00
|
|
|
defer child.deinit();
|
|
|
|
|
2018-10-15 22:23:47 +00:00
|
|
|
child.env_map = b.env_map;
|
2019-05-26 17:17:34 +00:00
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Pipe;
|
|
|
|
child.stderr_behavior = .Pipe;
|
2017-09-26 05:01:49 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-22 15:36:42 +00:00
|
|
|
var stdout_buf = Buffer.initNull(b.allocator);
|
|
|
|
var stderr_buf = Buffer.initNull(b.allocator);
|
|
|
|
|
2018-09-30 21:23:42 +00:00
|
|
|
var stdout_file_in_stream = child.stdout.?.inStream();
|
|
|
|
var stderr_file_in_stream = child.stderr.?.inStream();
|
2017-11-07 08:22:27 +00:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
|
|
|
|
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
2017-04-22 15:36:42 +00:00
|
|
|
|
2018-01-07 22:28:20 +00:00
|
|
|
const term = child.wait() catch |err| {
|
2019-12-09 03:53:51 +00:00
|
|
|
debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
|
2017-04-19 18:00:12 +00:00
|
|
|
};
|
|
|
|
switch (term) {
|
2019-05-26 17:17:34 +00:00
|
|
|
.Exited => |code| {
|
2017-04-19 18:00:12 +00:00
|
|
|
if (code == 0) {
|
2019-03-15 21:47:47 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2018-01-15 05:01:02 +00:00
|
|
|
return error.CompilationIncorrectlySucceeded;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
else => {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Process {} terminated unexpectedly\n", .{b.zig_exe});
|
2019-03-15 21:47:47 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 18:00:12 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
2017-12-22 05:50:30 +00:00
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
const stdout = stdout_buf.toSliceConst();
|
|
|
|
const stderr = stderr_buf.toSliceConst();
|
|
|
|
|
|
|
|
if (stdout.len != 0) {
|
2017-10-31 08:47:55 +00:00
|
|
|
warn(
|
2017-04-19 18:00:12 +00:00
|
|
|
\\
|
|
|
|
\\Expected empty stdout, instead found:
|
|
|
|
\\================================================
|
|
|
|
\\{}
|
|
|
|
\\================================================
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{stdout});
|
2017-04-19 18:00:12 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:47:53 +00:00
|
|
|
var ok = true;
|
|
|
|
if (self.case.expect_exact) {
|
|
|
|
var err_iter = ErrLineIter.init(stderr);
|
|
|
|
var i: usize = 0;
|
|
|
|
ok = while (err_iter.next()) |line| : (i += 1) {
|
|
|
|
if (i >= self.case.expected_errors.len) break false;
|
|
|
|
const expected = self.case.expected_errors.at(i);
|
|
|
|
if (mem.indexOf(u8, line, expected) == null) break false;
|
|
|
|
continue;
|
|
|
|
} else true;
|
|
|
|
|
|
|
|
ok = ok and i == self.case.expected_errors.len;
|
|
|
|
|
|
|
|
if (!ok) {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\n======== Expected these compile errors: ========\n", .{});
|
2019-02-17 20:47:53 +00:00
|
|
|
for (self.case.expected_errors.toSliceConst()) |expected| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("{}\n", .{expected});
|
2019-02-17 20:47:53 +00:00
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
2019-02-17 20:47:53 +00:00
|
|
|
} else {
|
|
|
|
for (self.case.expected_errors.toSliceConst()) |expected| {
|
|
|
|
if (mem.indexOf(u8, stderr, expected) == null) {
|
|
|
|
warn(
|
2019-02-20 13:04:46 +00:00
|
|
|
\\
|
|
|
|
\\=========== Expected compile error: ============
|
2019-02-17 20:47:53 +00:00
|
|
|
\\{}
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{expected});
|
2019-02-17 20:47:53 +00:00
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
warn(
|
|
|
|
\\================= Full output: =================
|
|
|
|
\\{}
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{stderr});
|
2019-02-17 20:47:53 +00:00
|
|
|
return error.TestFailed;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
2019-02-17 20:47:53 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("OK\n", .{});
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
|
2019-02-03 21:13:28 +00:00
|
|
|
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
|
|
|
tc.* = TestCase{
|
2017-04-19 18:00:12 +00:00
|
|
|
.name = name,
|
2017-05-04 18:05:06 +00:00
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
|
|
|
.expected_errors = ArrayList([]const u8).init(self.b.allocator),
|
2019-02-17 20:47:53 +00:00
|
|
|
.expect_exact = false,
|
2017-04-19 18:00:12 +00:00
|
|
|
.link_libc = false,
|
|
|
|
.is_exe = false,
|
2019-02-09 00:23:46 +00:00
|
|
|
.is_test = false,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-06-20 15:40:21 +00:00
|
|
|
|
2019-03-01 20:35:29 +00:00
|
|
|
tc.addSourceFile("tmp.zig", source);
|
2017-04-19 18:00:12 +00:00
|
|
|
comptime var arg_i = 0;
|
2017-05-03 22:12:07 +00:00
|
|
|
inline while (arg_i < expected_lines.len) : (arg_i += 1) {
|
2017-05-27 03:31:38 +00:00
|
|
|
tc.addExpectedError(expected_lines[arg_i]);
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
var tc = self.create(name, source, expected_lines);
|
|
|
|
tc.link_libc = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addExe(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
var tc = self.create(name, source, expected_lines);
|
|
|
|
tc.is_exe = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn add(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const tc = self.create(name, source, expected_lines);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2019-02-09 00:23:46 +00:00
|
|
|
pub fn addTest(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
|
|
|
const tc = self.create(name, source, expected_lines);
|
|
|
|
tc.is_test = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const b = self.b;
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {}", .{
|
|
|
|
case.name,
|
|
|
|
}) catch unreachable;
|
2019-06-23 06:06:57 +00:00
|
|
|
if (self.test_filter) |filter| {
|
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-06-23 06:06:57 +00:00
|
|
|
const compile_and_cmp_errors = CompileCmpOutputStep.create(self, annotated_case_name, case, .Debug);
|
|
|
|
self.step.dependOn(&compile_and_cmp_errors.step);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-06-23 06:06:57 +00:00
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
|
|
|
const expanded_src_path = fs.path.join(
|
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, src_file.filename },
|
2019-06-23 06:06:57 +00:00
|
|
|
) catch unreachable;
|
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
compile_and_cmp_errors.step.dependOn(&write_src.step);
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
pub const StandaloneContext = struct {
|
2018-05-31 14:56:59 +00:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2017-04-19 18:00:12 +00:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
2018-07-18 08:28:14 +00:00
|
|
|
modes: []const Mode,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
pub fn addC(self: *StandaloneContext, root_src: []const u8) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
self.addAllArgs(root_src, true);
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
pub fn add(self: *StandaloneContext, root_src: []const u8) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
self.addAllArgs(root_src, false);
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8) void {
|
2017-04-21 05:56:12 +00:00
|
|
|
const b = self.b;
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = b.fmt("build {} (Debug)", .{build_file});
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2017-04-21 05:56:12 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 18:05:06 +00:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2019-05-26 17:17:34 +00:00
|
|
|
const rel_zig_exe = fs.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable;
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append(rel_zig_exe) catch unreachable;
|
|
|
|
zig_args.append("build") catch unreachable;
|
2017-04-21 05:56:12 +00:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("--build-file") catch unreachable;
|
|
|
|
zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
|
2017-04-21 05:56:12 +00:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("test") catch unreachable;
|
2017-04-21 05:56:12 +00:00
|
|
|
|
|
|
|
if (b.verbose) {
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append("--verbose") catch unreachable;
|
2017-04-21 05:56:12 +00:00
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
|
2017-04-21 05:56:12 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
|
2017-04-21 05:56:12 +00:00
|
|
|
log_step.step.dependOn(&run_cmd.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&log_step.step);
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:15:46 +00:00
|
|
|
pub fn addAllArgs(self: *StandaloneContext, root_src: []const u8, link_libc: bool) void {
|
2017-04-19 18:00:12 +00:00
|
|
|
const b = self.b;
|
|
|
|
|
2018-07-18 08:28:14 +00:00
|
|
|
for (self.modes) |mode| {
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})", .{
|
|
|
|
root_src,
|
|
|
|
@tagName(mode),
|
|
|
|
}) catch unreachable;
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test", root_src);
|
2017-05-02 21:34:21 +00:00
|
|
|
exe.setBuildMode(mode);
|
2017-04-19 18:00:12 +00:00
|
|
|
if (link_libc) {
|
2017-04-21 05:56:12 +00:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
|
2017-04-19 18:00:12 +00:00
|
|
|
log_step.step.dependOn(&exe.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&log_step.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
pub const TranslateCContext = struct {
|
2018-05-31 14:56:59 +00:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2017-04-19 20:59:20 +00:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const TestCase = struct {
|
2017-04-19 20:59:20 +00:00
|
|
|
name: []const u8,
|
2017-05-04 18:05:06 +00:00
|
|
|
sources: ArrayList(SourceFile),
|
|
|
|
expected_lines: ArrayList([]const u8),
|
2017-04-19 20:59:20 +00:00
|
|
|
allow_warnings: bool,
|
2019-05-10 20:03:54 +00:00
|
|
|
stage2: bool,
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const SourceFile = struct {
|
2017-04-19 20:59:20 +00:00
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
2018-11-13 13:08:37 +00:00
|
|
|
self.sources.append(SourceFile{
|
2017-04-19 20:59:20 +00:00
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
2018-01-09 05:07:01 +00:00
|
|
|
}) catch unreachable;
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
|
2018-01-09 05:07:01 +00:00
|
|
|
self.expected_lines.append(text) catch unreachable;
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const TranslateCCmpOutputStep = struct {
|
2017-04-19 20:59:20 +00:00
|
|
|
step: build.Step,
|
2018-05-31 14:56:59 +00:00
|
|
|
context: *TranslateCContext,
|
2017-04-19 20:59:20 +00:00
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
2018-05-31 14:56:59 +00:00
|
|
|
case: *const TestCase,
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep {
|
2017-04-19 20:59:20 +00:00
|
|
|
const allocator = context.b.allocator;
|
2019-02-03 21:13:28 +00:00
|
|
|
const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
|
|
|
|
ptr.* = TranslateCCmpOutputStep{
|
2017-09-06 02:55:03 +00:00
|
|
|
.step = build.Step.init("ParseCCmpOutput", allocator, make),
|
2017-04-19 20:59:20 +00:00
|
|
|
.context = context,
|
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.case = case,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-06-20 15:40:21 +00:00
|
|
|
|
2017-04-19 20:59:20 +00:00
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
fn make(step: *build.Step) !void {
|
2017-11-24 19:56:05 +00:00
|
|
|
const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
|
2017-04-19 20:59:20 +00:00
|
|
|
const b = self.context.b;
|
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
const root_src = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2017-05-04 18:05:06 +00:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append(b.zig_exe) catch unreachable;
|
2017-09-26 05:01:49 +00:00
|
|
|
|
2019-05-10 20:03:54 +00:00
|
|
|
const translate_c_cmd = if (self.case.stage2) "translate-c-2" else "translate-c";
|
|
|
|
zig_args.append(translate_c_cmd) catch unreachable;
|
2018-01-09 05:07:01 +00:00
|
|
|
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2017-04-19 20:59:20 +00:00
|
|
|
|
|
|
|
if (b.verbose) {
|
2017-10-15 20:03:32 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 17:17:34 +00:00
|
|
|
const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
|
2017-09-26 05:01:49 +00:00
|
|
|
defer child.deinit();
|
|
|
|
|
2018-10-15 22:23:47 +00:00
|
|
|
child.env_map = b.env_map;
|
2019-05-26 17:17:34 +00:00
|
|
|
child.stdin_behavior = .Ignore;
|
|
|
|
child.stdout_behavior = .Pipe;
|
|
|
|
child.stderr_behavior = .Pipe;
|
2017-09-26 05:01:49 +00:00
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{
|
|
|
|
zig_args.toSliceConst()[0],
|
|
|
|
@errorName(err),
|
|
|
|
});
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2017-04-22 15:36:42 +00:00
|
|
|
var stdout_buf = Buffer.initNull(b.allocator);
|
|
|
|
var stderr_buf = Buffer.initNull(b.allocator);
|
|
|
|
|
2018-09-30 21:23:42 +00:00
|
|
|
var stdout_file_in_stream = child.stdout.?.inStream();
|
|
|
|
var stderr_file_in_stream = child.stderr.?.inStream();
|
2017-11-07 08:22:27 +00:00
|
|
|
|
2018-01-09 05:07:01 +00:00
|
|
|
stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
|
|
|
|
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
2017-04-22 15:36:42 +00:00
|
|
|
|
2018-01-07 22:28:20 +00:00
|
|
|
const term = child.wait() catch |err| {
|
2019-12-09 03:53:51 +00:00
|
|
|
debug.panic("Unable to spawn {}: {}\n", .{ zig_args.toSliceConst()[0], @errorName(err) });
|
2017-04-19 20:59:20 +00:00
|
|
|
};
|
|
|
|
switch (term) {
|
2019-05-26 17:17:34 +00:00
|
|
|
.Exited => |code| {
|
2017-04-19 20:59:20 +00:00
|
|
|
if (code != 0) {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Compilation failed with exit code {}\n", .{code});
|
2019-03-01 22:15:58 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 20:59:20 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
2019-05-26 17:17:34 +00:00
|
|
|
.Signal => |code| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Compilation failed with signal {}\n", .{code});
|
2019-03-01 22:15:58 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 20:59:20 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
else => {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Compilation terminated unexpectedly\n", .{});
|
2019-03-01 22:15:58 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 20:59:20 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
},
|
2017-12-22 05:50:30 +00:00
|
|
|
}
|
2017-04-19 20:59:20 +00:00
|
|
|
|
|
|
|
const stdout = stdout_buf.toSliceConst();
|
|
|
|
const stderr = stderr_buf.toSliceConst();
|
|
|
|
|
|
|
|
if (stderr.len != 0 and !self.case.allow_warnings) {
|
2017-10-31 08:47:55 +00:00
|
|
|
warn(
|
2017-11-24 19:56:05 +00:00
|
|
|
\\====== translate-c emitted warnings: =======
|
2017-04-19 20:59:20 +00:00
|
|
|
\\{}
|
|
|
|
\\============================================
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{stderr});
|
2019-03-19 00:09:27 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 20:59:20 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (self.case.expected_lines.toSliceConst()) |expected_line| {
|
|
|
|
if (mem.indexOf(u8, stdout, expected_line) == null) {
|
2017-10-31 08:47:55 +00:00
|
|
|
warn(
|
2017-04-19 20:59:20 +00:00
|
|
|
\\
|
|
|
|
\\========= Expected this output: ================
|
|
|
|
\\{}
|
2019-05-25 11:43:52 +00:00
|
|
|
\\========= But found: ===========================
|
2017-04-19 20:59:20 +00:00
|
|
|
\\{}
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{ expected_line, stdout });
|
2019-03-19 00:09:27 +00:00
|
|
|
printInvocation(zig_args.toSliceConst());
|
2017-04-19 20:59:20 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("OK\n", .{});
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
fn printInvocation(args: []const []const u8) void {
|
2017-04-19 20:59:20 +00:00
|
|
|
for (args) |arg| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("{} ", .{arg});
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\n", .{});
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
|
2019-02-03 21:13:28 +00:00
|
|
|
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
|
|
|
tc.* = TestCase{
|
2017-04-19 20:59:20 +00:00
|
|
|
.name = name,
|
2017-05-04 18:05:06 +00:00
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
|
|
|
.expected_lines = ArrayList([]const u8).init(self.b.allocator),
|
2017-04-19 20:59:20 +00:00
|
|
|
.allow_warnings = allow_warnings,
|
2019-05-10 20:03:54 +00:00
|
|
|
.stage2 = false,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-06-20 15:40:21 +00:00
|
|
|
|
2017-10-02 01:42:33 +00:00
|
|
|
tc.addSourceFile(filename, source);
|
2017-04-19 20:59:20 +00:00
|
|
|
comptime var arg_i = 0;
|
2017-05-03 22:12:07 +00:00
|
|
|
inline while (arg_i < expected_lines.len) : (arg_i += 1) {
|
2017-09-12 02:58:06 +00:00
|
|
|
tc.addExpectedLine(expected_lines[arg_i]);
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn add(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2017-10-02 01:42:33 +00:00
|
|
|
const tc = self.create(false, "source.h", name, source, expected_lines);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addC(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2017-10-02 01:42:33 +00:00
|
|
|
const tc = self.create(false, "source.c", name, source, expected_lines);
|
2017-04-19 20:59:20 +00:00
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2019-05-10 20:03:54 +00:00
|
|
|
pub fn add_both(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2019-06-09 23:24:24 +00:00
|
|
|
for ([_]bool{ false, true }) |stage2| {
|
2019-05-11 16:05:33 +00:00
|
|
|
const tc = self.create(false, "source.h", name, source, expected_lines);
|
|
|
|
tc.stage2 = stage2;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addC_both(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2019-06-09 23:24:24 +00:00
|
|
|
for ([_]bool{ false, true }) |stage2| {
|
2019-05-10 20:03:54 +00:00
|
|
|
const tc = self.create(false, "source.c", name, source, expected_lines);
|
|
|
|
tc.stage2 = stage2;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_2(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2019-05-11 16:05:33 +00:00
|
|
|
const tc = self.create(false, "source.h", name, source, expected_lines);
|
2019-05-10 20:03:54 +00:00
|
|
|
tc.stage2 = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addC_2(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
|
|
|
const tc = self.create(false, "source.c", name, source, expected_lines);
|
|
|
|
tc.stage2 = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addAllowWarnings(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2017-10-02 01:42:33 +00:00
|
|
|
const tc = self.create(true, "source.h", name, source, expected_lines);
|
2017-04-19 20:59:20 +00:00
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addCase(self: *TranslateCContext, case: *const TestCase) void {
|
2017-04-19 20:59:20 +00:00
|
|
|
const b = self.b;
|
|
|
|
|
2019-05-10 20:03:54 +00:00
|
|
|
const translate_c_cmd = if (case.stage2) "translate-c-2" else "translate-c";
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {}", .{ translate_c_cmd, case.name }) catch unreachable;
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 19:56:05 +00:00
|
|
|
const translate_c_and_cmp = TranslateCCmpOutputStep.create(self, annotated_case_name, case);
|
|
|
|
self.step.dependOn(&translate_c_and_cmp.step);
|
2017-04-19 20:59:20 +00:00
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2019-05-26 17:17:34 +00:00
|
|
|
const expanded_src_path = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, src_file.filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2017-04-19 20:59:20 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
2017-11-24 19:56:05 +00:00
|
|
|
translate_c_and_cmp.step.dependOn(&write_src.step);
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-01-23 03:24:07 +00:00
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
pub const GenHContext = struct {
|
2018-05-31 14:56:59 +00:00
|
|
|
b: *build.Builder,
|
|
|
|
step: *build.Step,
|
2018-01-23 03:24:07 +00:00
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const TestCase = struct {
|
2018-01-23 03:24:07 +00:00
|
|
|
name: []const u8,
|
|
|
|
sources: ArrayList(SourceFile),
|
|
|
|
expected_lines: ArrayList([]const u8),
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const SourceFile = struct {
|
2018-01-23 03:24:07 +00:00
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addSourceFile(self: *TestCase, filename: []const u8, source: []const u8) void {
|
2018-11-13 13:08:37 +00:00
|
|
|
self.sources.append(SourceFile{
|
2018-01-23 03:24:07 +00:00
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
|
|
|
}) catch unreachable;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addExpectedLine(self: *TestCase, text: []const u8) void {
|
2018-01-23 03:24:07 +00:00
|
|
|
self.expected_lines.append(text) catch unreachable;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-13 13:08:37 +00:00
|
|
|
const GenHCmpOutputStep = struct {
|
2018-01-23 03:24:07 +00:00
|
|
|
step: build.Step,
|
2018-05-31 14:56:59 +00:00
|
|
|
context: *GenHContext,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
obj: *LibExeObjStep,
|
2018-01-23 03:24:07 +00:00
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
2018-05-31 14:56:59 +00:00
|
|
|
case: *const TestCase,
|
2018-01-23 03:24:07 +00:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
pub fn create(
|
|
|
|
context: *GenHContext,
|
|
|
|
obj: *LibExeObjStep,
|
|
|
|
name: []const u8,
|
|
|
|
case: *const TestCase,
|
|
|
|
) *GenHCmpOutputStep {
|
2018-01-23 03:24:07 +00:00
|
|
|
const allocator = context.b.allocator;
|
2019-02-03 21:13:28 +00:00
|
|
|
const ptr = allocator.create(GenHCmpOutputStep) catch unreachable;
|
|
|
|
ptr.* = GenHCmpOutputStep{
|
2018-01-23 03:24:07 +00:00
|
|
|
.step = build.Step.init("ParseCCmpOutput", allocator, make),
|
|
|
|
.context = context,
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
.obj = obj,
|
2018-01-23 03:24:07 +00:00
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.case = case,
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
ptr.step.dependOn(&obj.step);
|
2018-01-23 03:24:07 +00:00
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
fn make(step: *build.Step) !void {
|
2018-01-23 03:24:07 +00:00
|
|
|
const self = @fieldParentPtr(GenHCmpOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
|
2018-01-23 03:24:07 +00:00
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const full_h_path = self.obj.getOutputHPath();
|
2018-02-09 23:27:50 +00:00
|
|
|
const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
|
2018-01-23 03:24:07 +00:00
|
|
|
|
|
|
|
for (self.case.expected_lines.toSliceConst()) |expected_line| {
|
|
|
|
if (mem.indexOf(u8, actual_h, expected_line) == null) {
|
|
|
|
warn(
|
|
|
|
\\
|
|
|
|
\\========= Expected this output: ================
|
|
|
|
\\{}
|
2019-05-25 11:43:52 +00:00
|
|
|
\\========= But found: ===========================
|
2018-01-23 03:24:07 +00:00
|
|
|
\\{}
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{ expected_line, actual_h });
|
2018-01-23 03:24:07 +00:00
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("OK\n", .{});
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-25 09:10:11 +00:00
|
|
|
fn printInvocation(args: []const []const u8) void {
|
2018-01-23 03:24:07 +00:00
|
|
|
for (args) |arg| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("{} ", .{arg});
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\n", .{});
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
|
2019-02-03 21:13:28 +00:00
|
|
|
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
|
|
|
tc.* = TestCase{
|
2018-01-23 03:24:07 +00:00
|
|
|
.name = name,
|
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
|
|
|
.expected_lines = ArrayList([]const u8).init(self.b.allocator),
|
2019-02-03 21:13:28 +00:00
|
|
|
};
|
2018-06-20 15:40:21 +00:00
|
|
|
|
2018-01-23 03:24:07 +00:00
|
|
|
tc.addSourceFile(filename, source);
|
|
|
|
comptime var arg_i = 0;
|
|
|
|
inline while (arg_i < expected_lines.len) : (arg_i += 1) {
|
|
|
|
tc.addExpectedLine(expected_lines[arg_i]);
|
|
|
|
}
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
|
2019-03-11 14:29:57 +00:00
|
|
|
const tc = self.create("test.zig", name, source, expected_lines);
|
2018-01-23 03:24:07 +00:00
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
2018-05-31 14:56:59 +00:00
|
|
|
pub fn addCase(self: *GenHContext, case: *const TestCase) void {
|
2018-01-23 03:24:07 +00:00
|
|
|
const b = self.b;
|
2019-05-26 17:17:34 +00:00
|
|
|
const root_src = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, case.sources.items[0].filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2018-01-23 03:24:07 +00:00
|
|
|
|
|
|
|
const mode = builtin.Mode.Debug;
|
2019-12-09 03:53:51 +00:00
|
|
|
const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable;
|
2018-01-23 03:24:07 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2018-05-18 03:21:44 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
|
2018-01-23 03:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const obj = b.addObject("test", root_src);
|
|
|
|
obj.setBuildMode(mode);
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2019-05-26 17:17:34 +00:00
|
|
|
const expanded_src_path = fs.path.join(
|
2019-02-07 05:42:41 +00:00
|
|
|
b.allocator,
|
2019-11-27 08:30:39 +00:00
|
|
|
&[_][]const u8{ b.cache_root, src_file.filename },
|
2019-02-07 05:42:41 +00:00
|
|
|
) catch unreachable;
|
2018-01-23 03:24:07 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
obj.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
|
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
to call, unless setOutputDir() was used, or within a custom make()
function. Instead there is more convenient API to use which takes
advantage of the caching system. Search this commit diff for
`exe.run()` for an example.
* Zig build by default enables caching. All build artifacts will go
into zig-cache. If you want to access build artifacts in a convenient
location, it is recommended to add an `install` step. Otherwise
you can use the `run()` API mentioned above to execute programs
directly from their location in the cache. Closes #330.
`addSystemCommand` is available for programs not built with Zig
build.
* Please note that Zig does no cache evicting yet. You may have to
manually delete zig-cache directories periodically to keep disk
usage down. It's planned for this to be a simple Least Recently
Used eviction system eventually.
* `--output`, `--output-lib`, and `--output-h` are removed. Instead,
use `--output-dir` which defaults to the current working directory.
Or take advantage of `--cache on`, which will print the main output
path to stdout, and the other artifacts will be in the same directory
with predictable file names. `--disable-gen-h` is available when
one wants to prevent .h file generation.
* `@cImport` is always independently cached now. Closes #2015.
It always writes the generated Zig code to disk which makes debug
info and compile errors better. No more "TODO: remember C source
location to display here"
* Fix .d file parsing. (Fixes the MacOS CI failure)
* Zig no longer creates "temporary files" other than inside a
zig-cache directory.
This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-09 03:53:35 +00:00
|
|
|
const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case);
|
2018-01-23 03:24:07 +00:00
|
|
|
|
|
|
|
self.step.dependOn(&cmp_h.step);
|
|
|
|
}
|
|
|
|
};
|
2019-03-15 21:47:47 +00:00
|
|
|
|
|
|
|
fn printInvocation(args: []const []const u8) void {
|
|
|
|
for (args) |arg| {
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("{} ", .{arg});
|
2019-03-15 21:47:47 +00:00
|
|
|
}
|
2019-12-09 03:53:51 +00:00
|
|
|
warn("\n", .{});
|
2019-03-15 21:47:47 +00:00
|
|
|
}
|