authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-10-18 15:29:51+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-18 15:29:51+02:00
logdc68aab6fbe193a98ad687d80a2901cb38928ddf
treeba38302af07bfd30188e63ef1375314812242f55
parent919dcc5104d08fdb0828b3ed33e747bd2afacfbc
parent3d857f7808171221235a04323e3defa8637b8e1f
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6728 from Snektron/std-build-dupePkg-fix

Fix invalid call to dupePkg in build.zig

1 files changed, 32 insertions(+), 1 deletions(-)

lib/std/build.zig+32-1
...@@ -1843,7 +1843,7 @@ pub const LibExeObjStep = struct {...@@ -1843,7 +1843,7 @@ pub const LibExeObjStep = struct {
1843 }1843 }
18441844
1845 pub fn addPackage(self: *LibExeObjStep, package: Pkg) void {1845 pub fn addPackage(self: *LibExeObjStep, package: Pkg) void {
1846 self.packages.append(self.dupePkg(package)) catch unreachable;1846 self.packages.append(self.builder.dupePkg(package)) catch unreachable;
1847 }1847 }
18481848
1849 pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {1849 pub fn addPackagePath(self: *LibExeObjStep, name: []const u8, pkg_index_path: []const u8) void {
...@@ -2749,6 +2749,37 @@ test "Builder.dupePkg()" {...@@ -2749,6 +2749,37 @@ test "Builder.dupePkg()" {
2749 std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);2749 std.testing.expect(dupe_deps[0].path.ptr != pkg_dep.path.ptr);
2750}2750}
27512751
2752test "LibExeObjStep.addPackage" {
2753 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
2754 defer arena.deinit();
2755
2756 var builder = try Builder.create(
2757 &arena.allocator,
2758 "test",
2759 "test",
2760 "test",
2761 );
2762 defer builder.destroy();
2763
2764 const pkg_dep = Pkg{
2765 .name = "pkg_dep",
2766 .path = "/not/a/pkg_dep.zig",
2767 };
2768 const pkg_top = Pkg{
2769 .name = "pkg_dep",
2770 .path = "/not/a/pkg_top.zig",
2771 .dependencies = &[_]Pkg{pkg_dep},
2772 };
2773
2774 var exe = builder.addExecutable("not_an_executable", "/not/an/executable.zig");
2775 exe.addPackage(pkg_top);
2776
2777 std.testing.expectEqual(@as(usize, 1), exe.packages.items.len);
2778
2779 const dupe = exe.packages.items[0];
2780 std.testing.expectEqualStrings(pkg_top.name, dupe.name);
2781}
2782
2752test "" {2783test "" {
2753 // The only purpose of this test is to get all these untested functions2784 // The only purpose of this test is to get all these untested functions
2754 // to be referenced to avoid regression so it is okay to skip some targets.2785 // to be referenced to avoid regression so it is okay to skip some targets.