Commit 518ff33e64

Jimmi Holst Christensen <jhc@liab.dk>
2018-12-05 14:10:09
Allow packages in TestStep
1 parent 9ac838c
Changed files (1)
std/build.zig
@@ -811,6 +811,11 @@ pub const Target = union(enum) {
     }
 };
 
+const Pkg = struct {
+    name: []const u8,
+    path: []const u8,
+};
+
 pub const LibExeObjStep = struct {
     step: Step,
     builder: *Builder,
@@ -853,11 +858,6 @@ pub const LibExeObjStep = struct {
     source_files: ArrayList([]const u8),
     object_src: []const u8,
 
-    const Pkg = struct {
-        name: []const u8,
-        path: []const u8,
-    };
-
     const Kind = enum {
         Exe,
         Lib,
@@ -1667,6 +1667,7 @@ pub const TestStep = struct {
     exec_cmd_args: ?[]const ?[]const u8,
     include_dirs: ArrayList([]const u8),
     lib_paths: ArrayList([]const u8),
+    packages: ArrayList(Pkg),
     object_files: ArrayList([]const u8),
     no_rosegment: bool,
     output_path: ?[]const u8,
@@ -1687,6 +1688,7 @@ pub const TestStep = struct {
             .exec_cmd_args = null,
             .include_dirs = ArrayList([]const u8).init(builder.allocator),
             .lib_paths = ArrayList([]const u8).init(builder.allocator),
+            .packages = ArrayList(Pkg).init(builder.allocator),
             .object_files = ArrayList([]const u8).init(builder.allocator),
             .no_rosegment = false,
             .output_path = null,
@@ -1702,6 +1704,13 @@ pub const TestStep = struct {
         self.lib_paths.append(path) catch unreachable;
     }
 
+    pub fn addPackagePath(self: *TestStep, name: []const u8, pkg_index_path: []const u8) void {
+        self.packages.append(Pkg{
+            .name = name,
+            .path = pkg_index_path,
+        }) catch unreachable;
+    }
+
     pub fn setVerbose(self: *TestStep, value: bool) void {
         self.verbose = value;
     }
@@ -1878,6 +1887,13 @@ pub const TestStep = struct {
             try zig_args.append(lib_path);
         }
 
+        for (self.packages.toSliceConst()) |pkg| {
+            zig_args.append("--pkg-begin") catch unreachable;
+            zig_args.append(pkg.name) catch unreachable;
+            zig_args.append(builder.pathFromRoot(pkg.path)) catch unreachable;
+            zig_args.append("--pkg-end") catch unreachable;
+        }
+
         if (self.no_rosegment) {
             try zig_args.append("--no-rosegment");
         }