mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 07:03:11 +00:00
std.Build.LazyPath: add getPath3; deprecate getPath2 and getPath
The goal is to move towards using `std.Build.Cache.Path` instead of absolute path names. This was helpful for implementing file watching integration to the InstallDir Step
This commit is contained in:
parent
0994e22a64
commit
26bdc836d2
@ -2327,36 +2327,52 @@ pub const LazyPath = union(enum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an absolute path.
|
/// Deprecated, see `getPath3`.
|
||||||
/// Intended to be used during the make phase only.
|
|
||||||
pub fn getPath(lazy_path: LazyPath, src_builder: *Build) []const u8 {
|
pub fn getPath(lazy_path: LazyPath, src_builder: *Build) []const u8 {
|
||||||
return getPath2(lazy_path, src_builder, null);
|
return getPath2(lazy_path, src_builder, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an absolute path.
|
/// Deprecated, see `getPath3`.
|
||||||
|
pub fn getPath2(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
|
||||||
|
const p = getPath3(lazy_path, src_builder, asking_step);
|
||||||
|
return src_builder.pathResolve(&.{ p.root_dir.path orelse ".", p.sub_path });
|
||||||
|
}
|
||||||
|
|
||||||
/// Intended to be used during the make phase only.
|
/// Intended to be used during the make phase only.
|
||||||
///
|
///
|
||||||
/// `asking_step` is only used for debugging purposes; it's the step being
|
/// `asking_step` is only used for debugging purposes; it's the step being
|
||||||
/// run that is asking for the path.
|
/// run that is asking for the path.
|
||||||
pub fn getPath2(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
|
pub fn getPath3(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) Cache.Path {
|
||||||
switch (lazy_path) {
|
switch (lazy_path) {
|
||||||
.src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path),
|
.src_path => |sp| return .{
|
||||||
.cwd_relative => |p| return src_builder.pathFromCwd(p),
|
.root_dir = sp.owner.build_root,
|
||||||
|
.sub_path = sp.sub_path,
|
||||||
|
},
|
||||||
|
.cwd_relative => |sub_path| return .{
|
||||||
|
.root_dir = Cache.Directory.cwd(),
|
||||||
|
.sub_path = sub_path,
|
||||||
|
},
|
||||||
.generated => |gen| {
|
.generated => |gen| {
|
||||||
var file_path: []const u8 = gen.file.step.owner.pathFromRoot(gen.file.path orelse {
|
// TODO make gen.file.path not be absolute and use that as the
|
||||||
|
// basis for not traversing up too many directories.
|
||||||
|
|
||||||
|
var file_path: Cache.Path = .{
|
||||||
|
.root_dir = gen.file.step.owner.build_root,
|
||||||
|
.sub_path = gen.file.path orelse {
|
||||||
std.debug.lockStdErr();
|
std.debug.lockStdErr();
|
||||||
const stderr = std.io.getStdErr();
|
const stderr = std.io.getStdErr();
|
||||||
dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {};
|
dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {};
|
||||||
std.debug.unlockStdErr();
|
std.debug.unlockStdErr();
|
||||||
@panic("misconfigured build script");
|
@panic("misconfigured build script");
|
||||||
});
|
},
|
||||||
|
};
|
||||||
|
|
||||||
if (gen.up > 0) {
|
if (gen.up > 0) {
|
||||||
const cache_root_path = src_builder.cache_root.path orelse
|
const cache_root_path = src_builder.cache_root.path orelse
|
||||||
(src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM"));
|
(src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM"));
|
||||||
|
|
||||||
for (0..gen.up) |_| {
|
for (0..gen.up) |_| {
|
||||||
if (mem.eql(u8, file_path, cache_root_path)) {
|
if (mem.eql(u8, file_path.sub_path, cache_root_path)) {
|
||||||
// If we hit the cache root and there's still more to go,
|
// If we hit the cache root and there's still more to go,
|
||||||
// the script attempted to go too far.
|
// the script attempted to go too far.
|
||||||
dumpBadDirnameHelp(gen.file.step, asking_step,
|
dumpBadDirnameHelp(gen.file.step, asking_step,
|
||||||
@ -2370,7 +2386,7 @@ pub const LazyPath = union(enum) {
|
|||||||
// path is absolute.
|
// path is absolute.
|
||||||
// dirname will return null only if we're at root.
|
// dirname will return null only if we're at root.
|
||||||
// Typically, we'll stop well before that at the cache root.
|
// Typically, we'll stop well before that at the cache root.
|
||||||
file_path = fs.path.dirname(file_path) orelse {
|
file_path.sub_path = fs.path.dirname(file_path.sub_path) orelse {
|
||||||
dumpBadDirnameHelp(gen.file.step, asking_step,
|
dumpBadDirnameHelp(gen.file.step, asking_step,
|
||||||
\\dirname() reached root.
|
\\dirname() reached root.
|
||||||
\\No more directories left to go up.
|
\\No more directories left to go up.
|
||||||
@ -2381,9 +2397,12 @@ pub const LazyPath = union(enum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return src_builder.pathResolve(&.{ file_path, gen.sub_path });
|
return file_path.join(src_builder.allocator, gen.sub_path) catch @panic("OOM");
|
||||||
|
},
|
||||||
|
.dependency => |dep| return .{
|
||||||
|
.root_dir = dep.dependency.builder.build_root,
|
||||||
|
.sub_path = dep.sub_path,
|
||||||
},
|
},
|
||||||
.dependency => |dep| return dep.dependency.builder.pathFromRoot(dep.sub_path),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user