diff options
| author | Dongyan Qian <qiandongyan@loongson.cn> | 2026-09-16 09:45:38 +0300 |
|---|---|---|
| committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2026-10-08 06:58:55 +0300 |
| commit | c51403090f63efa4e463cd17095dd9f012a00c4b (patch) | |
| tree | 81d5f4d5ea04f1e735d8ba3c7ac6928772f4ebaa /BaseTools/Source/Python/Workspace | |
| parent | 78fdd2db8932d619eced4c69ef06a13c4f6469b2 (diff) | |
| download | edk2-c51403090f63efa4e463cd17095dd9f012a00c4b.tar.xz | |
BaseTools: Reject trailing content after !else and !endif
The DSC parser accepts "!else if <expression>" as an unconditional
!else branch without evaluating the trailing condition. This can select
an unintended build branch instead of reporting the syntax error.
For example, the following incorrect syntax is currently accepted:
!if $(MODE) == 1
# Branch A
!else if $(MODE) == 2
# Branch B
!endif
When MODE is 3, the parser treats the second directive as a plain !else
and selects branch B. Replacing it with "!elseif $(MODE) == 2" would
correctly select neither branch.
Reject trailing content after !else and !endif. When the first word
following !else is "if", suggest "!elseif <expression>" instead.
Trailing comments remain valid because they are removed before
directive parsing.
Cc: Fei Shen <shenfei@loongson.cn>
Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
Diffstat (limited to 'BaseTools/Source/Python/Workspace')
| -rw-r--r-- | BaseTools/Source/Python/Workspace/MetaFileParser.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index e3f0e6334c..0185240bca 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1087,6 +1087,14 @@ class DscParser(MetaFileParser): File=self.MetaFile, Line=self._LineIndex + 1,
ExtraData=self._CurrentLine)
+ if DirectiveName in ['!ELSE', '!ENDIF'] and self._ValueList[1] != '':
+ Message = "Unexpected content after '%s'" % self._ValueList[0]
+ if DirectiveName == '!ELSE' and self._ValueList[1].split()[0].lower() == 'if':
+ Message += "; use '!elseif <expression>' for a conditional branch"
+ EdkLogger.error("Parser", FORMAT_INVALID, Message,
+ File=self.MetaFile, Line=self._LineIndex + 1,
+ ExtraData=self._CurrentLine)
+
ItemType = self.DataType[DirectiveName]
Scope = [[TAB_COMMON, TAB_COMMON, TAB_COMMON]]
if ItemType == MODEL_META_DATA_INCLUDE:
|
