aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/input.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-06 14:11:43 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-06 14:11:43 -0600
commit5a101a96ada9ddbd4be54c46cd7d0125825c2283 (patch)
treedd5b54a8b0917d53e17e9fbd31b7280669bcc0ec /src/makefile/input.rs
parent1602ad07efa6d3c4170928537843a0d61a5cd5e7 (diff)
downloadmakers-5a101a96ada9ddbd4be54c46cd7d0125825c2283.tar.gz
makers-5a101a96ada9ddbd4be54c46cd7d0125825c2283.zip
eagerly expand when appending to eagerly-expanded macros
Diffstat (limited to 'src/makefile/input.rs')
-rw-r--r--src/makefile/input.rs56
1 files changed, 37 insertions, 19 deletions
diff --git a/src/makefile/input.rs b/src/makefile/input.rs
index 5dfaed7..5883590 100644
--- a/src/makefile/input.rs
+++ b/src/makefile/input.rs
@@ -16,7 +16,7 @@ use super::command_line::CommandLine;
#[cfg(feature = "full")]
use super::conditional::{Line as ConditionalLine, State as ConditionalState};
use super::inference_rules::InferenceRule;
-use super::r#macro::{Set as MacroSet, Source as MacroSource};
+use super::r#macro::{Macro, Set as MacroSet, Source as MacroSource};
use super::target::Target;
use super::token::{tokenize, Token, TokenString};
@@ -162,21 +162,21 @@ impl<'a, 'parent> MakefileReader<'a, 'parent, BufReader<File>> {
path: impl AsRef<Path>,
) -> Result<Self> {
#[cfg(feature = "full")]
- if let Some((_, mut old_makefile_list)) = macros.pop("MAKEFILE_LIST") {
- old_makefile_list.extend(TokenString::text(format!(
+ if let Some(mut old_makefile_list) = macros.pop("MAKEFILE_LIST") {
+ old_makefile_list.text.extend(TokenString::text(format!(
" {}",
path.as_ref().to_string_lossy()
)));
- macros.set(
- "MAKEFILE_LIST".to_owned(),
- MacroSource::Builtin,
- old_makefile_list,
- );
+ macros.set("MAKEFILE_LIST".to_owned(), old_makefile_list);
} else {
macros.set(
"MAKEFILE_LIST".to_owned(),
- MacroSource::Builtin,
- TokenString::text(path.as_ref().to_string_lossy()),
+ Macro {
+ source: MacroSource::Builtin,
+ text: TokenString::text(path.as_ref().to_string_lossy()),
+ #[cfg(feature = "full")]
+ eagerly_expanded: false,
+ },
);
}
let file = File::open(path);
@@ -606,23 +606,41 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
match self.macros.get(name) {
// We always let command line or MAKEFLAGS macros override macros from the file.
- Some((MacroSource::CommandLineOrMakeflags, _)) => return Ok(()),
+ Some(Macro {
+ source: MacroSource::CommandLineOrMakeflags,
+ ..
+ }) => return Ok(()),
// We let environment variables override macros from the file only if the command-line argument to do that was given
- Some((MacroSource::Environment, _)) if self.args.environment_overrides => return Ok(()),
+ Some(Macro {
+ source: MacroSource::Environment,
+ ..
+ }) if self.args.environment_overrides => return Ok(()),
Some(_) if skip_if_defined => return Ok(()),
_ => {}
}
let value = match self.macros.pop(name) {
- Some((_, mut old_value)) if append => {
- // TODO eagerly expand if appending to eagerly-expanded macro
- old_value.extend(TokenString::text(" "));
- old_value.extend(value);
+ Some(mut old_value) if append => {
+ #[cfg(feature = "full")]
+ let value = if old_value.eagerly_expanded {
+ TokenString::text(self.expand_macros(&value).wrap_err_with(|| {
+ format!("while defining {} on line {}", name, line_number)
+ })?)
+ } else {
+ value
+ };
+ old_value.text.extend(TokenString::text(" "));
+ old_value.text.extend(value);
old_value
}
- _ => value,
+ _ => Macro {
+ source: MacroSource::File,
+ text: value,
+ #[cfg(feature = "full")]
+ eagerly_expanded: expand_value,
+ },
};
- self.macros.set(name.into(), MacroSource::File, value);
+ self.macros.set(name.into(), value);
Ok(())
}
@@ -652,7 +670,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
pub struct FinishedMakefileReader {
pub inference_rules: Vec<InferenceRule>,
- pub macros: HashMap<String, (MacroSource, TokenString)>,
+ pub macros: HashMap<String, Macro>,
pub targets: HashMap<String, Target>,
pub first_non_special_target: Option<String>,
}