From 433bbe6e493adeb75d8799e01a84968aa97db1a0 Mon Sep 17 00:00:00 2001 From: Sergii Dmytruk Date: Sat, 9 Aug 2025 16:47:12 +0300 Subject: BaseTools: DSC: fix processing !include in multiarch subsections Commit f0a2015373 ("UefiPayloadPkg: Add AARCH64 support") changed `[Components.X64]` to `[Components.X64, Components.AARCH64]` which resulted in the following code within that section to not work as expected (the code wasn't there, just providing a real world example that uncovered the issue): [Components.X64, Components.AARCH64] FmpDevicePkg/FmpDxe/FmpDxe.inf { ... !include .../...PcdFmpDevicePkcs7CertBufferXdr.inc ... } At the same time `[Components.X64]` or even `[Components.AARCH64, Components.X64]` (notice the swapped order) worked fine for X64 target. The cause of the issue turned out to be skipping includes inside `_PostProcess()` method of `DscParser` class. This method processes list of items stored in a database filled on the first pass through a DSC file in `Start()` method. One of the fields stored in each row of a table is link to a parent object (owner). A section like `[Components.X64, Components.AARCH64]` creates two objects and all of its subelements are duplicated for both X64 and AARCH64. This was not happening for !include statement in the example above. Because `_PostProcess()` contracted a sequence of !include objects disregarding their owner, it did not create instance for each of the requested targets. Codewise, `self._ContentIndex` was incremented more than once, while `__ProcessDirective()` method (invoked indirectly as `Processer[self._ItemType]()`) queried owner of the current directive as: if self._InSubsection: Owner = self._Content[self._ContentIndex - 1][8] else: # not taken in this case This is why order of targets made a difference, only the last was fully initialized in this case. An alternative fix is completely dropping merging of !include directives, but hard to say whether it still has some utility (the code is complex, hard to follow and barely documented). Safer to keep it, in the worst case it doesn't do anything now. Signed-off-by: Sergii Dmytruk --- BaseTools/Source/Python/Workspace/MetaFileParser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'BaseTools/Source/Python/Workspace/MetaFileParser.py') diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index ed1ccb1cf1..5d2a44481d 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1407,7 +1407,11 @@ class DscParser(MetaFileParser): if self._ContentIndex >= len(self._Content): break Record = self._Content[self._ContentIndex] - if LineStart == Record[10] and LineEnd == Record[12]: + # + # Avoid merging includes with different owners to make sure an + # include is correctly processed per arch. + # + if Owner == Record[8] and LineStart == Record[10] and LineEnd == Record[12]: if [Record[5], Record[6], Record[7]] not in self._Scope: self._Scope.append([Record[5], Record[6], Record[7]]) self._ContentIndex += 1 -- cgit v1.2.3