Skip to content

Commit 21f006a

Browse files
ehaasadhanali
andcommitted
stdlib: Add test for generating HEX files.
Co-authored-by: Akbar Dhanaliwala <[email protected]>
1 parent f59176e commit 21f006a

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

lib/std/build/InstallRawStep.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ artifact: *LibExeObjStep,
347347
dest_dir: InstallDir,
348348
dest_filename: []const u8,
349349
format: RawFormat,
350+
output_file: std.build.GeneratedFile,
350351

351352
fn detectFormat(filename: []const u8) RawFormat {
352353
if (std.mem.endsWith(u8, filename, ".hex") or std.mem.endsWith(u8, filename, ".ihex")) {
@@ -369,13 +370,18 @@ pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []cons
369370
},
370371
.dest_filename = dest_filename,
371372
.format = if (format) |f| f else detectFormat(dest_filename),
373+
.output_file = std.build.GeneratedFile{ .step = &self.step },
372374
};
373375
self.step.dependOn(&artifact.step);
374376

375377
builder.pushInstalledFile(self.dest_dir, dest_filename);
376378
return self;
377379
}
378380

381+
pub fn getOutputSource(self: *const InstallRawStep) std.build.FileSource {
382+
return std.build.FileSource{ .generated = &self.output_file };
383+
}
384+
379385
fn make(step: *Step) !void {
380386
const self = @fieldParentPtr(InstallRawStep, "step", step);
381387
const builder = self.builder;
@@ -390,6 +396,7 @@ fn make(step: *Step) !void {
390396

391397
fs.cwd().makePath(builder.getInstallPath(self.dest_dir, "")) catch unreachable;
392398
try emitRaw(builder.allocator, full_src_path, full_dest_path, self.format);
399+
self.output_file.path = full_dest_path;
393400
}
394401

395402
test {

test/standalone.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
2626
cases.addBuildFile("test/standalone/brace_expansion/build.zig", .{});
2727
cases.addBuildFile("test/standalone/empty_env/build.zig", .{});
2828
cases.addBuildFile("test/standalone/issue_7030/build.zig", .{});
29+
cases.addBuildFile("test/standalone/install_raw_hex/build.zig", .{});
2930
if (std.Target.current.os.tag != .wasi) {
3031
cases.addBuildFile("test/standalone/load_dynamic_library/build.zig", .{});
3132
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
const Builder = @import("std").build.Builder;
2+
const builtin = @import("builtin");
3+
const std = @import("std");
4+
const CheckFileStep = std.build.CheckFileStep;
5+
6+
pub fn build(b: *Builder) void {
7+
const target = .{
8+
.cpu_arch = .thumb,
9+
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 },
10+
.os_tag = .freestanding,
11+
.abi = .gnueabihf,
12+
};
13+
14+
const mode = b.standardReleaseOptions();
15+
16+
const elf = b.addExecutable("zig-nrf52-blink.elf", "main.zig");
17+
elf.setTarget(target);
18+
elf.setBuildMode(mode);
19+
20+
const test_step = b.step("test", "Test the program");
21+
b.default_step.dependOn(test_step);
22+
23+
const hex_step = b.addInstallRaw(elf, "hello.hex");
24+
test_step.dependOn(&hex_step.step);
25+
26+
const explicit_format_hex_step = b.addInstallRawWithFormat(elf, "hello.foo", .hex);
27+
test_step.dependOn(&explicit_format_hex_step.step);
28+
29+
const expected_hex = &[_][]const u8{
30+
\\:020000021000EC
31+
\\:1000D400D001010001000000D20101000100000074
32+
\\:1000E40028020100010000002402010001000000B8
33+
\\:1000F4003A02010001000000E202010001000000D8
34+
\\:100104000C03010001000000A50202000000000031
35+
\\:1001140000000000000000000000000000000000DB
36+
\\:1001240000000000000000000000000000000000CB
37+
\\:1001340000000000000000000000000000000000BB
38+
\\:10014400AF02020098020100090000004D02010004
39+
\\:100154000900000001000000000000000000000091
40+
\\:100164000004000100C0800000020000080000003C
41+
\\:100174000000000000000000000000001E0000005D
42+
\\:1001840048010100000040888080FF000A14002913
43+
\\:1001940000C0B00000020090080000000000000051
44+
\\:1001A40000000000000000001E000000000000002D
45+
\\:1001B400000000000000000000000000000000003B
46+
\\:1001C400000000000000000000000000000000002B
47+
\\:1001D400000000000000000000000000000000001B
48+
\\:1001E400000000000000000000000000000000000B
49+
\\:1001F4000000000000000000000000008702010071
50+
\\:1002040010000000200201002C0000006B0201001D
51+
\\:100214001B000000570201001300000072656D61AD
52+
\\:10022400696E646572206469766973696F6E2062B1
53+
\\:1002340079207A65726F206F72206E6567617469C8
54+
\\:1002440076652076616C756500636F727465782DD0
55+
\\:100254006D3400696E646578206F7574206F662054
56+
\\:10026400626F756E647300696E746567657220638E
57+
\\:10027400617374207472756E63617465642062695D
58+
\\:100284007473006469766973696F6E206279207A89
59+
\\:1002940065726F00636F727465785F6D340000007F
60+
\\:1002A40081B00091FFE700BEFDE7D0B502AF90B08A
61+
\\:1002B4000391029007A800F029F803990020069002
62+
\\:1002C40048680490FFE704990698019088420FD289
63+
\\:1002D400FFE7019903980068405C07F8310C17F8B0
64+
\\:1002E400311C07A800F021F8019801300690EAE7D4
65+
\\:1002F400029807A9B1E80C50A0E80C5091E81C50F2
66+
\\:1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7
67+
\\:1003140040F2DC11C0F20101B1E80C50A0E80C502D
68+
\\:1003240091E81C5080E81C50D0BD80B56F4688B061
69+
\\:1003340006906FF35F2127F80A1C37F80A0C049023
70+
\\:10034400012038B9FFE740F20020C0F2010000218B
71+
\\:10035400FFF7A6FF0498C0F3431027F8020C37F800
72+
\\:100364000A0C0390002038B9FFE7039800F01F003F
73+
\\:100374000290012038B914E040F20820C0F20100D4
74+
\\:100384000021FFF78DFF029800F01F0007F8030C0F
75+
\\:100394000698009037F8020C0146019109280ED303
76+
\\:1003A40006E040F21020C0F201000021FFF778FFC0
77+
\\:1003B40040F21820C0F201000021FFF771FF0099FC
78+
\\:1003C400019A51F8220017F803CC012303FA0CF325
79+
\\:1003D400184341F8220008B080BD81B000F03F000E
80+
\\:1003E4008DF802009DF80200103000F03F00022852
81+
\\:1003F40004D3FFE700208DF8030003E001208DF80B
82+
\\:100404000300FFE79DF8030001B070470A000000F5
83+
\\:1004140012000000020071001200000066000000DB
84+
\\:1004240003007D0C06000000000000000001110123
85+
\\:10043400250E1305030E10171B0EB44219110112D9
86+
\\:0604440006000002340076
87+
\\:020000021000EC
88+
\\:1000D400D001010001000000D20101000100000074
89+
\\:1000E40028020100010000002402010001000000B8
90+
\\:1000F4003A02010001000000E202010001000000D8
91+
\\:100104000C03010001000000A50202000000000031
92+
\\:1001140000000000000000000000000000000000DB
93+
\\:1001240000000000000000000000000000000000CB
94+
\\:1001340000000000000000000000000000000000BB
95+
\\:10014400AF02020098020100090000004D02010004
96+
\\:100154000900000001000000000000000000000091
97+
\\:100164000004000100C0800000020000080000003C
98+
\\:100174000000000000000000000000001E0000005D
99+
\\:1001840048010100000040888080FF000A14002913
100+
\\:1001940000C0B00000020090080000000000000051
101+
\\:1001A40000000000000000001E000000000000002D
102+
\\:1001B400000000000000000000000000000000003B
103+
\\:1001C400000000000000000000000000000000002B
104+
\\:1001D400000000000000000000000000000000001B
105+
\\:1001E400000000000000000000000000000000000B
106+
\\:1001F4000000000000000000000000008702010071
107+
\\:1002040010000000200201002C0000006B0201001D
108+
\\:100214001B000000570201001300000072656D61AD
109+
\\:10022400696E646572206469766973696F6E2062B1
110+
\\:1002340079207A65726F206F72206E6567617469C8
111+
\\:1002440076652076616C756500636F727465782DD0
112+
\\:100254006D3400696E646578206F7574206F662054
113+
\\:10026400626F756E647300696E746567657220638E
114+
\\:10027400617374207472756E63617465642062695D
115+
\\:100284007473006469766973696F6E206279207A89
116+
\\:1002940065726F00636F727465785F6D340000007F
117+
\\:1002A40081B00091FFE700BEFDE7D0B502AF90B08A
118+
\\:1002B4000391029007A800F029F803990020069002
119+
\\:1002C40048680490FFE704990698019088420FD289
120+
\\:1002D400FFE7019903980068405C07F8310C17F8B0
121+
\\:1002E400311C07A800F021F8019801300690EAE7D4
122+
\\:1002F400029807A9B1E80C50A0E80C5091E81C50F2
123+
\\:1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7
124+
\\:1003140040F2DC11C0F20101B1E80C50A0E80C502D
125+
\\:1003240091E81C5080E81C50D0BD80B56F4688B061
126+
\\:1003340006906FF35F2127F80A1C37F80A0C049023
127+
\\:10034400012038B9FFE740F20020C0F2010000218B
128+
\\:10035400FFF7A6FF0498C0F3431027F8020C37F800
129+
\\:100364000A0C0390002038B9FFE7039800F01F003F
130+
\\:100374000290012038B914E040F20820C0F20100D4
131+
\\:100384000021FFF78DFF029800F01F0007F8030C0F
132+
\\:100394000698009037F8020C0146019109280ED303
133+
\\:1003A40006E040F21020C0F201000021FFF778FFC0
134+
\\:1003B40040F21820C0F201000021FFF771FF0099FC
135+
\\:1003C400019A51F8220017F803CC012303FA0CF325
136+
\\:1003D400184341F8220008B080BD81B000F03F000E
137+
\\:1003E4008DF802009DF80200103000F03F00022852
138+
\\:1003F40004D3FFE700208DF8030003E001208DF80B
139+
\\:100404000300FFE79DF8030001B070470A000000F5
140+
\\:1004140012000000020071001200000066000000DB
141+
\\:1004240003007D0C06000000000000000001110123
142+
\\:10043400250E1305030E10171B0EB44219110112D9
143+
\\:0604440006000002340076
144+
\\:020000022000DC
145+
\\:1002A40081B00091FFE700BEFDE7D0B502AF90B08A
146+
\\:1002B4000391029007A800F029F803990020069002
147+
\\:1002C40048680490FFE704990698019088420FD289
148+
\\:1002D400FFE7019903980068405C07F8310C17F8B0
149+
\\:1002E400311C07A800F021F8019801300690EAE7D4
150+
\\:1002F400029807A9B1E80C50A0E80C5091E81C50F2
151+
\\:1003040080E81C5010B0D0BDFFE7FEE7D0B502AFC7
152+
\\:1003140040F2DC11C0F20101B1E80C50A0E80C502D
153+
\\:1003240091E81C5080E81C50D0BD80B56F4688B061
154+
\\:1003340006906FF35F2127F80A1C37F80A0C049023
155+
\\:10034400012038B9FFE740F20020C0F2010000218B
156+
\\:10035400FFF7A6FF0498C0F3431027F8020C37F800
157+
\\:100364000A0C0390002038B9FFE7039800F01F003F
158+
\\:100374000290012038B914E040F20820C0F20100D4
159+
\\:100384000021FFF78DFF029800F01F0007F8030C0F
160+
\\:100394000698009037F8020C0146019109280ED303
161+
\\:1003A40006E040F21020C0F201000021FFF778FFC0
162+
\\:1003B40040F21820C0F201000021FFF771FF0099FC
163+
\\:1003C400019A51F8220017F803CC012303FA0CF325
164+
\\:1003D400184341F8220008B080BD81B000F03F000E
165+
\\:1003E4008DF802009DF80200103000F03F00022852
166+
\\:1003F40004D3FFE700208DF8030003E001208DF80B
167+
\\:0C0404000300FFE79DF8030001B0704703
168+
\\:00000001FF
169+
};
170+
171+
test_step.dependOn(&CheckFileStep.create(b, hex_step.getOutputSource(), expected_hex).step);
172+
test_step.dependOn(&CheckFileStep.create(b, explicit_format_hex_step.getOutputSource(), expected_hex).step);
173+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export fn _start() callconv(.C) noreturn {
2+
while (true) {}
3+
}

0 commit comments

Comments
 (0)