Skip to content

Commit 599aaa3

Browse files
committed
ci: test dependency overriding
1 parent 1b7f96f commit 599aaa3

File tree

23 files changed

+211
-0
lines changed

23 files changed

+211
-0
lines changed

ci/aarch64-linux-debug.sh

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ stage3-debug/bin/zig build test docs \
6464
--zig-lib-dir "$PWD/../lib" \
6565
-Denable-tidy
6666

67+
# Ensure that dependency overrides function correctly
68+
wd=$PWD
69+
70+
cd ../test/dependency_override
71+
./run-tests.sh ../../build-debug/stage3-debug/bin/zig
72+
cd $wd
73+
74+
unset wd
75+
6776
# Ensure that updating the wasm binary from this commit will result in a viable build.
6877
stage3-debug/bin/zig build update-zig1
6978

ci/aarch64-linux-release.sh

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ echo "If the following command fails, it means nondeterminism has been"
8080
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
8181
diff stage3-release/bin/zig stage4-release/bin/zig
8282

83+
# Ensure that dependency overrides function correctly
84+
wd=$PWD
85+
86+
cd ../test/dependency_override
87+
./run-tests.sh ../../build-release/stage3-release/bin/zig
88+
cd $wd
89+
90+
unset wd
91+
8392
# Ensure that updating the wasm binary from this commit will result in a viable build.
8493
stage3-release/bin/zig build update-zig1
8594

ci/aarch64-macos-debug.sh

+9
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,12 @@ stage3-debug/bin/zig build test docs \
5656
-Dstatic-llvm \
5757
-Dskip-non-native \
5858
--search-prefix "$PREFIX"
59+
60+
# Ensure that dependency overrides function correctly
61+
wd=$PWD
62+
63+
cd ../test/dependency_override
64+
./run-tests.sh ../../build-debug/stage3-debug/bin/zig
65+
cd $wd
66+
67+
unset wd

ci/aarch64-macos-release.sh

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ stage3-release/bin/zig build test docs \
5757
-Dskip-non-native \
5858
--search-prefix "$PREFIX"
5959

60+
# Ensure that dependency overrides function correctly
61+
wd=$PWD
62+
63+
cd ../test/dependency_override
64+
./run-tests.sh ../../build-release/stage3-release/bin/zig
65+
cd $wd
66+
67+
unset wd
68+
6069
# Ensure that stage3 and stage4 are byte-for-byte identical.
6170
stage3-release/bin/zig build \
6271
--prefix stage4-release \

ci/x86_64-linux-debug.sh

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ stage3-debug/bin/zig build test docs \
7373
--zig-lib-dir "$PWD/../lib" \
7474
-Denable-tidy
7575

76+
# Ensure that dependency overrides function correctly
77+
wd=$PWD
78+
79+
cd ../test/dependency_override
80+
./run-tests.sh ../../build-debug/stage3-debug/bin/zig
81+
cd $wd
82+
83+
unset wd
84+
7685
# Ensure that updating the wasm binary from this commit will result in a viable build.
7786
stage3-debug/bin/zig build update-zig1
7887

ci/x86_64-linux-release.sh

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ stage3-release/bin/zig build test docs \
7373
--zig-lib-dir "$PWD/../lib" \
7474
-Denable-tidy
7575

76+
# Ensure that dependency overrides function correctly
77+
wd=$PWD
78+
79+
cd ../test/dependency_override
80+
./run-tests.sh ../../build-release/stage3-release/bin/zig
81+
cd $wd
82+
83+
unset wd
84+
7685
# Ensure that stage3 and stage4 are byte-for-byte identical.
7786
stage3-release/bin/zig build \
7887
--prefix stage4-release \

ci/x86_64-macos-release.sh

+9
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ stage3/bin/zig build \
7676
echo "If the following command fails, it means nondeterminism has been"
7777
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
7878
diff stage3/bin/zig stage4/bin/zig
79+
80+
# Ensure that dependency overrides function correctly
81+
wd=$PWD
82+
83+
cd ../test/dependency_override
84+
./run-tests.sh ../../build/stage3/bin/zig
85+
cd $wd
86+
87+
unset wd

test/dependency_override/build.zig

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
pub fn build(b: *std.Build) !void {
2+
const optimize = b.standardOptimizeOption(.{});
3+
const target = b.standardTargetOptions(.{});
4+
5+
const overridden_runtime_pkg = b.dependency("overridden_runtime", .{});
6+
const overridden_buildtime_pkg = b.dependency("overridden_buildtime", .{});
7+
8+
const overridden_runtime_module = overridden_runtime_pkg.module("module");
9+
const overridden_buildtime_module = overridden_buildtime_pkg.module("module");
10+
11+
const test_step = b.step("test", "check package override behavior");
12+
b.default_step = test_step;
13+
14+
{
15+
const exe = b.addExecutable(.{
16+
.name = "dep-override-test-runtime",
17+
.root_source_file = b.path("src/main.zig"),
18+
.target = target,
19+
.optimize = optimize,
20+
});
21+
exe.root_module.addImport("module", overridden_runtime_module);
22+
23+
const run = b.addRunArtifact(exe);
24+
25+
const step = b.step("runtime", "check error package is overridden at runtime");
26+
step.dependOn(&run.step);
27+
28+
test_step.dependOn(&run.step);
29+
}
30+
31+
{
32+
const exe = b.addExecutable(.{
33+
.name = "dep-override-test-buildtime",
34+
.root_source_file = b.path("src/main.zig"),
35+
.target = target,
36+
.optimize = optimize,
37+
});
38+
exe.root_module.addImport("module", overridden_buildtime_module);
39+
40+
const run = b.addRunArtifact(exe);
41+
42+
const step = b.step("buildtime", "check error package is overridden at buildtime");
43+
step.dependOn(&run.step);
44+
45+
test_step.dependOn(&run.step);
46+
}
47+
}
48+
49+
const std = @import("std");
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.{
2+
.name = "dependency_override",
3+
.version = "0.0.0",
4+
.paths = .{""},
5+
.dependencies = .{
6+
.overridden_runtime = .{
7+
.url = "https://example.com",
8+
.hash = "1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e",
9+
},
10+
.overridden_buildtime = .{
11+
.url = "https://example.com",
12+
.hash = "12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3",
13+
},
14+
},
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub fn build(b: *std.Build) !void {
2+
_ = b.addModule("module", .{
3+
.root_source_file = b.path("src/root.zig"),
4+
});
5+
@panic("overridden-buildtime package has not been overridden");
6+
}
7+
8+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.{
2+
.name = "overriden-buildtime-pkg",
3+
.version = "0.0.0",
4+
.paths = .{""},
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn run() void {
2+
@panic("the overridden-buildtime package has not been overridden");
3+
}
4+
5+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn build(b: *std.Build) !void {
2+
_ = b.addModule("module", .{
3+
.root_source_file = b.path("src/root.zig"),
4+
});
5+
}
6+
7+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.{
2+
.name = "overriden-runtime-pkg",
3+
.version = "0.0.0",
4+
.paths = .{""},
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn run() void {
2+
@panic("the overridden-runtime package has not been overridden");
3+
}
4+
5+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn build(b: *std.Build) !void {
2+
_ = b.addModule("module", .{
3+
.root_source_file = b.path("src/root.zig"),
4+
});
5+
}
6+
7+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.{
2+
.name = "overriden-buildtime-pkg",
3+
.version = "0.0.0",
4+
.paths = .{""},
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn run() void {
2+
std.debug.print("this is the overridden-buildtime package\n", .{});
3+
}
4+
5+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn build(b: *std.Build) !void {
2+
_ = b.addModule("module", .{
3+
.root_source_file = b.path("src/root.zig"),
4+
});
5+
}
6+
7+
const std = @import("std");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.{
2+
.name = "overriden-runtime-pkg",
3+
.version = "0.0.0",
4+
.paths = .{""},
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn run() void {
2+
std.debug.print("this is the overridden-runtime package\n", .{});
3+
}
4+
5+
const std = @import("std");

test/dependency_override/run-tests.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
ZIG=$1
4+
5+
rm -r local-cache global-cache .zig-cache
6+
cp -r cache-with-good-pkgs local-cache
7+
cp -r cache-with-bad-pkgs global-cache
8+
$ZIG build test --global-cache-dir global-cache --cache-dir local-cache && \
9+
$ZIG build test --cache-dir local-cache && \
10+
$ZIG build test --system cache-with-good-pkgs/p

test/dependency_override/src/main.zig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn main() void {
2+
@import("module").run();
3+
}
4+
5+
const std = @import("std");

0 commit comments

Comments
 (0)