Skip to content

Commit 562a71b

Browse files
committed
docgen: avoid use of --enable-cache
1 parent 19ef5b0 commit 562a71b

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

doc/docgen.zig

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ const Code = struct {
325325
link_objects: []const []const u8,
326326
target_str: ?[]const u8,
327327
link_libc: bool,
328-
backend_stage1: bool,
329328
link_mode: ?std.builtin.LinkMode,
330329
disable_cache: bool,
331330
verbose_cimport: bool,
@@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
596595
var link_mode: ?std.builtin.LinkMode = null;
597596
var disable_cache = false;
598597
var verbose_cimport = false;
599-
var backend_stage1 = false;
600598
var additional_options = std.ArrayList([]const u8).init(allocator);
601599
defer additional_options.deinit();
602600

@@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
631629
link_libc = true;
632630
} else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
633631
link_mode = .Dynamic;
634-
} else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
635-
backend_stage1 = true;
636632
} else if (mem.eql(u8, end_tag_name, "additonal_option")) {
637633
_ = try eatToken(tokenizer, Token.Id.Separator);
638634
const option = try eatToken(tokenizer, Token.Id.TagContent);
@@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
660656
.link_objects = try link_objects.toOwnedSlice(),
661657
.target_str = target_str,
662658
.link_libc = link_libc,
663-
.backend_stage1 = backend_stage1,
664659
.link_mode = link_mode,
665660
.disable_cache = disable_cache,
666661
.verbose_cimport = verbose_cimport,
@@ -1380,10 +1375,10 @@ fn genHtml(
13801375
var build_args = std.ArrayList([]const u8).init(allocator);
13811376
defer build_args.deinit();
13821377
try build_args.appendSlice(&[_][]const u8{
1383-
zig_exe, "build-exe",
1384-
"--name", code.name,
1385-
"--color", "on",
1386-
"--enable-cache", tmp_source_file_name,
1378+
zig_exe, "build-exe",
1379+
"--name", code.name,
1380+
"--color", "on",
1381+
name_plus_ext,
13871382
});
13881383
if (opt_zig_lib_dir) |zig_lib_dir| {
13891384
try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir });
@@ -1400,21 +1395,13 @@ fn genHtml(
14001395
}
14011396
for (code.link_objects) |link_object| {
14021397
const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext });
1403-
const full_path_object = try fs.path.join(
1404-
allocator,
1405-
&[_][]const u8{ tmp_dir_name, name_with_ext },
1406-
);
1407-
try build_args.append(full_path_object);
1398+
try build_args.append(name_with_ext);
14081399
try shell_out.print("{s} ", .{name_with_ext});
14091400
}
14101401
if (code.link_libc) {
14111402
try build_args.append("-lc");
14121403
try shell_out.print("-lc ", .{});
14131404
}
1414-
if (code.backend_stage1) {
1415-
try build_args.append("-fstage1");
1416-
try shell_out.print("-fstage1", .{});
1417-
}
14181405
const target = try std.zig.CrossTarget.parse(.{
14191406
.arch_os_abi = code.target_str orelse "native",
14201407
});
@@ -1461,7 +1448,7 @@ fn genHtml(
14611448
try shell_out.writeAll(colored_stderr);
14621449
break :code_block;
14631450
}
1464-
const exec_result = exec(allocator, &env_map, build_args.items) catch
1451+
const exec_result = exec(allocator, &env_map, tmp_dir_name, build_args.items) catch
14651452
return parseError(tokenizer, code.source_token, "example failed to compile", .{});
14661453

14671454
if (code.verbose_cimport) {
@@ -1480,15 +1467,10 @@ fn genHtml(
14801467
}
14811468
}
14821469

1483-
const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
1484-
const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{
1470+
const path_to_exe = try std.fmt.allocPrint(allocator, "./{s}{s}", .{
14851471
code.name,
14861472
target.exeFileExt(),
14871473
});
1488-
const path_to_exe = try fs.path.join(allocator, &[_][]const u8{
1489-
path_to_exe_dir,
1490-
path_to_exe_basename,
1491-
});
14921474
const run_args = &[_][]const u8{path_to_exe};
14931475

14941476
var exited_with_signal = false;
@@ -1498,6 +1480,7 @@ fn genHtml(
14981480
.allocator = allocator,
14991481
.argv = run_args,
15001482
.env_map = &env_map,
1483+
.cwd = tmp_dir_name,
15011484
.max_output_bytes = max_doc_file_size,
15021485
});
15031486
switch (result.term) {
@@ -1514,7 +1497,7 @@ fn genHtml(
15141497
}
15151498
break :blk result;
15161499
} else blk: {
1517-
break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
1500+
break :blk exec(allocator, &env_map, tmp_dir_name, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
15181501
};
15191502

15201503
const escaped_stderr = try escapeHtml(allocator, result.stderr);
@@ -1555,10 +1538,6 @@ fn genHtml(
15551538
try test_args.append("-lc");
15561539
try shell_out.print("-lc ", .{});
15571540
}
1558-
if (code.backend_stage1) {
1559-
try test_args.append("-fstage1");
1560-
try shell_out.print("-fstage1", .{});
1561-
}
15621541
if (code.target_str) |triple| {
15631542
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
15641543
try shell_out.print("-target {s} ", .{triple});
@@ -1579,7 +1558,7 @@ fn genHtml(
15791558
},
15801559
}
15811560
}
1582-
const result = exec(allocator, &env_map, test_args.items) catch
1561+
const result = exec(allocator, &env_map, null, test_args.items) catch
15831562
return parseError(tokenizer, code.source_token, "test failed", .{});
15841563
const escaped_stderr = try escapeHtml(allocator, result.stderr);
15851564
const escaped_stdout = try escapeHtml(allocator, result.stdout);
@@ -1610,10 +1589,6 @@ fn genHtml(
16101589
try test_args.append("-lc");
16111590
try shell_out.print("-lc ", .{});
16121591
}
1613-
if (code.backend_stage1) {
1614-
try test_args.append("-fstage1");
1615-
try shell_out.print("-fstage1", .{});
1616-
}
16171592
const result = try ChildProcess.exec(.{
16181593
.allocator = allocator,
16191594
.argv = test_args.items,
@@ -1778,7 +1753,7 @@ fn genHtml(
17781753
const colored_stderr = try termColor(allocator, escaped_stderr);
17791754
try shell_out.print("\n{s} ", .{colored_stderr});
17801755
} else {
1781-
_ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
1756+
_ = exec(allocator, &env_map, null, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
17821757
}
17831758
try shell_out.writeAll("\n");
17841759
},
@@ -1831,7 +1806,7 @@ fn genHtml(
18311806
try test_args.append(option);
18321807
try shell_out.print("{s} ", .{option});
18331808
}
1834-
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1809+
const result = exec(allocator, &env_map, null, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
18351810
const escaped_stderr = try escapeHtml(allocator, result.stderr);
18361811
const escaped_stdout = try escapeHtml(allocator, result.stdout);
18371812
try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
@@ -1846,11 +1821,17 @@ fn genHtml(
18461821
}
18471822
}
18481823

1849-
fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult {
1824+
fn exec(
1825+
allocator: Allocator,
1826+
env_map: *process.EnvMap,
1827+
cwd: ?[]const u8,
1828+
args: []const []const u8,
1829+
) !ChildProcess.ExecResult {
18501830
const result = try ChildProcess.exec(.{
18511831
.allocator = allocator,
18521832
.argv = args,
18531833
.env_map = env_map,
1834+
.cwd = cwd,
18541835
.max_output_bytes = max_doc_file_size,
18551836
});
18561837
switch (result.term) {
@@ -1877,12 +1858,12 @@ fn getBuiltinCode(
18771858
opt_zig_lib_dir: ?[]const u8,
18781859
) ![]const u8 {
18791860
if (opt_zig_lib_dir) |zig_lib_dir| {
1880-
const result = try exec(allocator, env_map, &.{
1861+
const result = try exec(allocator, env_map, null, &.{
18811862
zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir,
18821863
});
18831864
return result.stdout;
18841865
} else {
1885-
const result = try exec(allocator, env_map, &.{
1866+
const result = try exec(allocator, env_map, null, &.{
18861867
zig_exe, "build-obj", "--show-builtin",
18871868
});
18881869
return result.stdout;

0 commit comments

Comments
 (0)