From 64ba56eda176e22351331c76d78a7238c6e7189f Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 6 Apr 2021 15:23:21 -0600 Subject: handle else ifs correctly --- src/makefile/conditional.rs | 5 ++++- src/makefile/input.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/makefile/conditional.rs b/src/makefile/conditional.rs index 989dfc9..95cab9e 100644 --- a/src/makefile/conditional.rs +++ b/src/makefile/conditional.rs @@ -168,7 +168,10 @@ impl Line { StateAction::Replace(State::SkippingUntilEndIf) } Some(State::SkippingUntilElseOrEndIf) => { - inner_condition.action(current_state, is_macro_defined, expand_macro)? + match inner_condition.action(current_state, is_macro_defined, expand_macro)? { + StateAction::Push(x) => StateAction::Replace(x), + x => x, + } } None => bail!("got an ElseIf but not in a conditional"), }, diff --git a/src/makefile/input.rs b/src/makefile/input.rs index 700bf4b..601a159 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -766,6 +766,25 @@ endef Ok(()) } + #[cfg(feature = "full")] + #[test] + fn elseif() -> R { + let file = " +ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE + KBUILD_CFLAGS += -O2 +else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 + KBUILD_CFLAGS += -O3 +else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE + KBUILD_CFLAGS += -Os +endif +FOO = bar +"; + let args = Args::empty(); + let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?; + assert_eq!(makefile.expand_macros(&TokenString::r#macro("FOO"))?, "bar",); + Ok(()) + } + #[test] #[cfg(feature = "full")] fn eval() -> R { -- cgit v1.2.3