Skip to content

Commit

Permalink
ci: test dependency overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiller committed Oct 31, 2024
1 parent 48f664f commit c2cca34
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ci/aarch64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ stage3-debug/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build-debug/stage3-debug/bin/zig
cd $wd

unset wd

# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-debug/bin/zig build update-zig1

Expand Down
9 changes: 9 additions & 0 deletions ci/aarch64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3-release/bin/zig stage4-release/bin/zig

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build-release/stage3-release/bin/zig
cd $wd

unset wd

# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-release/bin/zig build update-zig1

Expand Down
9 changes: 9 additions & 0 deletions ci/aarch64-macos-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ stage3-debug/bin/zig build test docs \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build-debug/stage3-debug/bin/zig
cd $wd

unset wd
9 changes: 9 additions & 0 deletions ci/aarch64-macos-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ stage3-release/bin/zig build test docs \
-Dskip-non-native \
--search-prefix "$PREFIX"

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build-release/stage3-release/bin/zig
cd $wd

unset wd

# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
Expand Down
9 changes: 9 additions & 0 deletions ci/x86_64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ stage3-debug/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build-debug/stage3-debug/bin/zig
cd $wd

unset wd

# Ensure that updating the wasm binary from this commit will result in a viable build.
stage3-debug/bin/zig build update-zig1

Expand Down
9 changes: 9 additions & 0 deletions ci/x86_64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ stage3-release/bin/zig build test docs \
--zig-lib-dir "$PWD/../lib" \
-Denable-superhtml

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build-release/stage3-release/bin/zig
cd $wd

unset wd

# Ensure that stage3 and stage4 are byte-for-byte identical.
stage3-release/bin/zig build \
--prefix stage4-release \
Expand Down
9 changes: 9 additions & 0 deletions ci/x86_64-macos-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,12 @@ stage3/bin/zig build \
echo "If the following command fails, it means nondeterminism has been"
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
diff stage3/bin/zig stage4/bin/zig

# Ensure that dependency overrides function correctly
wd=$PWD

cd ../test/dependency_override
./run-tests.sh ../../build/stage3/bin/zig
cd $wd

unset wd
49 changes: 49 additions & 0 deletions test/dependency_override/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});

const overridden_runtime_pkg = b.dependency("overridden_runtime", .{});
const overridden_buildtime_pkg = b.dependency("overridden_buildtime", .{});

const overridden_runtime_module = overridden_runtime_pkg.module("module");
const overridden_buildtime_module = overridden_buildtime_pkg.module("module");

const test_step = b.step("test", "check package override behavior");
b.default_step = test_step;

{
const exe = b.addExecutable(.{
.name = "dep-override-test-runtime",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("module", overridden_runtime_module);

const run = b.addRunArtifact(exe);

const step = b.step("runtime", "check error package is overridden at runtime");
step.dependOn(&run.step);

test_step.dependOn(&run.step);
}

{
const exe = b.addExecutable(.{
.name = "dep-override-test-buildtime",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("module", overridden_buildtime_module);

const run = b.addRunArtifact(exe);

const step = b.step("buildtime", "check error package is overridden at buildtime");
step.dependOn(&run.step);

test_step.dependOn(&run.step);
}
}

const std = @import("std");
15 changes: 15 additions & 0 deletions test/dependency_override/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.{
.name = "dependency_override",
.version = "0.0.0",
.paths = .{""},
.dependencies = .{
.overridden_runtime = .{
.url = "https://example.com",
.hash = "1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e",
},
.overridden_buildtime = .{
.url = "https://example.com",
.hash = "12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3",
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub fn build(b: *std.Build) !void {
_ = b.addModule("module", .{
.root_source_file = b.path("src/root.zig"),
});
@panic("overridden-buildtime package has not been overridden");
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.{
.name = "overriden-buildtime-pkg",
.version = "0.0.0",
.paths = .{""},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub fn run() void {
@panic("the overridden-buildtime package has not been overridden");
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn build(b: *std.Build) !void {
_ = b.addModule("module", .{
.root_source_file = b.path("src/root.zig"),
});
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.{
.name = "overriden-runtime-pkg",
.version = "0.0.0",
.paths = .{""},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub fn run() void {
@panic("the overridden-runtime package has not been overridden");
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn build(b: *std.Build) !void {
_ = b.addModule("module", .{
.root_source_file = b.path("src/root.zig"),
});
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.{
.name = "overriden-buildtime-pkg",
.version = "0.0.0",
.paths = .{""},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub fn run() void {
std.debug.print("this is the overridden-buildtime package\n", .{});
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn build(b: *std.Build) !void {
_ = b.addModule("module", .{
.root_source_file = b.path("src/root.zig"),
});
}

const std = @import("std");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.{
.name = "overriden-runtime-pkg",
.version = "0.0.0",
.paths = .{""},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub fn run() void {
std.debug.print("this is the overridden-runtime package\n", .{});
}

const std = @import("std");
10 changes: 10 additions & 0 deletions test/dependency_override/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

ZIG=$1

rm -r local-cache global-cache .zig-cache
cp -r cache-with-good-pkgs local-cache
cp -r cache-with-bad-pkgs global-cache
$ZIG build test --global-cache-dir global-cache --cache-dir local-cache && \
$ZIG build test --cache-dir local-cache && \
$ZIG build test --system cache-with-good-pkgs/p
5 changes: 5 additions & 0 deletions test/dependency_override/src/main.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub fn main() void {
@import("module").run();
}

const std = @import("std");

0 comments on commit c2cca34

Please sign in to comment.