| ... | ... | @@ -2327,36 +2327,52 @@ pub const LazyPath = union(enum) { |
| 2327 | 2327 | } |
| 2328 | 2328 | } |
| 2329 | 2329 | |
| 2330 | | /// Returns an absolute path. |
| 2331 | | /// Intended to be used during the make phase only. |
| 2330 | /// Deprecated, see `getPath3`. |
| 2332 | 2331 | pub fn getPath(lazy_path: LazyPath, src_builder: *Build) []const u8 { |
| 2333 | 2332 | return getPath2(lazy_path, src_builder, null); |
| 2334 | 2333 | } |
| 2335 | 2334 | |
| 2336 | | /// Returns an absolute path. |
| 2335 | /// Deprecated, see `getPath3`. |
| 2336 | pub fn getPath2(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 2337 | const p = getPath3(lazy_path, src_builder, asking_step); |
| 2338 | return src_builder.pathResolve(&.{ p.root_dir.path orelse ".", p.sub_path }); |
| 2339 | } |
| 2340 | |
| 2337 | 2341 | /// Intended to be used during the make phase only. |
| 2338 | 2342 | /// |
| 2339 | 2343 | /// `asking_step` is only used for debugging purposes; it's the step being |
| 2340 | 2344 | /// run that is asking for the path. |
| 2341 | | pub fn getPath2(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 2345 | pub fn getPath3(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) Cache.Path { |
| 2342 | 2346 | switch (lazy_path) { |
| 2343 | | .src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path), |
| 2344 | | .cwd_relative => |p| return src_builder.pathFromCwd(p), |
| 2347 | .src_path => |sp| return .{ |
| 2348 | .root_dir = sp.owner.build_root, |
| 2349 | .sub_path = sp.sub_path, |
| 2350 | }, |
| 2351 | .cwd_relative => |sub_path| return .{ |
| 2352 | .root_dir = Cache.Directory.cwd(), |
| 2353 | .sub_path = sub_path, |
| 2354 | }, |
| 2345 | 2355 | .generated => |gen| { |
| 2346 | | var file_path: []const u8 = gen.file.step.owner.pathFromRoot(gen.file.path orelse { |
| 2347 | | std.debug.lockStdErr(); |
| 2348 | | const stderr = std.io.getStdErr(); |
| 2349 | | dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {}; |
| 2350 | | std.debug.unlockStdErr(); |
| 2351 | | @panic("misconfigured build script"); |
| 2352 | | }); |
| 2356 | // TODO make gen.file.path not be absolute and use that as the |
| 2357 | // basis for not traversing up too many directories. |
| 2358 | |
| 2359 | var file_path: Cache.Path = .{ |
| 2360 | .root_dir = gen.file.step.owner.build_root, |
| 2361 | .sub_path = gen.file.path orelse { |
| 2362 | std.debug.lockStdErr(); |
| 2363 | const stderr = std.io.getStdErr(); |
| 2364 | dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {}; |
| 2365 | std.debug.unlockStdErr(); |
| 2366 | @panic("misconfigured build script"); |
| 2367 | }, |
| 2368 | }; |
| 2353 | 2369 | |
| 2354 | 2370 | if (gen.up > 0) { |
| 2355 | 2371 | const cache_root_path = src_builder.cache_root.path orelse |
| 2356 | 2372 | (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); |
| 2357 | 2373 | |
| 2358 | 2374 | for (0..gen.up) |_| { |
| 2359 | | if (mem.eql(u8, file_path, cache_root_path)) { |
| 2375 | if (mem.eql(u8, file_path.sub_path, cache_root_path)) { |
| 2360 | 2376 | // If we hit the cache root and there's still more to go, |
| 2361 | 2377 | // the script attempted to go too far. |
| 2362 | 2378 | dumpBadDirnameHelp(gen.file.step, asking_step, |
| ... | ... | @@ -2370,7 +2386,7 @@ pub const LazyPath = union(enum) { |
| 2370 | 2386 | // path is absolute. |
| 2371 | 2387 | // dirname will return null only if we're at root. |
| 2372 | 2388 | // Typically, we'll stop well before that at the cache root. |
| 2373 | | file_path = fs.path.dirname(file_path) orelse { |
| 2389 | file_path.sub_path = fs.path.dirname(file_path.sub_path) orelse { |
| 2374 | 2390 | dumpBadDirnameHelp(gen.file.step, asking_step, |
| 2375 | 2391 | \\dirname() reached root. |
| 2376 | 2392 | \\No more directories left to go up. |
| ... | ... | @@ -2381,9 +2397,12 @@ pub const LazyPath = union(enum) { |
| 2381 | 2397 | } |
| 2382 | 2398 | } |
| 2383 | 2399 | |
| 2384 | | return src_builder.pathResolve(&.{ file_path, gen.sub_path }); |
| 2400 | return file_path.join(src_builder.allocator, gen.sub_path) catch @panic("OOM"); |
| 2401 | }, |
| 2402 | .dependency => |dep| return .{ |
| 2403 | .root_dir = dep.dependency.builder.build_root, |
| 2404 | .sub_path = dep.sub_path, |
| 2385 | 2405 | }, |
| 2386 | | .dependency => |dep| return dep.dependency.builder.pathFromRoot(dep.sub_path), |
| 2387 | 2406 | } |
| 2388 | 2407 | } |
| 2389 | 2408 | |