commit dc68aab6fbe193a98ad687d80a2901cb38928ddf (tree)
parent 919dcc5104d08fdb0828b3ed33e747bd2afacfbc
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Sun, 18 Oct 2020 15:29:51 +0200
Merge pull request #6728 from Snektron/std-build-dupePkg-fix
Fix invalid call to dupePkg in build.zig
Diffstat:
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/lib/std/build.zig b/lib/std/build.zig
@@ -1843,7 +1843,7 @@ pub const LibExeObjStep = struct {
}
pub fn addPackage(self: *LibExeObjStep, package: Pkg) void {
- self.packages.append(self.dupePkg(package)) catch unreachable;
+ self.packages.append(self.builder.dupePkg(package)) catch unreachable;
}
pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
@@ -2749,6 +2749,37 @@ test "Builder.dupePkg()" {
std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
}
+test "LibExeObjStep.addPackage" {
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena.deinit();
+
+ var builder = try Builder.create(
+ &arena.allocator,
+ "test",
+ "test",
+ "test",
+ );
+ defer builder.destroy();
+
+ const pkg_dep = Pkg{
+ .name = "pkg_dep",
+ .path = "/not/a/pkg_dep.zig",
+ };
+ const pkg_top = Pkg{
+ .name = "pkg_dep",
+ .path = "/not/a/pkg_top.zig",
+ .dependencies = &[_]Pkg{pkg_dep},
+ };
+
+ var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
+ exe.addPackage(pkg_top);
+
+ std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
+
+ const dupe = exe.packages.items[0];
+ std.testing.expectEqualStrings(pkg_top.name, dupe.name);
+}
+
test "" {
// The only purpose of this test is to get all these untested functions
// to be referenced to avoid regression so it is okay to skip some targets.