aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-03-12 00:39:21 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-03-15 10:48:14 -0700
commitede5dcffea5a3a5fc9fd14e4e180464633402fae (patch)
treedcf88812197be81cdb36b747d2b2b55c56d2192b /src
parentef5f8bd7c62f929b5cc210caa816ce4a8c8f8538 (diff)
downloadzig-ede5dcffea5a3a5fc9fd14e4e180464633402fae.tar.gz
zig-ede5dcffea5a3a5fc9fd14e4e180464633402fae.zip
make the build runner and test runner talk to each other
std.Build.addTest creates a CompileStep as before, however, this kind of step no longer actually runs the unit tests. Instead it only compiles it, and one must additionally create a RunStep from the CompileStep in order to actually run the tests. RunStep gains integration with the default test runner, which now supports the standard --listen=- argument in order to communicate over stdin and stdout. It also reports test statistics; how many passed, failed, and leaked, as well as directly associating the relevant stderr with the particular test name that failed. This separation of CompileStep and RunStep means that `CompileStep.Kind.test_exe` is no longer needed, and therefore has been removed in this commit. * build runner: show unit test statistics in build summary * added Step.writeManifest since many steps want to treat it as a warning and emit the same message if it fails. * RunStep: fixed error message that prints the failed command printing the original argv and not the adjusted argv in case an interpreter was used. * RunStep: fixed not passing the command line arguments to the interpreter. * move src/Server.zig to std.zig.Server so that the default test runner can use it. * the simpler test runner function which is used by work-in-progress backends now no longer prints to stderr, which is necessary in order for the build runner to not print the stderr as a warning message.
Diffstat (limited to 'src')
-rw-r--r--src/Server.zig113
-rw-r--r--src/main.zig21
-rw-r--r--src/objcopy.zig9
3 files changed, 10 insertions, 133 deletions
diff --git a/src/Server.zig b/src/Server.zig
deleted file mode 100644
index a25dc93857..0000000000
--- a/src/Server.zig
+++ /dev/null
@@ -1,113 +0,0 @@
-in: std.fs.File,
-out: std.fs.File,
-receive_fifo: std.fifo.LinearFifo(u8, .Dynamic),
-
-pub const Options = struct {
- gpa: Allocator,
- in: std.fs.File,
- out: std.fs.File,
-};
-
-pub fn init(options: Options) !Server {
- var s: Server = .{
- .in = options.in,
- .out = options.out,
- .receive_fifo = std.fifo.LinearFifo(u8, .Dynamic).init(options.gpa),
- };
- try s.serveStringMessage(.zig_version, build_options.version);
- return s;
-}
-
-pub fn deinit(s: *Server) void {
- s.receive_fifo.deinit();
- s.* = undefined;
-}
-
-pub fn receiveMessage(s: *Server) !InMessage.Header {
- const Header = InMessage.Header;
- const fifo = &s.receive_fifo;
-
- while (true) {
- const buf = fifo.readableSlice(0);
- assert(fifo.readableLength() == buf.len);
- if (buf.len >= @sizeOf(Header)) {
- const header = @ptrCast(*align(1) const Header, buf[0..@sizeOf(Header)]);
- if (header.bytes_len != 0)
- return error.InvalidClientMessage;
- const result = header.*;
- fifo.discard(@sizeOf(Header));
- return result;
- }
-
- const write_buffer = try fifo.writableWithSize(256);
- const amt = try s.in.read(write_buffer);
- fifo.update(amt);
- }
-}
-
-pub fn serveStringMessage(s: *Server, tag: OutMessage.Tag, msg: []const u8) !void {
- return s.serveMessage(.{
- .tag = tag,
- .bytes_len = @intCast(u32, msg.len),
- }, &.{msg});
-}
-
-pub fn serveMessage(
- s: *const Server,
- header: OutMessage.Header,
- bufs: []const []const u8,
-) !void {
- var iovecs: [10]std.os.iovec_const = undefined;
- iovecs[0] = .{
- .iov_base = @ptrCast([*]const u8, &header),
- .iov_len = @sizeOf(OutMessage.Header),
- };
- for (bufs, iovecs[1 .. bufs.len + 1]) |buf, *iovec| {
- iovec.* = .{
- .iov_base = buf.ptr,
- .iov_len = buf.len,
- };
- }
- try s.out.writevAll(iovecs[0 .. bufs.len + 1]);
-}
-
-pub fn serveEmitBinPath(
- s: *Server,
- fs_path: []const u8,
- header: std.zig.Server.Message.EmitBinPath,
-) !void {
- try s.serveMessage(.{
- .tag = .emit_bin_path,
- .bytes_len = @intCast(u32, fs_path.len + @sizeOf(std.zig.Server.Message.EmitBinPath)),
- }, &.{
- std.mem.asBytes(&header),
- fs_path,
- });
-}
-
-pub fn serveErrorBundle(s: *Server, error_bundle: std.zig.ErrorBundle) !void {
- const eb_hdr: std.zig.Server.Message.ErrorBundle = .{
- .extra_len = @intCast(u32, error_bundle.extra.len),
- .string_bytes_len = @intCast(u32, error_bundle.string_bytes.len),
- };
- const bytes_len = @sizeOf(std.zig.Server.Message.ErrorBundle) +
- 4 * error_bundle.extra.len + error_bundle.string_bytes.len;
- try s.serveMessage(.{
- .tag = .error_bundle,
- .bytes_len = @intCast(u32, bytes_len),
- }, &.{
- std.mem.asBytes(&eb_hdr),
- // TODO: implement @ptrCast between slices changing the length
- std.mem.sliceAsBytes(error_bundle.extra),
- error_bundle.string_bytes,
- });
-}
-
-const OutMessage = std.zig.Server.Message;
-const InMessage = std.zig.Client.Message;
-
-const Server = @This();
-const std = @import("std");
-const build_options = @import("build_options");
-const Allocator = std.mem.Allocator;
-const assert = std.debug.assert;
diff --git a/src/main.zig b/src/main.zig
index e0283143d0..9602a5cd31 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -10,6 +10,7 @@ const ArrayList = std.ArrayList;
const Ast = std.zig.Ast;
const warn = std.log.warn;
const ThreadPool = std.Thread.Pool;
+const cleanExit = std.process.cleanExit;
const tracy = @import("tracy.zig");
const Compilation = @import("Compilation.zig");
@@ -26,7 +27,7 @@ const target_util = @import("target.zig");
const crash_report = @import("crash_report.zig");
const Module = @import("Module.zig");
const AstGen = @import("AstGen.zig");
-const Server = @import("Server.zig");
+const Server = std.zig.Server;
pub const std_options = struct {
pub const wasiCwd = wasi_cwd;
@@ -3545,6 +3546,7 @@ fn serve(
.gpa = gpa,
.in = in,
.out = out,
+ .zig_version = build_options.version,
});
defer server.deinit();
@@ -3656,8 +3658,8 @@ fn serve(
);
}
},
- _ => {
- @panic("TODO unrecognized message from client");
+ else => {
+ fatal("unrecognized message from client: 0x{x}", .{@enumToInt(hdr.tag)});
},
}
}
@@ -5624,19 +5626,6 @@ fn detectNativeTargetInfo(cross_target: std.zig.CrossTarget) !std.zig.system.Nat
return std.zig.system.NativeTargetInfo.detect(cross_target);
}
-/// Indicate that we are now terminating with a successful exit code.
-/// In debug builds, this is a no-op, so that the calling code's
-/// cleanup mechanisms are tested and so that external tools that
-/// check for resource leaks can be accurate. In release builds, this
-/// calls exit(0), and does not return.
-pub fn cleanExit() void {
- if (builtin.mode == .Debug) {
- return;
- } else {
- process.exit(0);
- }
-}
-
const usage_ast_check =
\\Usage: zig ast-check [file]
\\
diff --git a/src/objcopy.zig b/src/objcopy.zig
index e821a94b59..c3305e8c04 100644
--- a/src/objcopy.zig
+++ b/src/objcopy.zig
@@ -8,8 +8,8 @@ const assert = std.debug.assert;
const main = @import("main.zig");
const fatal = main.fatal;
-const cleanExit = main.cleanExit;
-const Server = @import("Server.zig");
+const Server = std.zig.Server;
+const build_options = @import("build_options");
pub fn cmdObjCopy(
gpa: Allocator,
@@ -116,6 +116,7 @@ pub fn cmdObjCopy(
.gpa = gpa,
.in = std.io.getStdIn(),
.out = std.io.getStdOut(),
+ .zig_version = build_options.version,
});
defer server.deinit();
@@ -124,7 +125,7 @@ pub fn cmdObjCopy(
const hdr = try server.receiveMessage();
switch (hdr.tag) {
.exit => {
- return cleanExit();
+ return std.process.cleanExit();
},
.update => {
if (seen_update) {
@@ -144,7 +145,7 @@ pub fn cmdObjCopy(
}
}
}
- return cleanExit();
+ return std.process.cleanExit();
}
const usage =