Immediately (in the configure phase), searches for an executable on the host that has more than one possible name.
Calling this function poisons the configuration cache, so it is only
appropriate when the existence of the program or its output needs to be
observed by configuration logic. For more information, see
Graph.CachePoison documentation.
Names are searched in order, observing search prefixes first and then PATH environment variable.
Windows file name extensions are searched automatically, respecting the PATHEXT environment variable, so they need not be included in this list. However, even on Windows, the names will be checked without appending extensions first, so that can be used as a priority system.
See also:
findProgramLazypub fn findProgram(b: *Build, options: FindProgramOptions) ?[]const u8
pub fn findProgram(b: *Build, options: FindProgramOptions) ?[]const u8 {
const graph = b.graph;
// Because it observes search prefixes and contents of directories in PATH.
graph.poisonCache();
for (options.names) |name| {
if (Io.Dir.path.isAbsolute(name)) {
if (tryFindProgram(b, name)) |found| return found;
}
for (graph.search_prefixes.items) |search_prefix| {
const full_path = b.pathJoin(&.{ search_prefix, "bin", name });
if (tryFindProgram(b, full_path)) |found| return found;
}
}
if (b.graph.environ_map.get("PATH")) |PATH| {
for (options.names) |name| {
var it = mem.tokenizeScalar(u8, PATH, Io.Dir.path.delimiter);
while (it.next()) |p| {
const full_path = b.pathJoin(&.{ p, name });
if (tryFindProgram(b, full_path)) |found| return found;
}
}
}
return null;
}