aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-05 11:41:17 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-05 11:41:17 -0600
commitc50170f000d382fa02090fbf79d0e5d12036f53b (patch)
tree99172664a9e670788eaa737510f57a55ca551a1d
parent45529cca7626677416c8d6048b5de8f4ff615fb8 (diff)
downloadmakers-c50170f000d382fa02090fbf79d0e5d12036f53b.tar.gz
makers-c50170f000d382fa02090fbf79d0e5d12036f53b.zip
implement function `realpath`
-rw-r--r--src/makefile/functions.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 6dacd10..6815ac4 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -53,6 +53,10 @@ pub fn expand_call(
assert_eq!(args.len(), 1);
file_name::wildcard(macros, &args[0])
}
+ "realpath" => {
+ assert_eq!(args.len(), 1);
+ file_name::realpath(macros, &args[0])
+ }
"if" => {
assert!(args.len() == 2 || args.len() == 3);
@@ -179,6 +183,7 @@ mod text {
mod file_name {
use std::env;
use std::ffi::OsStr;
+ use std::fs;
use std::path::Path;
use eyre::WrapErr;
@@ -246,6 +251,19 @@ mod file_name {
.collect::<Vec<_>>();
Ok(results.join(" "))
}
+
+ pub fn realpath(macros: &MacroSet, targets: &TokenString) -> Result<String> {
+ let targets = macros.expand(targets)?;
+ let results = targets
+ .split_whitespace()
+ .map(|x| {
+ fs::canonicalize(x)
+ .map(|p| p.to_string_lossy().into_owned())
+ .unwrap_or_else(|_| x.to_owned())
+ })
+ .collect::<Vec<_>>();
+ Ok(results.join(" "))
+ }
}
// Functions for Conditionals