| ... | ... | @@ -166,10 +166,9 @@ pub const Graph = struct { |
| 166 | 166 | /// A path whose components and contents are known at some point during |
| 167 | 167 | /// `Step` resolution, relative to the provided base directory. |
| 168 | 168 | pub fn path(graph: *Graph, base: Configuration.Path.Base, sub_path: []const u8) LazyPath { |
| 169 | | const wc = &graph.wip_configuration; |
| 170 | 169 | return .{ .relative = .{ |
| 171 | 170 | .base = base, |
| 172 | | .sub_path = wc.addString(sub_path) catch @panic("OOM"), |
| 171 | .sub_path = @This().dupePath(graph, sub_path), |
| 173 | 172 | } }; |
| 174 | 173 | } |
| 175 | 174 | |
| ... | ... | @@ -974,12 +973,12 @@ pub fn dupe(b: *Build, bytes: []const u8) []const u8 { |
| 974 | 973 | return b.graph.dupeString(bytes); |
| 975 | 974 | } |
| 976 | 975 | |
| 977 | | /// Duplicates an array of strings without the need to handle out of memory. |
| 976 | /// Deprecated, call `Graph.dupeStrings` instead. |
| 978 | 977 | pub fn dupeStrings(b: *Build, strings: []const []const u8) []const []const u8 { |
| 979 | 978 | return b.graph.dupeStrings(strings); |
| 980 | 979 | } |
| 981 | 980 | |
| 982 | | /// Duplicates a path, canonicalizing path separators. |
| 981 | /// Deprecated, call `Graph.dupePath` instead. |
| 983 | 982 | pub fn dupePath(b: *Build, bytes: []const u8) []const u8 { |
| 984 | 983 | return b.graph.dupePath(bytes); |
| 985 | 984 | } |
| ... | ... | @@ -1536,7 +1535,7 @@ pub fn addUserInputFlag(b: *Build, name_raw: []const u8) error{OutOfMemory}!bool |
| 1536 | 1535 | return true; |
| 1537 | 1536 | }, |
| 1538 | 1537 | .lazy_path => |lp| { |
| 1539 | | log.err("Flag '-D{s}' conflicts with option '-D{s}={f}'.", .{ name, name, lp.fmt(graph) }); |
| 1538 | log.err("Flag '-D{s}' conflicts with option '-D{s}={f}'.", .{ name, name, lp }); |
| 1540 | 1539 | return true; |
| 1541 | 1540 | }, |
| 1542 | 1541 | |
| ... | ... | @@ -2381,10 +2380,10 @@ pub const LazyPath = union(enum) { |
| 2381 | 2380 | |
| 2382 | 2381 | relative: struct { |
| 2383 | 2382 | base: Configuration.Path.Base, |
| 2384 | | sub_path: Configuration.String = .empty, |
| 2383 | sub_path: []const u8 = "", |
| 2385 | 2384 | |
| 2386 | 2385 | pub fn eql(a: @This(), b: @This()) bool { |
| 2387 | | return a.base == b.base and a.sub_path == b.sub_path; |
| 2386 | return a.base == b.base and mem.eql(u8, a.sub_path, b.sub_path); |
| 2388 | 2387 | } |
| 2389 | 2388 | }, |
| 2390 | 2389 | |
| ... | ... | @@ -2398,11 +2397,11 @@ pub const LazyPath = union(enum) { |
| 2398 | 2397 | |
| 2399 | 2398 | /// Returns a lazy path referring to the directory containing this path. |
| 2400 | 2399 | /// |
| 2401 | | /// The dirname is not allowed to escape the logical root for underlying path. |
| 2402 | | /// For example, if the path is relative to the build root, |
| 2403 | | /// the dirname is not allowed to traverse outside of the build root. |
| 2404 | | /// Similarly, if the path is a generated file inside zig-cache, |
| 2405 | | /// the dirname is not allowed to traverse outside of zig-cache. |
| 2400 | /// The dirname is not allowed to escape the logical root for underlying |
| 2401 | /// path. For example, if the path is relative to the build root, the |
| 2402 | /// dirname is not allowed to traverse outside of the build root. |
| 2403 | /// Similarly, if the path is a generated file inside zig-cache, the |
| 2404 | /// dirname is not allowed to traverse outside of zig-cache. |
| 2406 | 2405 | pub fn dirname(lazy_path: LazyPath) LazyPath { |
| 2407 | 2406 | return switch (lazy_path) { |
| 2408 | 2407 | .src_path => |sp| .{ .src_path = .{ |
| ... | ... | @@ -2444,9 +2443,13 @@ pub const LazyPath = union(enum) { |
| 2444 | 2443 | } |
| 2445 | 2444 | }, |
| 2446 | 2445 | }, |
| 2447 | | .relative => .{ |
| 2448 | | .relative = @panic("TODO"), |
| 2449 | | }, |
| 2446 | .relative => |r| .{ .relative = .{ |
| 2447 | .base = r.base, |
| 2448 | .sub_path = dirnameAllowEmpty(r.sub_path) orelse { |
| 2449 | dumpBadDirnameHelp(null, null, "dirname() attempted to traverse outside the base path\n", .{}) catch {}; |
| 2450 | @panic("misconfigured build script"); |
| 2451 | }, |
| 2452 | } }, |
| 2450 | 2453 | .dependency => |dep| .{ .dependency = .{ |
| 2451 | 2454 | .dependency = dep.dependency, |
| 2452 | 2455 | .sub_path = dirnameAllowEmpty(dep.sub_path) orelse { |
| ... | ... | @@ -2480,9 +2483,10 @@ pub const LazyPath = union(enum) { |
| 2480 | 2483 | .cwd_relative => |cwd_relative| .{ |
| 2481 | 2484 | .cwd_relative = try fs.path.resolve(arena, &.{ cwd_relative, sub_path }), |
| 2482 | 2485 | }, |
| 2483 | | .relative => .{ |
| 2484 | | .relative = @panic("TODO"), |
| 2485 | | }, |
| 2486 | .relative => |r| .{ .relative = .{ |
| 2487 | .base = r.base, |
| 2488 | .sub_path = try fs.path.resolve(arena, &.{ r.sub_path, sub_path }), |
| 2489 | } }, |
| 2486 | 2490 | .dependency => |dep| .{ .dependency = .{ |
| 2487 | 2491 | .dependency = dep.dependency, |
| 2488 | 2492 | .sub_path = try fs.path.resolve(arena, &.{ dep.sub_path, sub_path }), |
| ... | ... | @@ -2490,27 +2494,25 @@ pub const LazyPath = union(enum) { |
| 2490 | 2494 | }; |
| 2491 | 2495 | } |
| 2492 | 2496 | |
| 2493 | | pub const Format = struct { |
| 2494 | | graph: *const Graph, |
| 2495 | | lazy_path: *const LazyPath, |
| 2496 | | |
| 2497 | | pub fn format(f: Format, w: *Io.Writer) Io.Writer.Error!void { |
| 2498 | | switch (f.lazy_path.*) { |
| 2499 | | .src_path => |sp| try w.writeAll(sp.sub_path), |
| 2500 | | .cwd_relative => |p| try w.writeAll(p), |
| 2501 | | .generated => try w.writeAll("generated"), |
| 2502 | | .dependency => try w.writeAll("dependency"), |
| 2503 | | .relative => |r| { |
| 2504 | | const wc = &f.graph.wip_configuration; |
| 2505 | | try w.writeAll(@tagName(r.base)); |
| 2506 | | try w.writeAll(wc.stringSlice(r.sub_path)); |
| 2507 | | }, |
| 2508 | | } |
| 2509 | | } |
| 2510 | | }; |
| 2497 | /// Deprecated, use `format` instead. |
| 2498 | pub fn getDisplayName(lazy_path: LazyPath) []const u8 { |
| 2499 | return switch (lazy_path) { |
| 2500 | .src_path => |sp| sp.sub_path, |
| 2501 | .cwd_relative => |p| p, |
| 2502 | .generated => "generated", |
| 2503 | .dependency => "dependency", |
| 2504 | .relative => |r| @tagName(r.base), |
| 2505 | }; |
| 2506 | } |
| 2511 | 2507 | |
| 2512 | | pub fn fmt(lp: *const LazyPath, graph: *const Graph) Format { |
| 2513 | | return .{ .graph = graph, .lazy_path = lp }; |
| 2508 | pub fn format(lp: LazyPath, w: *Io.Writer) Io.Writer.Error!void { |
| 2509 | switch (lp) { |
| 2510 | .src_path => |sp| try w.writeAll(sp.sub_path), |
| 2511 | .cwd_relative => |p| try w.writeAll(p), |
| 2512 | .generated => try w.writeAll("generated"), |
| 2513 | .dependency => try w.writeAll("dependency"), |
| 2514 | .relative => |r| try w.print("{t} {s}", .{ r.base, r.sub_path }), |
| 2515 | } |
| 2514 | 2516 | } |
| 2515 | 2517 | |
| 2516 | 2518 | /// Adds dependencies this file source implies to the given step. |
| ... | ... | @@ -2525,15 +2527,6 @@ pub const LazyPath = union(enum) { |
| 2525 | 2527 | } |
| 2526 | 2528 | } |
| 2527 | 2529 | |
| 2528 | | pub fn basename(lazy_path: LazyPath) []const u8 { |
| 2529 | | return fs.path.basename(switch (lazy_path) { |
| 2530 | | .src_path => |sp| sp.sub_path, |
| 2531 | | .cwd_relative => |sub_path| sub_path, |
| 2532 | | .generated => |gen| gen.sub_path, |
| 2533 | | .dependency => |dep| dep.sub_path, |
| 2534 | | }); |
| 2535 | | } |
| 2536 | | |
| 2537 | 2530 | /// Copies the internal strings. |
| 2538 | 2531 | /// |
| 2539 | 2532 | /// The `graph` parameter is only used for the global arena allocator. |