Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
220 lines (210 loc) · 8.84 KB
/
Copy pathbuild.zig
File metadata and controls
220 lines (210 loc) · 8.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
const std = @import("std");
const build_runner = @import("src/build_runner.zig");
// Re-export the zbuild API so dependents can use @import("zbuild").configureBuild
pub const configureBuild = build_runner.configureBuild;
pub const Options = build_runner.Options;
pub const BuildResult = build_runner.BuildResult;
const FixtureCommand = struct {
name: []const u8,
cwd: []const u8,
build_args: []const []const u8 = &.{},
expect_exit: u8 = 0,
stdout_match: ?[]const u8 = null,
stderr_match: ?[]const u8 = null,
};
fn addFixtureCommand(b: *std.Build, aggregate: *std.Build.Step, command: FixtureCommand) void {
const run = b.addSystemCommand(&.{ b.graph.zig_exe, "build" });
run.has_side_effects = true;
run.addArgs(command.build_args);
run.setCwd(b.path(command.cwd));
run.expectExitCode(command.expect_exit);
if (command.stdout_match) |expected| run.expectStdOutMatch(expected);
if (command.stderr_match) |expected| run.expectStdErrMatch(expected);
const step = b.step(
b.fmt("test:fixture:{s}", .{command.name}),
b.fmt("Run fixture check {s}", .{command.name}),
);
step.dependOn(&run.step);
aggregate.dependOn(&run.step);
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// zbuild library module (for use by zbuild-powered projects)
const zbuild_module = b.addModule("zbuild", .{
.root_source_file = b.path("src/build_runner.zig"),
.target = target,
.optimize = optimize,
});
// Tests
const tls_run_test = b.step("test", "Run all tests");
const test_zbuild = b.addTest(.{
.name = "zbuild",
.root_module = zbuild_module,
.filters = b.option([]const []const u8, "zbuild.filters", "zbuild test filters") orelse &.{},
});
const run_test_zbuild = b.addRunArtifact(test_zbuild);
const tls_test_zbuild = b.step("test:zbuild", "Run the zbuild tests");
tls_test_zbuild.dependOn(&run_test_zbuild.step);
tls_run_test.dependOn(&run_test_zbuild.step);
const tls_test_fixtures = b.step("test:fixtures", "Run fixture integration tests");
tls_run_test.dependOn(tls_test_fixtures);
addFixtureCommand(b, tls_test_fixtures, .{
.name = "examples-full-build",
.cwd = "examples/full",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "examples-full-info",
.cwd = "examples/full",
.build_args = &.{"info"},
.stdout_match = "full_example v1.0.0",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "manual-interop-build",
.cwd = "test/fixtures/manual_interop",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "manual-interop-run",
.cwd = "test/fixtures/manual_interop",
.build_args = &.{"run:myapp"},
.stderr_match = "manual manual",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "manual-interop-cmd",
.cwd = "test/fixtures/manual_interop",
.build_args = &.{"cmd:demo"},
.stdout_match = "manual interop ok",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "undeclared-external-module",
.cwd = "test/fixtures/undeclared_external_module",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "undeclared-external-step",
.cwd = "test/fixtures/undeclared_external_step",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "manual-step-named-test",
.cwd = "test/fixtures/manual_step_named_test",
.build_args = &.{"cmd:demo"},
.stdout_match = "manual test step ok",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "aliases-nested",
.cwd = "test/fixtures/aliases_nested",
.build_args = &.{"check"},
.stderr_match = "alias fixture ok",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "presets-prod",
.cwd = "test/fixtures/presets",
.build_args = &.{ "run:demo", "-Dpreset=prod" },
.stderr_match = "level=warn tracing=false asset=dist/prod",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "presets-cli-override",
.cwd = "test/fixtures/presets",
.build_args = &.{ "run:demo", "-Dpreset=prod", "-Dconfig.log_level=debug" },
.stderr_match = "level=debug tracing=false asset=dist/prod",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "presets-invalid-name",
.cwd = "test/fixtures/presets",
.build_args = &.{ "run:demo", "-Dpreset=missing" },
.expect_exit = 1,
.stderr_match = "invalid value for -Dpreset: 'missing'",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "manual-module-collision",
.cwd = "test/fixtures/manual_module_collision",
.expect_exit = 1,
.stderr_match = "named module 'core' collides with an existing module registered before configureBuild",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "manual-step-collision",
.cwd = "test/fixtures/manual_step_collision",
.expect_exit = 1,
.stderr_match = "run command step 'cmd:demo' collides with an existing top-level step registered before configureBuild",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "import-namespace-named-options-collision",
.cwd = "test/fixtures/import_namespace_named_options_collision",
.expect_exit = 1,
.stderr_match = "options module 'config' collides with another zbuild-owned import name (named module)",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "import-namespace-dependency-default-collision",
.cwd = "test/fixtures/import_namespace_dependency_default_collision",
.expect_exit = 1,
.stderr_match = "dependency default module 'dep_pkg' collides with another zbuild-owned import name (options module)",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "inline-name-collision",
.cwd = "test/fixtures/inline_name_collision",
.expect_exit = 2,
.stderr_match = "collides with named module",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "dependency-bad-import",
.cwd = "test/fixtures/dependency_bad_import",
.expect_exit = 1,
.stderr_match = "could not resolve module 'missing' from dependency 'dep_pkg'",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "dependency-bad-lazy-path",
.cwd = "test/fixtures/dependency_bad_lazy_path",
.expect_exit = 1,
.stderr_match = "could not resolve named lazy path 'missing' from dependency 'dep_pkg'",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "dependency-explicit-args",
.cwd = "test/fixtures/dependency_explicit_args",
// Use uncommon target queries for distinguishability on
// common host machines
.build_args = &.{ "-Dtarget=powerpc64-linux-none", "-Doptimize=ReleaseSafe" },
.stderr_match =
\\dep arch=powerpc64 os=linux abi=none optimize=ReleaseFast portable=true
\\dep arch=mips64 os=linux abi=none optimize=ReleaseFast portable=true
,
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "root-module-string-options-module",
.cwd = "test/fixtures/root_module_string_options_module",
.expect_exit = 2,
.stderr_match = "options module 'config' is import-only and cannot be used as root_module",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "duplicate-installable-artifact-name",
.cwd = "test/fixtures/duplicate_installable_artifact_name",
.expect_exit = 2,
.stderr_match = "installable artifact names must be unique",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "alias-empty-depends-on",
.cwd = "test/fixtures/alias_empty_depends_on",
.expect_exit = 2,
.stderr_match = "aliases 'check': depends_on must not be empty",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "preset-unknown-option",
.cwd = "test/fixtures/preset_unknown_option",
.expect_exit = 2,
.stderr_match = "presets 'dev.config': unknown option 'missing'",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "invalid-optimize",
.cwd = "test/fixtures/invalid_optimize",
.expect_exit = 2,
.stderr_match = "executables 'demo': invalid optimize '.Release'",
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "stdlib-passthrough-library",
.cwd = "test/fixtures/stdlib_passthrough",
.build_args = &.{"build-lib:mylib"},
});
addFixtureCommand(b, tls_test_fixtures, .{
.name = "stdlib-passthrough-test",
.cwd = "test/fixtures/stdlib_passthrough",
.build_args = &.{"build-test:unit"},
});
}