Documentation
Filesystem Helpers
File and directory operations including path checks, manipulation, and reading.
Section
exists / is_file / is_dir
Check if paths exist. These are essential for the is_* check functions in recipes.
// Check if anything exists at path
if exists("/usr/bin/gcc") {
set_env("CC", "gcc");
}
// Check specifically for a file
if is_file(join_path(ctx.source_dir, "configure")) {
shell_in(ctx.source_dir, "./configure");
}
// Check specifically for a directory
if is_dir(join_path(BUILD_DIR, "vendor")) {
log("Vendor directory exists");
} Aliases: file_exists() = is_file(), dir_exists() = is_dir()
Section
mkdir
Create a directory and all parent directories (like mkdir -p).
mkdir(BUILD_DIR);
mkdir(join_path(PREFIX, "bin"));
mkdir(join_path(PREFIX, "share/man/man1")); Section
rm
Remove files or directories. Accepts a path string.
rm(join_path(BUILD_DIR, "tmp"));
rm(join_path(ctx.source_dir, "build")); Section
mv
Move or rename a file.
mv(
join_path(ctx.source_dir, "config.example"),
join_path(ctx.source_dir, "config.toml")
); Section
ln
Create a symbolic link. First argument is the target, second is the link name.
// Create symlink: /usr/local/bin/python -> python3
ln(
join_path(PREFIX, "bin/python3"),
join_path(PREFIX, "bin/python")
); Section
chmod
Change file permissions. Takes octal mode as integer.
chmod(join_path(PREFIX, "bin/myapp"), 0o755); // rwxr-xr-x
chmod(join_path(PREFIX, "etc/secret.key"), 0o600); // rw------- Section
read_file / read_file_or_empty
Read a file's contents as a string. read_file_or_empty() returns empty string if file doesn't exist instead of throwing.
// Read kernel version from file
let version = trim(read_file(join_path(build_dir, "include/config/kernel.release")));
// Read with fallback to empty
let cached_hash = read_file_or_empty(join_path(build_dir, ".hash"));
if cached_hash == "" {
// No cached hash, need to rebuild
} Section
write_file / append_file
Write or append content to a file.
write_file(join_path(build_dir, ".hash"), new_hash);
append_file(join_path(PREFIX, "etc/shells"), "/bin/zsh\n"); Section
glob_list
List files matching a glob pattern. Returns an array of paths.
let sources = glob_list(join_path(ctx.source_dir, "src/*.c"));
for file in sources {
log("Found: " + file);
}