Docs: Path Helpers

Documentation

Path Helpers

Pure functions for building paths and working with strings. They have no effects and never touch the filesystem.

Overview

Build paths from src, out, WORK and the other engine constants with join_path() instead of string concatenation.

join_path

Join two path segments.

Rhai
let dir = join_path(WORK, "foo-1.0");
// WORK + "/foo-1.0"
let program = join_path(out, "bin/myapp");
// the output folder + "/bin/myapp"

dirname / basename

Get the parent directory, or the final component, of a path.

Rhai
dirname("/out/bin/myapp");          // "/out/bin"
basename("/work/build/foo.tar.gz");  // "foo.tar.gz"

String Helpers

HelperReturns
trim(s)s without leading and trailing whitespace
starts_with(s, prefix) / ends_with(s, suffix)bool
contains(s, pattern)bool
replace(s, from, to)s with every from replaced
split(s, sep)Array of strings
Rhai
let release = trim(read_file(join_path(src.source, "VERSION")));
if ends_with(archive, ".zip") {
    extract_with_format(archive, WORK, "zip");
}
let parts = split(PACKAGE.version, ".");

Common Patterns

Rhai
fn build(src, out) {
    let archive = join_path(WORK, "foo-1.0.tar.gz");
    let dir = join_path(WORK, "foo-1.0");
    let program = join_path(out, "bin/foo");
    let manpage = join_path(out, "share/man/man1/foo.1");
}