| ... | ... | @@ -215,6 +215,8 @@ const usage_build_generic = |
| 215 | 215 | \\ ReleaseFast Optimizations on, safety off |
| 216 | 216 | \\ ReleaseSafe Optimizations on, safety on |
| 217 | 217 | \\ ReleaseSmall Optimize for small binary, safety off |
| 218 | \\ --pkg-begin [name] [path] Make pkg available to import and push current pkg |
| 219 | \\ --pkg-end Pop current pkg |
| 218 | 220 | \\ -fPIC Force-enable Position Independent Code |
| 219 | 221 | \\ -fno-PIC Force-disable Position Independent Code |
| 220 | 222 | \\ -fstack-check Enable stack probing in unsafe builds |
| ... | ... | @@ -397,6 +399,13 @@ pub fn buildOutputType( |
| 397 | 399 | var test_exec_args = std.ArrayList(?[]const u8).init(gpa); |
| 398 | 400 | defer test_exec_args.deinit(); |
| 399 | 401 | |
| 402 | var root_pkg_memory: Package = .{ |
| 403 | .root_src_directory = undefined, |
| 404 | .root_src_path = undefined, |
| 405 | }; |
| 406 | defer root_pkg_memory.table.deinit(gpa); |
| 407 | var cur_pkg: *Package = &root_pkg_memory; |
| 408 | |
| 400 | 409 | switch (arg_mode) { |
| 401 | 410 | .build, .translate_c, .zig_test, .run => { |
| 402 | 411 | output_mode = switch (arg_mode) { |
| ... | ... | @@ -427,6 +436,33 @@ pub fn buildOutputType( |
| 427 | 436 | } else { |
| 428 | 437 | fatal("unexpected end-of-parameter mark: --", .{}); |
| 429 | 438 | } |
| 439 | } else if (mem.eql(u8, arg, "--pkg-begin")) { |
| 440 | if (i + 2 >= args.len) fatal("Expected 2 arguments after {}", .{arg}); |
| 441 | i += 1; |
| 442 | const pkg_name = args[i]; |
| 443 | i += 1; |
| 444 | const pkg_path = args[i]; |
| 445 | |
| 446 | const new_cur_pkg = try arena.create(Package); |
| 447 | new_cur_pkg.* = .{ |
| 448 | .root_src_directory = if (fs.path.dirname(pkg_path)) |dirname| |
| 449 | .{ |
| 450 | .path = dirname, |
| 451 | .handle = try fs.cwd().openDir(dirname, .{}), // TODO close this fd |
| 452 | } |
| 453 | else |
| 454 | .{ |
| 455 | .path = null, |
| 456 | .handle = fs.cwd(), |
| 457 | }, |
| 458 | .root_src_path = fs.path.basename(pkg_path), |
| 459 | .parent = cur_pkg, |
| 460 | }; |
| 461 | try cur_pkg.table.put(gpa, pkg_name, new_cur_pkg); |
| 462 | cur_pkg = new_cur_pkg; |
| 463 | } else if (mem.eql(u8, arg, "--pkg-end")) { |
| 464 | cur_pkg = cur_pkg.parent orelse |
| 465 | fatal("encountered --pkg-end with no matching --pkg-begin", .{}); |
| 430 | 466 | } else if (mem.eql(u8, arg, "--color")) { |
| 431 | 467 | if (i + 1 >= args.len) { |
| 432 | 468 | fatal("expected [auto|on|off] after --color", .{}); |
| ... | ... | @@ -1212,12 +1248,9 @@ pub fn buildOutputType( |
| 1212 | 1248 | .yes => |p| p, |
| 1213 | 1249 | }; |
| 1214 | 1250 | |
| 1215 | | var root_pkg_memory: Package = undefined; |
| 1216 | 1251 | const root_pkg: ?*Package = if (root_src_file) |src_path| blk: { |
| 1217 | | root_pkg_memory = .{ |
| 1218 | | .root_src_directory = .{ .path = null, .handle = fs.cwd() }, |
| 1219 | | .root_src_path = src_path, |
| 1220 | | }; |
| 1252 | root_pkg_memory.root_src_directory = .{ .path = null, .handle = fs.cwd() }; |
| 1253 | root_pkg_memory.root_src_path = src_path; |
| 1221 | 1254 | break :blk &root_pkg_memory; |
| 1222 | 1255 | } else null; |
| 1223 | 1256 | |