BaseTools: Honor DSC conditional branches during post-process#12856
Open
kirkchoutw wants to merge 1 commit into
Open
BaseTools: Honor DSC conditional branches during post-process#12856kirkchoutw wants to merge 1 commit into
kirkchoutw wants to merge 1 commit into
Conversation
When DSC conditional directives disable a branch, data records inside the branch should not be processed. Previously macro expansion, PCD processing and include evaluation could still be performed on records from disabled branches during post-process, which might trigger build failures for undefined macros or non-existent include files. Introduce a centralized _Enabled gate in DscParser._PostProcess() so that only conditional directives and section context records are processed while a branch is disabled. This preserves directive-stack correctness while preventing side effects from inactive branches. Also reset _Enabled at the beginning of post-process to avoid stale state from raw parsing. Signed-off-by: Kirk Chou <kirk.chou@hpe.com>
tianocore-assign-reviewers
Bot
requested review from
AshrafAliS,
YuweiChen1110,
gapalomi,
lgao4 and
ponchofigueroa
July 22, 2026 20:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When DSC conditional directives (!if/!ifdef/!ifndef/!else/!elseif) disable a branch, the data records inside that branch should not be processed during post-process. Previously, macro expansion, PCD processing, and "!include" evaluation could still be performed on records belonging to disabled branches, which could trigger build failures due to undefined macros or non-existent include files.
This PR introduces a centralized "_Enabled" gate in "DscParser._PostProcess()". Only conditional-directive records and section context records (section/subsection headers) are always processed, while all other records are skipped when the current branch is disabled. This preserves directive-stack correctness while preventing side effects from inactive
branches. "_Enabled" is also reset at the beginning of post-process to avoid stale state carried over from raw parsing.
The per-processor "if not self._Enabled: return" guards (in "_ProcessError", "__ProcessDefine", "__ProcessDirective"/include handling, and "__ProcessPcd") are removed in favor of the single gate, simplifying the logic.
How This Was Tested
Tested with the standard build command using a real package - MdePkg.
A disabled conditional branch containing an undefined macro was temporarily added to MdePkg/MdePkg.dsc :
[LibraryClasses]
SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
!if 0
DisabledLib|$(THIS_MACRO_IS_NOT_DEFINED)/DisabledLib.inf
!endif
Build command :
Results:
The same module also builds cleanly with no disabled branch present, confirming active-branch parsing is unaffected.
Integration Instructions
N/A