Documentation
Path Helpers
Functions for manipulating file paths. These are essential for building paths to sources, archives, and install destinations.
Section
Overview
Path helpers let you build paths programmatically instead of string concatenation. Use join_path() to combine path segments safely.
Section
join_path
Join two path segments. Handles trailing slashes correctly.
Command
rhai
let src = join_path(BUILD_DIR, "foo-1.0");
// BUILD_DIR/foo-1.0
let binary = join_path(src, "target/release/myapp");
// BUILD_DIR/foo-1.0/target/release/myapp
let dest = join_path(PREFIX, "bin/myapp");
// /usr/local/bin/myapp Section
dirname
Get the parent directory of a path.
Command
rhai
let parent = dirname("/home/user/foo/bar");
// "/home/user/foo"
// Useful for finding monorepo root from BUILD_DIR
let leviso_dir = dirname(BUILD_DIR);
let monorepo = dirname(leviso_dir); Section
basename
Get the final component of a path (filename or directory name).
Command
rhai
let name = basename("/home/user/foo.tar.gz");
// "foo.tar.gz"
let dir = basename("/home/user/projects/myapp");
// "myapp" Section
Common Patterns
Path helpers are commonly used to:
Command
rhai
// Build archive destination path
let archive = download(url, join_path(BUILD_DIR, ctx.name + ".tar.gz"));
// Build source directory path after extraction
ctx.source_dir = join_path(BUILD_DIR, ctx.name + "-" + ctx.version);
// Build install destination paths
let bin_dest = join_path(PREFIX, "bin/" + ctx.name);
let man_dest = join_path(PREFIX, "share/man/man1/" + ctx.name + ".1");
// Navigate relative to BUILD_DIR
let leviso_dir = dirname(BUILD_DIR);
let output_dir = join_path(leviso_dir, "output");
let staging = join_path(output_dir, "staging");