From c88299e851b845b9d89bff13338411c45636ddd4 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 29 Aug 2023 14:52:23 -0700 Subject: [PATCH] instanced_fv_table: better handling of RuleOverride When parsing an FDF file, an INF can be prepending with a RuleOverride directive. The previous functionality to ignore this directive and retrive the actual INF value could not handle any spaces in the directive (such as RuleOverride = ACPITABLE). This commit expands the ability to handle spaces in the directive. --- edk2toollib/database/tables/instanced_fv_table.py | 6 +++++- tests.unit/database/test_instanced_fv_table.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/edk2toollib/database/tables/instanced_fv_table.py b/edk2toollib/database/tables/instanced_fv_table.py index 735564e97..c11d33e6c 100644 --- a/edk2toollib/database/tables/instanced_fv_table.py +++ b/edk2toollib/database/tables/instanced_fv_table.py @@ -7,6 +7,7 @@ # SPDX-License-Identifier: BSD-2-Clause-Patent ## """A module to generate a table containing fv information.""" +import re from pathlib import Path from tinyrecord import transaction @@ -27,6 +28,9 @@ class InstancedFvTable(TableGenerator): |------------------------------------------------------| ``` """ # noqa: E501 + + RULEOVERRIDE = re.compile(r'RuleOverride\s*=.+\s+(.*\.inf)', re.IGNORECASE) + def __init__(self, *args, **kwargs): """Initialize the query with the specific settings.""" self.env = kwargs.pop("env") @@ -54,7 +58,7 @@ def parse(self, db: Edk2DB) -> None: inf_list = [] # Some INF's start with RuleOverride. We only need the INF for inf in fdfp.FVs[fv]["Infs"]: if inf.lower().startswith("ruleoverride"): - inf = inf.split(" ", 1)[-1] + inf = InstancedFvTable.RULEOVERRIDE.findall(inf)[0] if Path(inf).is_absolute(): inf = str(Path(self.pathobj.GetEdk2RelativePathFromAbsolutePath(inf))) inf_list.append(Path(inf).as_posix()) diff --git a/tests.unit/database/test_instanced_fv_table.py b/tests.unit/database/test_instanced_fv_table.py index 05ba7d9da..2d39a56f0 100644 --- a/tests.unit/database/test_instanced_fv_table.py +++ b/tests.unit/database/test_instanced_fv_table.py @@ -29,6 +29,7 @@ def test_valid_fdf(empty_tree: Tree): # noqa: F811 comp2 = empty_tree.create_component("TestDriver2", "DXE_DRIVER") comp3 = empty_tree.create_component("TestDriver3", "DXE_DRIVER") comp4 = str(Path('TestPkg','Extra Drivers','TestDriver4.inf')) + comp5 = empty_tree.create_component("TestDriver5", "DXE_DRIVER") dsc = empty_tree.create_dsc() @@ -39,7 +40,8 @@ def test_valid_fdf(empty_tree: Tree): # noqa: F811 f"INF {comp1}", # PP relative f'INF {str(empty_tree.ws / comp2)}', # Absolute f'INF RuleOverride=RESET_VECTOR {comp3}', # RuleOverride - f'INF {comp4}' # Space in path + f'INF {comp4}', # Space in path + f'INT ruleoverride = RESET_VECTOR {comp5}', # RuleOverride lowercase & spaces ] ) @@ -62,5 +64,6 @@ def test_valid_fdf(empty_tree: Tree): # noqa: F811 Path(comp1).as_posix(), Path(comp2).as_posix(), Path(comp3).as_posix(), + Path(comp5).as_posix(), Path(comp4).as_posix(), ])