authorgravatar for lacc97@protonmail.chLuis Cáceres <lacc97@protonmail.ch> 2023-09-28 23:30:42+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-09-28 19:30:42-04:00
logacac685621fc427e4e962f9b54b7f822a3d00dd0
tree465d2bb87c4d463b45737c3698929eed22f5048f
parent8f2f12f94080ede762df4a5018249160eedc7f09
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.Build.ConfigHeader: override include guard option for blank style (#17310)

This commit adds an option to allow for overriding the default header guard that is generated from the output file path.

1 files changed, 15 insertions(+), 8 deletions(-)

lib/std/Build/Step/ConfigHeader.zig+15-8
...@@ -42,6 +42,7 @@ output_file: std.Build.GeneratedFile,...@@ -42,6 +42,7 @@ output_file: std.Build.GeneratedFile,
42style: Style,42style: Style,
43max_bytes: usize,43max_bytes: usize,
44include_path: []const u8,44include_path: []const u8,
45include_guard_override: ?[]const u8,
4546
46pub const base_id: Step.Id = .config_header;47pub const base_id: Step.Id = .config_header;
4748
...@@ -50,6 +51,7 @@ pub const Options = struct {...@@ -50,6 +51,7 @@ pub const Options = struct {
50 max_bytes: usize = 2 * 1024 * 1024,51 max_bytes: usize = 2 * 1024 * 1024,
51 include_path: ?[]const u8 = null,52 include_path: ?[]const u8 = null,
52 first_ret_addr: ?usize = null,53 first_ret_addr: ?usize = null,
54 include_guard_override: ?[]const u8 = null,
53};55};
5456
55pub fn create(owner: *std.Build, options: Options) *ConfigHeader {57pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
...@@ -91,6 +93,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {...@@ -91,6 +93,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
9193
92 .max_bytes = options.max_bytes,94 .max_bytes = options.max_bytes,
93 .include_path = include_path,95 .include_path = include_path,
96 .include_guard_override = options.include_guard_override,
94 .output_file = .{ .step = &self.step },97 .output_file = .{ .step = &self.step },
95 };98 };
9699
...@@ -201,7 +204,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -201,7 +204,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
201 },204 },
202 .blank => {205 .blank => {
203 try output.appendSlice(c_generated_line);206 try output.appendSlice(c_generated_line);
204 try render_blank(&output, self.values, self.include_path);207 try render_blank(&output, self.values, self.include_path, self.include_guard_override);
205 },208 },
206 .nasm => {209 .nasm => {
207 try output.appendSlice(asm_generated_line);210 try output.appendSlice(asm_generated_line);
...@@ -415,15 +418,19 @@ fn render_blank(...@@ -415,15 +418,19 @@ fn render_blank(
415 output: *std.ArrayList(u8),418 output: *std.ArrayList(u8),
416 defines: std.StringArrayHashMap(Value),419 defines: std.StringArrayHashMap(Value),
417 include_path: []const u8,420 include_path: []const u8,
421 include_guard_override: ?[]const u8,
418) !void {422) !void {
419 const include_guard_name = try output.allocator.dupe(u8, include_path);423 const include_guard_name = include_guard_override orelse blk: {
420 for (include_guard_name) |*byte| {424 const name = try output.allocator.dupe(u8, include_path);
421 switch (byte.*) {425 for (name) |*byte| {
422 'a'...'z' => byte.* = byte.* - 'a' + 'A',426 switch (byte.*) {
423 'A'...'Z', '0'...'9' => continue,427 'a'...'z' => byte.* = byte.* - 'a' + 'A',
424 else => byte.* = '_',428 'A'...'Z', '0'...'9' => continue,
429 else => byte.* = '_',
430 }
425 }431 }
426 }432 break :blk name;
433 };
427434
428 try output.appendSlice("#ifndef ");435 try output.appendSlice("#ifndef ");
429 try output.appendSlice(include_guard_name);436 try output.appendSlice(include_guard_name);