aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-05 11:48:45 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-05 11:48:45 -0600
commitb5c3132edbee5e80292c7e3a976bd1bd73d0c420 (patch)
tree3ca82d35d92a94b731291a3836eeada127c0eea4
parentc50170f000d382fa02090fbf79d0e5d12036f53b (diff)
downloadmakers-b5c3132edbee5e80292c7e3a976bd1bd73d0c420.tar.gz
makers-b5c3132edbee5e80292c7e3a976bd1bd73d0c420.zip
implement function `dir`
-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 6815ac4..4ead48f 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -37,6 +37,10 @@ pub fn expand_call(
text::sort(macros, &args[0])
}
+ "dir" => {
+ assert_eq!(args.len(), 1);
+ file_name::dir(macros, &args[0])
+ }
"notdir" => {
assert_eq!(args.len(), 1);
file_name::notdir(macros, &args[0])
@@ -190,6 +194,20 @@ mod file_name {
use super::*;
+ pub fn dir(macros: &MacroSet, words: &TokenString) -> Result<String> {
+ let words = macros.expand(words)?;
+ let words = words
+ .split_whitespace()
+ .map(|word| {
+ Path::new(word)
+ .parent()
+ .and_then(Path::to_str)
+ .unwrap_or("./")
+ })
+ .collect::<Vec<_>>();
+ Ok(words.join(" "))
+ }
+
pub fn notdir(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
let words = words