aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Step
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-10-23 22:56:04 -0700
committerGitHub <noreply@github.com>2024-10-23 22:56:04 -0700
commitc563ba6b15b65ecdc1cb538c9437e11dfb330453 (patch)
tree99dd968efc3daea52a1d3628b7d8cedba53e84b7 /lib/std/Build/Step
parent33d07f4b6efe461ee3fbfa32cb18f60aac8c2827 (diff)
parent4bdc2d38717b5655acd862a5762e069419b158c7 (diff)
downloadzig-c563ba6b15b65ecdc1cb538c9437e11dfb330453.tar.gz
zig-c563ba6b15b65ecdc1cb538c9437e11dfb330453.zip
Merge pull request #21700 from ziglang/cli-lib-dirs
move linker input file parsing to the frontend
Diffstat (limited to 'lib/std/Build/Step')
-rw-r--r--lib/std/Build/Step/Compile.zig50
1 files changed, 42 insertions, 8 deletions
diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig
index 469fbdf74a..f0dad8b49a 100644
--- a/lib/std/Build/Step/Compile.zig
+++ b/lib/std/Build/Step/Compile.zig
@@ -186,6 +186,15 @@ want_lto: ?bool = null,
use_llvm: ?bool,
use_lld: ?bool,
+/// Corresponds to the `-fallow-so-scripts` / `-fno-allow-so-scripts` CLI
+/// flags, overriding the global user setting provided to the `zig build`
+/// command.
+///
+/// The compiler defaults this value to off so that users whose system shared
+/// libraries are all ELF files don't have to pay the cost of checking every
+/// file to find out if it is a text file instead.
+allow_so_scripts: ?bool = null,
+
/// This is an advanced setting that can change the intent of this Compile step.
/// If this value is non-null, it means that this Compile step exists to
/// check for compile errors and return *success* if they match, and failure
@@ -236,6 +245,7 @@ pub const ExpectedCompileErrors = union(enum) {
contains: []const u8,
exact: []const []const u8,
starts_with: []const u8,
+ stderr_contains: []const u8,
};
pub const Entry = union(enum) {
@@ -1035,6 +1045,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
if (b.reference_trace) |some| {
try zig_args.append(try std.fmt.allocPrint(arena, "-freference-trace={d}", .{some}));
}
+ try addFlag(&zig_args, "allow-so-scripts", compile.allow_so_scripts orelse b.graph.allow_so_scripts);
try addFlag(&zig_args, "llvm", compile.use_llvm);
try addFlag(&zig_args, "lld", compile.use_lld);
@@ -1945,24 +1956,24 @@ fn checkCompileErrors(compile: *Compile) !void {
const arena = compile.step.owner.allocator;
- var actual_stderr_list = std.ArrayList(u8).init(arena);
+ var actual_errors_list = std.ArrayList(u8).init(arena);
try actual_eb.renderToWriter(.{
.ttyconf = .no_color,
.include_reference_trace = false,
.include_source_line = false,
- }, actual_stderr_list.writer());
- const actual_stderr = try actual_stderr_list.toOwnedSlice();
+ }, actual_errors_list.writer());
+ const actual_errors = try actual_errors_list.toOwnedSlice();
// Render the expected lines into a string that we can compare verbatim.
var expected_generated = std.ArrayList(u8).init(arena);
const expect_errors = compile.expect_errors.?;
- var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n');
+ var actual_line_it = mem.splitScalar(u8, actual_errors, '\n');
// TODO merge this with the testing.expectEqualStrings logic, and also CheckFile
switch (expect_errors) {
.starts_with => |expect_starts_with| {
- if (std.mem.startsWith(u8, actual_stderr, expect_starts_with)) return;
+ if (std.mem.startsWith(u8, actual_errors, expect_starts_with)) return;
return compile.step.fail(
\\
\\========= should start with: ============
@@ -1970,7 +1981,7 @@ fn checkCompileErrors(compile: *Compile) !void {
\\========= but not found: ================
\\{s}
\\=========================================
- , .{ expect_starts_with, actual_stderr });
+ , .{ expect_starts_with, actual_errors });
},
.contains => |expect_line| {
while (actual_line_it.next()) |actual_line| {
@@ -1985,6 +1996,29 @@ fn checkCompileErrors(compile: *Compile) !void {
\\========= but not found: ================
\\{s}
\\=========================================
+ , .{ expect_line, actual_errors });
+ },
+ .stderr_contains => |expect_line| {
+ const actual_stderr: []const u8 = if (compile.step.result_error_msgs.items.len > 0)
+ compile.step.result_error_msgs.items[0]
+ else
+ &.{};
+ compile.step.result_error_msgs.clearRetainingCapacity();
+
+ var stderr_line_it = mem.splitScalar(u8, actual_stderr, '\n');
+
+ while (stderr_line_it.next()) |actual_line| {
+ if (!matchCompileError(actual_line, expect_line)) continue;
+ return;
+ }
+
+ return compile.step.fail(
+ \\
+ \\========= should contain: ===============
+ \\{s}
+ \\========= but not found: ================
+ \\{s}
+ \\=========================================
, .{ expect_line, actual_stderr });
},
.exact => |expect_lines| {
@@ -2003,7 +2037,7 @@ fn checkCompileErrors(compile: *Compile) !void {
try expected_generated.append('\n');
}
- if (mem.eql(u8, expected_generated.items, actual_stderr)) return;
+ if (mem.eql(u8, expected_generated.items, actual_errors)) return;
return compile.step.fail(
\\
@@ -2012,7 +2046,7 @@ fn checkCompileErrors(compile: *Compile) !void {
\\========= but found: ====================
\\{s}
\\=========================================
- , .{ expected_generated.items, actual_stderr });
+ , .{ expected_generated.items, actual_errors });
},
}
}