fud-core 0.0.2

Library for building declarative build tools
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use camino::{Utf8Path, Utf8PathBuf};
use pathdiff::diff_utf8_paths;

/// Get a version of `path` that works when the working directory is `base`. This is
/// opportunistically a relative path, but we can always fall back to an absolute path to make sure
/// the path still works.
pub fn relative_path(path: &Utf8Path, base: &Utf8Path) -> Utf8PathBuf {
    match diff_utf8_paths(path, base) {
        Some(p) => p,
        None => path
            .canonicalize_utf8()
            .expect("could not get absolute path"),
    }
}