aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/functions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/functions.rs')
-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