Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove --enable-cache option; std.Build.CompileStep: remove output_dir #15234

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 21 additions & 40 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ const Code = struct {
link_objects: []const []const u8,
target_str: ?[]const u8,
link_libc: bool,
backend_stage1: bool,
link_mode: ?std.builtin.LinkMode,
disable_cache: bool,
verbose_cimport: bool,
Expand Down Expand Up @@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
var link_mode: ?std.builtin.LinkMode = null;
var disable_cache = false;
var verbose_cimport = false;
var backend_stage1 = false;
var additional_options = std.ArrayList([]const u8).init(allocator);
defer additional_options.deinit();

Expand Down Expand Up @@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
link_libc = true;
} else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
link_mode = .Dynamic;
} else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
backend_stage1 = true;
} else if (mem.eql(u8, end_tag_name, "additonal_option")) {
_ = try eatToken(tokenizer, Token.Id.Separator);
const option = try eatToken(tokenizer, Token.Id.TagContent);
Expand Down Expand Up @@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
.link_objects = try link_objects.toOwnedSlice(),
.target_str = target_str,
.link_libc = link_libc,
.backend_stage1 = backend_stage1,
.link_mode = link_mode,
.disable_cache = disable_cache,
.verbose_cimport = verbose_cimport,
Expand Down Expand Up @@ -1380,10 +1375,10 @@ fn genHtml(
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
try build_args.appendSlice(&[_][]const u8{
zig_exe, "build-exe",
"--name", code.name,
"--color", "on",
"--enable-cache", tmp_source_file_name,
zig_exe, "build-exe",
"--name", code.name,
"--color", "on",
name_plus_ext,
});
if (opt_zig_lib_dir) |zig_lib_dir| {
try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir });
Expand All @@ -1400,21 +1395,13 @@ fn genHtml(
}
for (code.link_objects) |link_object| {
const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext });
const full_path_object = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_with_ext },
);
try build_args.append(full_path_object);
try build_args.append(name_with_ext);
try shell_out.print("{s} ", .{name_with_ext});
}
if (code.link_libc) {
try build_args.append("-lc");
try shell_out.print("-lc ", .{});
}
if (code.backend_stage1) {
try build_args.append("-fstage1");
try shell_out.print("-fstage1", .{});
}
const target = try std.zig.CrossTarget.parse(.{
.arch_os_abi = code.target_str orelse "native",
});
Expand Down Expand Up @@ -1461,7 +1448,7 @@ fn genHtml(
try shell_out.writeAll(colored_stderr);
break :code_block;
}
const exec_result = exec(allocator, &env_map, build_args.items) catch
const exec_result = exec(allocator, &env_map, tmp_dir_name, build_args.items) catch
return parseError(tokenizer, code.source_token, "example failed to compile", .{});

if (code.verbose_cimport) {
Expand All @@ -1480,15 +1467,10 @@ fn genHtml(
}
}

const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{
const path_to_exe = try std.fmt.allocPrint(allocator, "./{s}{s}", .{
code.name,
target.exeFileExt(),
});
const path_to_exe = try fs.path.join(allocator, &[_][]const u8{
path_to_exe_dir,
path_to_exe_basename,
});
const run_args = &[_][]const u8{path_to_exe};

var exited_with_signal = false;
Expand All @@ -1498,6 +1480,7 @@ fn genHtml(
.allocator = allocator,
.argv = run_args,
.env_map = &env_map,
.cwd = tmp_dir_name,
.max_output_bytes = max_doc_file_size,
});
switch (result.term) {
Expand All @@ -1514,7 +1497,7 @@ fn genHtml(
}
break :blk result;
} else blk: {
break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
break :blk exec(allocator, &env_map, tmp_dir_name, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
};

const escaped_stderr = try escapeHtml(allocator, result.stderr);
Expand Down Expand Up @@ -1555,10 +1538,6 @@ fn genHtml(
try test_args.append("-lc");
try shell_out.print("-lc ", .{});
}
if (code.backend_stage1) {
try test_args.append("-fstage1");
try shell_out.print("-fstage1", .{});
}
if (code.target_str) |triple| {
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
try shell_out.print("-target {s} ", .{triple});
Expand All @@ -1579,7 +1558,7 @@ fn genHtml(
},
}
}
const result = exec(allocator, &env_map, test_args.items) catch
const result = exec(allocator, &env_map, null, test_args.items) catch
return parseError(tokenizer, code.source_token, "test failed", .{});
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const escaped_stdout = try escapeHtml(allocator, result.stdout);
Expand Down Expand Up @@ -1610,10 +1589,6 @@ fn genHtml(
try test_args.append("-lc");
try shell_out.print("-lc ", .{});
}
if (code.backend_stage1) {
try test_args.append("-fstage1");
try shell_out.print("-fstage1", .{});
}
const result = try ChildProcess.exec(.{
.allocator = allocator,
.argv = test_args.items,
Expand Down Expand Up @@ -1778,7 +1753,7 @@ fn genHtml(
const colored_stderr = try termColor(allocator, escaped_stderr);
try shell_out.print("\n{s} ", .{colored_stderr});
} else {
_ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
_ = exec(allocator, &env_map, null, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
}
try shell_out.writeAll("\n");
},
Expand Down Expand Up @@ -1831,7 +1806,7 @@ fn genHtml(
try test_args.append(option);
try shell_out.print("{s} ", .{option});
}
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
const result = exec(allocator, &env_map, null, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const escaped_stdout = try escapeHtml(allocator, result.stdout);
try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
Expand All @@ -1846,11 +1821,17 @@ fn genHtml(
}
}

fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult {
fn exec(
allocator: Allocator,
env_map: *process.EnvMap,
cwd: ?[]const u8,
args: []const []const u8,
) !ChildProcess.ExecResult {
const result = try ChildProcess.exec(.{
.allocator = allocator,
.argv = args,
.env_map = env_map,
.cwd = cwd,
.max_output_bytes = max_doc_file_size,
});
switch (result.term) {
Expand All @@ -1877,12 +1858,12 @@ fn getBuiltinCode(
opt_zig_lib_dir: ?[]const u8,
) ![]const u8 {
if (opt_zig_lib_dir) |zig_lib_dir| {
const result = try exec(allocator, env_map, &.{
const result = try exec(allocator, env_map, null, &.{
zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir,
});
return result.stdout;
} else {
const result = try exec(allocator, env_map, &.{
const result = try exec(allocator, env_map, null, &.{
zig_exe, "build-obj", "--show-builtin",
});
return result.stdout;
Expand Down
4 changes: 4 additions & 0 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ pub const TestOptions = struct {
optimize: std.builtin.Mode = .Debug,
version: ?std.builtin.Version = null,
max_rss: usize = 0,
filter: ?[]const u8 = null,
test_runner: ?[]const u8 = null,
};

pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
Expand All @@ -549,6 +551,8 @@ pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
.target = options.target,
.optimize = options.optimize,
.max_rss = options.max_rss,
.filter = options.filter,
.test_runner = options.test_runner,
});
}

Expand Down
Loading