getPath3
Intended to be used during the make phase only.
asking_step is only used for debugging purposes; it's the step being
run that is asking for the path.
Function parameters
Parameters
Type definitions in this namespace
Types
- Graph
- Shared state among all Build instances.
- GeneratedFile
- A file that is generated by a build step.
- LazyPath
- A reference to an existing or future path.
- ResolvedTarget
- A pair of target query and fully resolved target.
Functions in this namespace
Functions
- resolveInstallPrefix
- This function is intended to be called by lib/build_runner.zig, not a build.zig file.
- addOptions
- Create a set of key-value pairs that can be converted into a Zig source
- addTest
- Creates an executable containing unit tests.
- addModule
- This function creates a module and adds it to the package's module set, making
- createModule
- This function creates a private module, to be used by the current package,
- addSystemCommand
- Initializes a `Step.Run` with argv, which must at least have the path to the
- addRunArtifact
- Creates a `Step.Run` with an executable built with `addExecutable`.
- addConfigHeader
- Using the `values` provided, produces a C header file, possibly based on a
- dupe
- Allocator.dupe without the need to handle out of memory.
- dupeStrings
- Duplicates an array of strings without the need to handle out of memory.
- dupePath
- Duplicates a path and converts all slashes to the OS's canonical path separator.
- option
- Creates a configuration option to be passed to the build.zig script.
- standardTargetOptions
- Exposes standard `zig build` options for choosing a target and additionally
- parseTargetQuery
- Obtain a target query from a string, reporting diagnostics to stderr if the
- standardTargetOptionsQueryOnly
- Exposes standard `zig build` options for choosing a target.
- installArtifact
- This creates the install step and adds it to the dependencies of the
- addInstallArtifact
- This merely creates the step; it does not add it to the dependencies of the
- installFile
- `dest_rel_path` is relative to prefix path
- installBinFile
- `dest_rel_path` is relative to bin path
- installLibFile
- `dest_rel_path` is relative to lib path
- addInstallFile
- `dest_rel_path` is relative to install prefix path
- addInstallBinFile
- `dest_rel_path` is relative to bin path
- addInstallLibFile
- `dest_rel_path` is relative to lib path
- addInstallHeaderFile
- `dest_rel_path` is relative to header path
- path
- References a file or directory relative to the source root.
- pathFromRoot
- This is low-level implementation details of the build system, not meant to
- run
- This is a helper function to be called from build.zig scripts, *not* from
- lazyDependency
- When this function is called, it means that the current build does, in
- lazyImport
- In a build.zig file, this function is to `@import` what `lazyDependency` is to `dependency`.
- dumpBadGetPathHelp
- In this function the stderr mutex has already been locked.
- makeTempPath
- This function is intended to be called in the `configure` phase only.
- resolveTargetQuery
- Converts a target query into a fully resolved target that can be passed to
Error sets in this namespace
Error Sets
Source
Implementation
pub fn getPath3(lazy_path: LazyPath, src_builder: *Build, asking_step: ?*Step) Cache.Path {
switch (lazy_path) {
.src_path => |sp| return .{
.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| {
// 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 = Cache.Directory.cwd(),
.sub_path = gen.file.path orelse {
const w = debug.lockStderrWriter(&.{});
dumpBadGetPathHelp(gen.file.step, w, .detect(.stderr()), src_builder, asking_step) catch {};
debug.unlockStderrWriter();
@panic("misconfigured build script");
},
};
if (gen.up > 0) {
const cache_root_path = src_builder.cache_root.path orelse
(src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM"));
for (0..gen.up) |_| {
if (mem.eql(u8, file_path.sub_path, cache_root_path)) {
// If we hit the cache root and there's still more to go,
// the script attempted to go too far.
dumpBadDirnameHelp(gen.file.step, asking_step,
\\dirname() attempted to traverse outside the cache root.
\\This is not allowed.
\\
, .{}) catch {};
@panic("misconfigured build script");
}
// path is absolute.
// dirname will return null only if we're at root.
// Typically, we'll stop well before that at the cache root.
file_path.sub_path = fs.path.dirname(file_path.sub_path) orelse {
dumpBadDirnameHelp(gen.file.step, asking_step,
\\dirname() reached root.
\\No more directories left to go up.
\\
, .{}) catch {};
@panic("misconfigured build script");
};
}
}
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,
},
}
}