diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-05 11:48:45 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-05 11:48:45 -0600 |
commit | b5c3132edbee5e80292c7e3a976bd1bd73d0c420 (patch) | |
tree | 3ca82d35d92a94b731291a3836eeada127c0eea4 | |
parent | c50170f000d382fa02090fbf79d0e5d12036f53b (diff) | |
download | makers-b5c3132edbee5e80292c7e3a976bd1bd73d0c420.tar.gz makers-b5c3132edbee5e80292c7e3a976bd1bd73d0c420.zip |
implement function `dir`
-rw-r--r-- | src/makefile/functions.rs | 18 |
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 |