Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instanced_inf_table: include NULL libs #499

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions edk2toollib/database/tables/instanced_inf_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,16 @@ 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")
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):
library_instance_list.append(null_lib)
library_class_list.append("NULL")

#
# 3. Recursively parse used libraries
Expand Down Expand Up @@ -355,3 +360,34 @@ 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,
scope: str,
library_dict: dict,
) -> list:
"""Returns all null libraries for a given scope.

Args:
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, []))

return null_libs
58 changes: 58 additions & 0 deletions tests.unit/database/test_instanced_inf_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading