From c2cca34733162370c60af894f8eccd371077ac89 Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:44:59 +1000 Subject: [PATCH] ci: test dependency overriding --- ci/aarch64-linux-debug.sh | 9 ++++ ci/aarch64-linux-release.sh | 9 ++++ ci/aarch64-macos-debug.sh | 9 ++++ ci/aarch64-macos-release.sh | 9 ++++ ci/x86_64-linux-debug.sh | 9 ++++ ci/x86_64-linux-release.sh | 9 ++++ ci/x86_64-macos-release.sh | 9 ++++ test/dependency_override/build.zig | 49 +++++++++++++++++++ test/dependency_override/build.zig.zon | 15 ++++++ .../build.zig | 8 +++ .../build.zig.zon | 5 ++ .../src/root.zig | 5 ++ .../build.zig | 7 +++ .../build.zig.zon | 5 ++ .../src/root.zig | 5 ++ .../build.zig | 7 +++ .../build.zig.zon | 5 ++ .../src/root.zig | 5 ++ .../build.zig | 7 +++ .../build.zig.zon | 5 ++ .../src/root.zig | 5 ++ test/dependency_override/run-tests.sh | 10 ++++ test/dependency_override/src/main.zig | 5 ++ 23 files changed, 211 insertions(+) create mode 100644 test/dependency_override/build.zig create mode 100644 test/dependency_override/build.zig.zon create mode 100644 test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig create mode 100644 test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon create mode 100644 test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig create mode 100644 test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig create mode 100644 test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon create mode 100644 test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig create mode 100644 test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig create mode 100644 test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon create mode 100644 test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig create mode 100644 test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig create mode 100644 test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon create mode 100644 test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig create mode 100755 test/dependency_override/run-tests.sh create mode 100644 test/dependency_override/src/main.zig diff --git a/ci/aarch64-linux-debug.sh b/ci/aarch64-linux-debug.sh index 47f75c462476..adf5c9041005 100644 --- a/ci/aarch64-linux-debug.sh +++ b/ci/aarch64-linux-debug.sh @@ -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 diff --git a/ci/aarch64-linux-release.sh b/ci/aarch64-linux-release.sh index a41255b45476..a51a303ea2e9 100644 --- a/ci/aarch64-linux-release.sh +++ b/ci/aarch64-linux-release.sh @@ -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 diff --git a/ci/aarch64-macos-debug.sh b/ci/aarch64-macos-debug.sh index 4d44401a9924..4227ae2c5300 100755 --- a/ci/aarch64-macos-debug.sh +++ b/ci/aarch64-macos-debug.sh @@ -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 diff --git a/ci/aarch64-macos-release.sh b/ci/aarch64-macos-release.sh index e8ce56eaea2d..faf42229f0c7 100755 --- a/ci/aarch64-macos-release.sh +++ b/ci/aarch64-macos-release.sh @@ -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 \ diff --git a/ci/x86_64-linux-debug.sh b/ci/x86_64-linux-debug.sh index 7204fa29f1c2..6547a7db276c 100755 --- a/ci/x86_64-linux-debug.sh +++ b/ci/x86_64-linux-debug.sh @@ -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 diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index b51b6f12d6d8..f6e7dfeb0006 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -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 \ diff --git a/ci/x86_64-macos-release.sh b/ci/x86_64-macos-release.sh index 838952b181bb..e11029d0b986 100755 --- a/ci/x86_64-macos-release.sh +++ b/ci/x86_64-macos-release.sh @@ -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 diff --git a/test/dependency_override/build.zig b/test/dependency_override/build.zig new file mode 100644 index 000000000000..67bc4b5483b4 --- /dev/null +++ b/test/dependency_override/build.zig @@ -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"); diff --git a/test/dependency_override/build.zig.zon b/test/dependency_override/build.zig.zon new file mode 100644 index 000000000000..62b3d2f21007 --- /dev/null +++ b/test/dependency_override/build.zig.zon @@ -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", + }, + }, +} diff --git a/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig b/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig new file mode 100644 index 000000000000..d48e4478fd5e --- /dev/null +++ b/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig @@ -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"); diff --git a/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon b/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon new file mode 100644 index 000000000000..b9060c98a158 --- /dev/null +++ b/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon @@ -0,0 +1,5 @@ +.{ + .name = "overriden-buildtime-pkg", + .version = "0.0.0", + .paths = .{""}, +} diff --git a/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig b/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig new file mode 100644 index 000000000000..ecbe273abae2 --- /dev/null +++ b/test/dependency_override/cache-with-bad-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig @@ -0,0 +1,5 @@ +pub fn run() void { + @panic("the overridden-buildtime package has not been overridden"); +} + +const std = @import("std"); diff --git a/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig b/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig new file mode 100644 index 000000000000..4eaa1c5571ab --- /dev/null +++ b/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig @@ -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"); diff --git a/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon b/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon new file mode 100644 index 000000000000..fc42a48e8127 --- /dev/null +++ b/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon @@ -0,0 +1,5 @@ +.{ + .name = "overriden-runtime-pkg", + .version = "0.0.0", + .paths = .{""}, +} diff --git a/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig b/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig new file mode 100644 index 000000000000..058fd2fc70bd --- /dev/null +++ b/test/dependency_override/cache-with-bad-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig @@ -0,0 +1,5 @@ +pub fn run() void { + @panic("the overridden-runtime package has not been overridden"); +} + +const std = @import("std"); diff --git a/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig b/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig new file mode 100644 index 000000000000..4eaa1c5571ab --- /dev/null +++ b/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig @@ -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"); diff --git a/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon b/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon new file mode 100644 index 000000000000..b9060c98a158 --- /dev/null +++ b/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/build.zig.zon @@ -0,0 +1,5 @@ +.{ + .name = "overriden-buildtime-pkg", + .version = "0.0.0", + .paths = .{""}, +} diff --git a/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig b/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig new file mode 100644 index 000000000000..cb8f6f597884 --- /dev/null +++ b/test/dependency_override/cache-with-good-pkgs/p/12205377339014b33ba4f8ed6acaf863a2eb14b6769a9a1d5c2f23b04bac936897a3/src/root.zig @@ -0,0 +1,5 @@ +pub fn run() void { + std.debug.print("this is the overridden-buildtime package\n", .{}); +} + +const std = @import("std"); diff --git a/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig b/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig new file mode 100644 index 000000000000..4eaa1c5571ab --- /dev/null +++ b/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig @@ -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"); diff --git a/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon b/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon new file mode 100644 index 000000000000..fc42a48e8127 --- /dev/null +++ b/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/build.zig.zon @@ -0,0 +1,5 @@ +.{ + .name = "overriden-runtime-pkg", + .version = "0.0.0", + .paths = .{""}, +} diff --git a/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig b/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig new file mode 100644 index 000000000000..072cfeb3a414 --- /dev/null +++ b/test/dependency_override/cache-with-good-pkgs/p/1220af21050dd194c8500c038b2466dabf449cd4355861cc5473bd9dae99eed7c47e/src/root.zig @@ -0,0 +1,5 @@ +pub fn run() void { + std.debug.print("this is the overridden-runtime package\n", .{}); +} + +const std = @import("std"); diff --git a/test/dependency_override/run-tests.sh b/test/dependency_override/run-tests.sh new file mode 100755 index 000000000000..785d26902171 --- /dev/null +++ b/test/dependency_override/run-tests.sh @@ -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 diff --git a/test/dependency_override/src/main.zig b/test/dependency_override/src/main.zig new file mode 100644 index 000000000000..c8994ea75da1 --- /dev/null +++ b/test/dependency_override/src/main.zig @@ -0,0 +1,5 @@ +pub fn main() void { + @import("module").run(); +} + +const std = @import("std");