mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.Build.LazyPath: fix resolution of cwd_relative
The callsites of getPath rely on the result being absolute so that they can pass the path to a child process with the cwd set to the build root.
This commit is contained in:
parent
bdbd617237
commit
25a9487caa
4 changed files with 26 additions and 23 deletions
|
|
@ -46,7 +46,7 @@ pub fn build(b: *std.Build) !void {
|
||||||
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
|
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
|
||||||
if (b.zig_lib_dir) |p| {
|
if (b.zig_lib_dir) |p| {
|
||||||
docgen_cmd.addArg("--zig-lib-dir");
|
docgen_cmd.addArg("--zig-lib-dir");
|
||||||
docgen_cmd.addFileArg(p);
|
docgen_cmd.addDirectoryArg(p);
|
||||||
}
|
}
|
||||||
docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" });
|
docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" });
|
||||||
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
|
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,9 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
|
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
|
||||||
if (args_it.next()) |param| {
|
if (args_it.next()) |param| {
|
||||||
opt_zig_lib_dir = param;
|
// Convert relative to absolute because this will be passed
|
||||||
|
// to a child process with a different cwd.
|
||||||
|
opt_zig_lib_dir = try fs.realpathAlloc(allocator, param);
|
||||||
} else {
|
} else {
|
||||||
fatal("expected parameter after --zig-lib-dir", .{});
|
fatal("expected parameter after --zig-lib-dir", .{});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1390,6 +1390,11 @@ pub fn pathFromRoot(b: *Build, p: []const u8) []u8 {
|
||||||
return fs.path.resolve(b.allocator, &.{ b.build_root.path orelse ".", p }) catch @panic("OOM");
|
return fs.path.resolve(b.allocator, &.{ b.build_root.path orelse ".", p }) catch @panic("OOM");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pathFromCwd(b: *Build, p: []const u8) []u8 {
|
||||||
|
const cwd = process.getCwdAlloc(b.allocator) catch @panic("OOM");
|
||||||
|
return fs.path.resolve(b.allocator, &.{ cwd, p }) catch @panic("OOM");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn pathJoin(self: *Build, paths: []const []const u8) []u8 {
|
pub fn pathJoin(self: *Build, paths: []const []const u8) []u8 {
|
||||||
return fs.path.join(self.allocator, paths) catch @panic("OOM");
|
return fs.path.join(self.allocator, paths) catch @panic("OOM");
|
||||||
}
|
}
|
||||||
|
|
@ -1706,17 +1711,13 @@ pub const LazyPath = union(enum) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a path relative to the current process's current working directory, suitable
|
/// Returns an absolute path.
|
||||||
/// for direct file system operations.
|
|
||||||
///
|
|
||||||
/// Intended to be used during the make phase only.
|
/// Intended to be used during the make phase only.
|
||||||
pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 {
|
pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 {
|
||||||
return getPath2(self, src_builder, null);
|
return getPath2(self, src_builder, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a path relative to the current process's current working directory, suitable
|
/// Returns an absolute path.
|
||||||
/// for direct file system operations.
|
|
||||||
///
|
|
||||||
/// 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
|
||||||
|
|
@ -1724,7 +1725,7 @@ pub const LazyPath = union(enum) {
|
||||||
pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
|
pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.path => |p| return src_builder.pathFromRoot(p),
|
.path => |p| return src_builder.pathFromRoot(p),
|
||||||
.cwd_relative => |p| return p,
|
.cwd_relative => |p| return src_builder.pathFromCwd(p),
|
||||||
.generated => |gen| return gen.path orelse {
|
.generated => |gen| return gen.path orelse {
|
||||||
std.debug.getStderrMutex().lock();
|
std.debug.getStderrMutex().lock();
|
||||||
const stderr = std.io.getStdErr();
|
const stderr = std.io.getStdErr();
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ has_side_effects: bool = false,
|
||||||
pub const StdIn = union(enum) {
|
pub const StdIn = union(enum) {
|
||||||
none,
|
none,
|
||||||
bytes: []const u8,
|
bytes: []const u8,
|
||||||
file_source: std.Build.LazyPath,
|
lazy_path: std.Build.LazyPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const StdIo = union(enum) {
|
pub const StdIo = union(enum) {
|
||||||
|
|
@ -120,7 +120,7 @@ pub const StdIo = union(enum) {
|
||||||
|
|
||||||
pub const Arg = union(enum) {
|
pub const Arg = union(enum) {
|
||||||
artifact: *Step.Compile,
|
artifact: *Step.Compile,
|
||||||
file_source: PrefixedLazyPath,
|
lazy_path: PrefixedLazyPath,
|
||||||
directory_source: PrefixedLazyPath,
|
directory_source: PrefixedLazyPath,
|
||||||
bytes: []u8,
|
bytes: []u8,
|
||||||
output: *Output,
|
output: *Output,
|
||||||
|
|
@ -128,7 +128,7 @@ pub const Arg = union(enum) {
|
||||||
|
|
||||||
pub const PrefixedLazyPath = struct {
|
pub const PrefixedLazyPath = struct {
|
||||||
prefix: []const u8,
|
prefix: []const u8,
|
||||||
file_source: std.Build.LazyPath,
|
lazy_path: std.Build.LazyPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Output = struct {
|
pub const Output = struct {
|
||||||
|
|
@ -213,9 +213,9 @@ pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath
|
||||||
|
|
||||||
const prefixed_file_source: PrefixedLazyPath = .{
|
const prefixed_file_source: PrefixedLazyPath = .{
|
||||||
.prefix = b.dupe(prefix),
|
.prefix = b.dupe(prefix),
|
||||||
.file_source = lp.dupe(b),
|
.lazy_path = lp.dupe(b),
|
||||||
};
|
};
|
||||||
self.argv.append(.{ .file_source = prefixed_file_source }) catch @panic("OOM");
|
self.argv.append(.{ .lazy_path = prefixed_file_source }) catch @panic("OOM");
|
||||||
lp.addStepDependencies(&self.step);
|
lp.addStepDependencies(&self.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +234,7 @@ pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source:
|
||||||
|
|
||||||
const prefixed_directory_source: PrefixedLazyPath = .{
|
const prefixed_directory_source: PrefixedLazyPath = .{
|
||||||
.prefix = b.dupe(prefix),
|
.prefix = b.dupe(prefix),
|
||||||
.file_source = directory_source.dupe(b),
|
.lazy_path = directory_source.dupe(b),
|
||||||
};
|
};
|
||||||
self.argv.append(.{ .directory_source = prefixed_directory_source }) catch @panic("OOM");
|
self.argv.append(.{ .directory_source = prefixed_directory_source }) catch @panic("OOM");
|
||||||
directory_source.addStepDependencies(&self.step);
|
directory_source.addStepDependencies(&self.step);
|
||||||
|
|
@ -252,7 +252,7 @@ pub fn addArgs(self: *Run, args: []const []const u8) void {
|
||||||
|
|
||||||
pub fn setStdIn(self: *Run, stdin: StdIn) void {
|
pub fn setStdIn(self: *Run, stdin: StdIn) void {
|
||||||
switch (stdin) {
|
switch (stdin) {
|
||||||
.file_source => |file_source| file_source.addStepDependencies(&self.step),
|
.lazy_path => |lazy_path| lazy_path.addStepDependencies(&self.step),
|
||||||
.bytes, .none => {},
|
.bytes, .none => {},
|
||||||
}
|
}
|
||||||
self.stdin = stdin;
|
self.stdin = stdin;
|
||||||
|
|
@ -444,14 +444,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
|
||||||
try argv_list.append(bytes);
|
try argv_list.append(bytes);
|
||||||
man.hash.addBytes(bytes);
|
man.hash.addBytes(bytes);
|
||||||
},
|
},
|
||||||
.file_source => |file| {
|
.lazy_path => |file| {
|
||||||
const file_path = file.file_source.getPath(b);
|
const file_path = file.lazy_path.getPath(b);
|
||||||
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
|
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
|
||||||
man.hash.addBytes(file.prefix);
|
man.hash.addBytes(file.prefix);
|
||||||
_ = try man.addFile(file_path, null);
|
_ = try man.addFile(file_path, null);
|
||||||
},
|
},
|
||||||
.directory_source => |file| {
|
.directory_source => |file| {
|
||||||
const file_path = file.file_source.getPath(b);
|
const file_path = file.lazy_path.getPath(b);
|
||||||
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
|
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
|
||||||
man.hash.addBytes(file.prefix);
|
man.hash.addBytes(file.prefix);
|
||||||
man.hash.addBytes(file_path);
|
man.hash.addBytes(file_path);
|
||||||
|
|
@ -486,8 +486,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
|
||||||
.bytes => |bytes| {
|
.bytes => |bytes| {
|
||||||
man.hash.addBytes(bytes);
|
man.hash.addBytes(bytes);
|
||||||
},
|
},
|
||||||
.file_source => |file_source| {
|
.lazy_path => |lazy_path| {
|
||||||
const file_path = file_source.getPath(b);
|
const file_path = lazy_path.getPath(b);
|
||||||
_ = try man.addFile(file_path, null);
|
_ = try man.addFile(file_path, null);
|
||||||
},
|
},
|
||||||
.none => {},
|
.none => {},
|
||||||
|
|
@ -1186,8 +1186,8 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult {
|
||||||
child.stdin.?.close();
|
child.stdin.?.close();
|
||||||
child.stdin = null;
|
child.stdin = null;
|
||||||
},
|
},
|
||||||
.file_source => |file_source| {
|
.lazy_path => |lazy_path| {
|
||||||
const path = file_source.getPath(self.step.owner);
|
const path = lazy_path.getPath(self.step.owner);
|
||||||
const file = self.step.owner.build_root.handle.openFile(path, .{}) catch |err| {
|
const file = self.step.owner.build_root.handle.openFile(path, .{}) catch |err| {
|
||||||
return self.step.fail("unable to open stdin file: {s}", .{@errorName(err)});
|
return self.step.fail("unable to open stdin file: {s}", .{@errorName(err)});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue