From 442deac0325eaee6eddc136dd5a6fb0353c61c93 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 30 Jan 2024 12:53:24 -0800 Subject: [PATCH 1/4] update --- .../database/tables/instanced_inf_table.py | 40 +++++++++++++ .../database/test_instanced_inf_table.py | 58 +++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/edk2toollib/database/tables/instanced_inf_table.py b/edk2toollib/database/tables/instanced_inf_table.py index 2752a9d6..d7cfca71 100644 --- a/edk2toollib/database/tables/instanced_inf_table.py +++ b/edk2toollib/database/tables/instanced_inf_table.py @@ -228,6 +228,10 @@ def _parse_inf_recursively( library_instance_list.append(null_lib) library_class_list.append("NULL") + for null_lib in self._get_null_lib_instances(inf, scope, library_dict): + library_instance_list.append(null_lib) + library_class_list.append("NULL") + # # 3. Recursively parse used libraries # @@ -355,3 +359,39 @@ def _reduce_lib_instances(self, module: str, library_instance_list: list[str]) - library_instance = self.pathobj.GetEdk2RelativePathFromAbsolutePath(library_instance) return library_instance return None + + def _get_null_lib_instances( + self, + inf: str, + scope: str, + library_dict: dict, + ) -> list: + """Returns all null libraries for a given scope. + + Args: + inf (str): The INF file to ignore null libraries for. + scope (str): The scope to search for null libraries. + library_dict (dict): The dictionary of libraries to search through. + + Returns: + list: A list of null libraries for the given scope. + """ + arch, module = tuple(scope.split(".")) + null_libs = [] + + lookup = f'{arch}.{module}.null' + null_libs.extend(library_dict.get(lookup, [])) + + lookup = f'common.{module}.null' + null_libs.extend(library_dict.get(lookup, [])) + + lookup = f'{arch}.null' + null_libs.extend(library_dict.get(lookup, [])) + + lookup = 'common.null' + null_libs.extend(library_dict.get(lookup, [])) + + if inf in null_libs: + null_libs.remove(inf) + + return null_libs diff --git a/tests.unit/database/test_instanced_inf_table.py b/tests.unit/database/test_instanced_inf_table.py index 3dd33410..4a5b460b 100644 --- a/tests.unit/database/test_instanced_inf_table.py +++ b/tests.unit/database/test_instanced_inf_table.py @@ -410,3 +410,61 @@ def test_dsc_with_component_section_moduletype_definition(empty_tree: Tree, capl # Should not error db.parse(env) + +def test_dsc_with_null_lib_in_libraryclasses_section(empty_tree: Tree): + edk2path = Edk2Path(str(empty_tree.ws), []) + db = Edk2DB(empty_tree.ws / "db.db", pathobj=edk2path) + db.register(InstancedInfTable()) + + lib1 = empty_tree.create_library("TestLib", "TestCls") + nulllib1 = empty_tree.create_library("NullLib1", "NULL") + nulllib2 = empty_tree.create_library("NullLib2", "NULL") + nulllib3 = empty_tree.create_library("NullLib3", "NULL") + + comp1 = empty_tree.create_component("TestDriver", "PEIM", libraryclasses=["TestCls"]) + + dsc = empty_tree.create_dsc( + libraryclasses = [ + f'TestCls| {Path(lib1).as_posix()}', + f'NULL| {Path(nulllib1).as_posix()}', + ], + libraryclasses_x64 = [ + f'NULL| {Path(nulllib2).as_posix()}', + ], + libraryclasses_x64_DXE_DRIVER = [ + f'NULL| {Path(nulllib3).as_posix()}', + ], + components = [], + components_ia32_PEIM = [ + Path(comp1).as_posix(), + ], + components_x64 = [ + Path(comp1).as_posix(), + ] + ) + + env = { + "ACTIVE_PLATFORM": dsc, + "TARGET_ARCH": "IA32", + "TARGET": "DEBUG", + } + + db.parse(env) + + with db.session() as session: + component = session.query(InstancedInf).filter_by(cls = None).one() + assert len(component.libraries) == 2 + + db = Edk2DB(":memory:", pathobj=edk2path) + db.register(InstancedInfTable()) + env = { + "ACTIVE_PLATFORM": dsc, + "TARGET_ARCH": "X64", + "TARGET": "DEBUG", + } + + db.parse(env) + + with db.session() as session: + component = session.query(InstancedInf).filter_by(cls = None).one() + assert len(component.libraries) == 3 From e2d523cf0feeac9c102ade99945eca62d21a6328 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 30 Jan 2024 12:58:40 -0800 Subject: [PATCH 2/4] update --- edk2toollib/database/tables/instanced_inf_table.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/edk2toollib/database/tables/instanced_inf_table.py b/edk2toollib/database/tables/instanced_inf_table.py index d7cfca71..52da78a7 100644 --- a/edk2toollib/database/tables/instanced_inf_table.py +++ b/edk2toollib/database/tables/instanced_inf_table.py @@ -228,7 +228,9 @@ def _parse_inf_recursively( library_instance_list.append(null_lib) library_class_list.append("NULL") - for null_lib in self._get_null_lib_instances(inf, scope, library_dict): + for null_lib in self._get_null_lib_instances(scope, library_dict): + if null_lib == inf: + continue library_instance_list.append(null_lib) library_class_list.append("NULL") @@ -362,14 +364,12 @@ def _reduce_lib_instances(self, module: str, library_instance_list: list[str]) - def _get_null_lib_instances( self, - inf: str, scope: str, library_dict: dict, ) -> list: """Returns all null libraries for a given scope. Args: - inf (str): The INF file to ignore null libraries for. scope (str): The scope to search for null libraries. library_dict (dict): The dictionary of libraries to search through. @@ -391,7 +391,4 @@ def _get_null_lib_instances( lookup = 'common.null' null_libs.extend(library_dict.get(lookup, [])) - if inf in null_libs: - null_libs.remove(inf) - return null_libs From 49a55997b0615d6238a3bff42d8fd4c52d69b162 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 30 Jan 2024 14:33:24 -0800 Subject: [PATCH 3/4] Update --- .../database/tables/instanced_inf_table.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/edk2toollib/database/tables/instanced_inf_table.py b/edk2toollib/database/tables/instanced_inf_table.py index 52da78a7..ffce63e3 100644 --- a/edk2toollib/database/tables/instanced_inf_table.py +++ b/edk2toollib/database/tables/instanced_inf_table.py @@ -222,17 +222,18 @@ def _parse_inf_recursively( library_class_list.append(lib) # - # 2. Append all NULL library instances + # 2. Append all NULL library instances if parsing the component. # - for null_lib in override_dict["NULL"]: - library_instance_list.append(null_lib) - library_class_list.append("NULL") - - for null_lib in self._get_null_lib_instances(scope, library_dict): - if null_lib == inf: - continue - library_instance_list.append(null_lib) - library_class_list.append("NULL") + if inf == component: + for null_lib in override_dict["NULL"]: + library_instance_list.append(null_lib) + library_class_list.append("NULL") + + for null_lib in self._get_null_lib_instances(scope, library_dict): + if null_lib == inf: + continue + library_instance_list.append(null_lib) + library_class_list.append("NULL") # # 3. Recursively parse used libraries From eff23343d394d7b1039bfed31ba7ab1f6e25ed72 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 30 Jan 2024 14:36:52 -0800 Subject: [PATCH 4/4] Update --- edk2toollib/database/tables/instanced_inf_table.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/edk2toollib/database/tables/instanced_inf_table.py b/edk2toollib/database/tables/instanced_inf_table.py index ffce63e3..b4b27ec9 100644 --- a/edk2toollib/database/tables/instanced_inf_table.py +++ b/edk2toollib/database/tables/instanced_inf_table.py @@ -230,8 +230,6 @@ def _parse_inf_recursively( library_class_list.append("NULL") for null_lib in self._get_null_lib_instances(scope, library_dict): - if null_lib == inf: - continue library_instance_list.append(null_lib) library_class_list.append("NULL")