aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/input.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2024-11-11 00:07:33 -0700
committerMelody Horn <melody@boringcactus.com>2024-11-11 00:07:33 -0700
commitec2c18171cd316a8b1f69baf92f67980820dfc9a (patch)
tree007add1cd59aec07098134b018efededee463d97 /src/makefile/input.rs
parent825ff799a2154ffb94ef21bbc14e2afe2afa2006 (diff)
downloadmakers-ec2c18171cd316a8b1f69baf92f67980820dfc9a.tar.gz
makers-ec2c18171cd316a8b1f69baf92f67980820dfc9a.zip
overhaul macro inheritance
i was really proud of the lifetimes i had going on in the previous code. i should not have been.
Diffstat (limited to 'src/makefile/input.rs')
-rw-r--r--src/makefile/input.rs49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/makefile/input.rs b/src/makefile/input.rs
index bbfdaee..40720c2 100644
--- a/src/makefile/input.rs
+++ b/src/makefile/input.rs
@@ -13,19 +13,19 @@ use regex::Regex;
use crate::args::Args;
-use super::command_line::CommandLine;
#[cfg(feature = "full")]
use super::conditional::{Line as ConditionalLine, State as ConditionalState};
#[cfg(feature = "full")]
use super::eval_context::DeferredEvalContext;
-use super::inference_rules::InferenceRule;
#[cfg(feature = "full")]
use super::r#macro::ExportConfig;
-use super::r#macro::{Macro, Set as MacroSet};
-use super::target::{StaticTargetSet, Target};
-use super::token::{Token, TokenString};
-use super::LookupInternal;
-use super::{builtin_targets, ItemSource};
+use super::r#macro::Macro;
+use super::target::StaticTargetSet;
+use super::token::Token;
+use super::{
+ builtin_targets, CommandLine, InferenceRule, ItemSource, LookupInternal, MacroScopeStack,
+ MacroSet, Target, TokenString,
+};
enum LineType {
Rule,
@@ -188,7 +188,8 @@ impl Default for NextLineSettings {
pub struct MakefileReader<'a, 'parent, R: BufRead> {
file_name: String,
pub inference_rules: Vec<InferenceRule>,
- pub macros: MacroSet<'parent, 'static>,
+ pub stack: MacroScopeStack<'parent>,
+ pub macros: MacroSet,
pub targets: StaticTargetSet,
built_in_targets: HashMap<String, Target>,
pub first_non_special_target: Option<String>,
@@ -205,10 +206,11 @@ pub struct MakefileReader<'a, 'parent, R: BufRead> {
impl<'a, 'parent> MakefileReader<'a, 'parent, BufReader<File>> {
pub fn read_file(
args: &'a Args,
- mut macros: MacroSet<'parent, 'static>,
+ stack: MacroScopeStack<'parent>,
path: impl AsRef<Path>,
file_names: Rc<RefCell<Vec<String>>>,
) -> Result<Self> {
+ let mut macros = MacroSet::new();
#[cfg(feature = "full")]
if let Some(mut old_makefile_list) = macros.pop("MAKEFILE_LIST") {
old_makefile_list.text.extend(TokenString::text(format!(
@@ -233,14 +235,15 @@ impl<'a, 'parent> MakefileReader<'a, 'parent, BufReader<File>> {
// TODO handle errors
let file = file.context("couldn't open makefile!")?;
let file_reader = BufReader::new(file);
- Self::read(args, macros, file_reader, file_name, file_names)
+ Self::read(args, stack, macros, file_reader, file_name, file_names)
}
}
impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
pub fn read(
args: &'a Args,
- macros: MacroSet<'parent, 'static>,
+ stack: MacroScopeStack<'parent>,
+ macros: MacroSet,
source: R,
name: impl Into<String>,
file_names: Rc<RefCell<Vec<String>>>,
@@ -249,6 +252,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
let mut reader = Self {
file_name: name.clone(),
inference_rules: Vec::new(),
+ stack,
macros,
targets: Default::default(),
built_in_targets: HashMap::new(),
@@ -525,10 +529,10 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
// handles arbitrarily many filenames, and it's not like that's more work
for field in fields {
log::trace!("{}:{}: including {}", &self.file_name, line_number, field);
- let child_macros = self.macros.with_overlay();
+ let child_stack = self.stack.with_scope(&self.macros);
let child = MakefileReader::read_file(
self.args,
- child_macros,
+ child_stack,
field,
Rc::clone(&self.file_names),
)
@@ -591,8 +595,9 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
#[cfg(feature = "full")]
let mut deferred_eval_context = DeferredEvalContext::new(self);
let prerequisites = self
- .macros
- .with_lookup(LookupInternal::new_partial(&targets))
+ .stack
+ .with_scope(&self.macros)
+ .with_scope(&LookupInternal::new_partial(&targets))
.expand(
&prerequisites,
#[cfg(feature = "full")]
@@ -890,7 +895,8 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
text: &TokenString,
#[cfg(feature = "full")] deferred_eval_context: &mut DeferredEvalContext<R>,
) -> Result<String> {
- self.macros
+ self.stack
+ .with_scope(&self.macros)
.expand(
text,
#[cfg(feature = "full")]
@@ -960,6 +966,7 @@ a: $(x) b \\
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -988,6 +995,7 @@ endif
let args = Args::empty();
let mut makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1012,6 +1020,7 @@ endif
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1034,6 +1043,7 @@ endef
let args = Args::empty();
let mut makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1062,6 +1072,7 @@ FOO = bar
let args = Args::empty();
let mut makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1110,6 +1121,7 @@ clean:
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1131,6 +1143,7 @@ info:
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1181,6 +1194,7 @@ cursed:
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1205,6 +1219,7 @@ cursed:
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1226,6 +1241,7 @@ test: c
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",
@@ -1246,6 +1262,7 @@ test: c
let args = Args::empty();
let makefile = MakefileReader::read(
&args,
+ MacroScopeStack::default(),
MacroSet::new(),
Cursor::new(file),
"",