Skip to content

Commit

Permalink
instanced_inf_table: Account for non-existing library instance
Browse files Browse the repository at this point in the history
Due to platforms performing complex includes in their DSCs, There is a
scenario in which a library instance references a library class that
does not exist. This is not an error as the library class instance may
not be consumed by a component in the platform, so the missing
dependency is acceptable.

This commit adds the ability to handle this scenario, and will not raise
an error for a missing library instance.
  • Loading branch information
Javagedes committed Aug 21, 2023
1 parent 0f713d9 commit b67b71f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions edk2toollib/database/tables/instanced_inf_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def _parse_inf_recursively(
Will immediately return if the INF has already been visited.
"""
if inf is None:
return []

logging.debug(f" Parsing Library: [{inf}]")
visited.append(inf)
library_instances = []
Expand All @@ -131,6 +134,8 @@ def _parse_inf_recursively(
for null_lib in override_dict["NULL"]:
library_instances.append(null_lib)

library_instances = list(filter(lambda lib: lib is not None, library_instances))

# Time to visit in libraries that we have not visited yet.
to_return = []
for library in filter(lambda lib: lib not in visited, library_instances):
Expand Down Expand Up @@ -207,8 +212,8 @@ def _lib_to_instance(self, library_class_name, scope, library_dict, override_dic
logging.debug(f'scoped library contents: {library_dict}')
logging.debug(f'override dictionary: {override_dict}')
e = f'Cannot find library class [{library_class_name}] for scope [{scope}] when evaluating {self.dsc}'
logging.error(e)
raise RuntimeError(e)
logging.warn(e)
return None

def _reduce_lib_instances(self, module: str, library_class_list: list[str]) -> str:
"""For a DSC, multiple library instances for the same library class can exist.
Expand Down
8 changes: 6 additions & 2 deletions tests.unit/database/test_instanced_inf_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_scoped_libraries2(empty_tree: Tree):
if "COMPONENT" not in row:
assert row["NAME"].replace("Driver", "Lib") in row["LIBRARIES_USED"][0]

def test_missing_library(empty_tree: Tree):
def test_missing_library(empty_tree: Tree, caplog):
"""Test when a library is missing."""
edk2path = Edk2Path(str(empty_tree.ws), [])
db = Edk2DB(Edk2DB.MEM_RW, pathobj=edk2path)
Expand All @@ -227,9 +227,13 @@ def test_missing_library(empty_tree: Tree):
"TARGET_ARCH": "IA32 X64",
"TARGET": "DEBUG",
})
with pytest.raises(RuntimeError):

with caplog.at_level(logging.WARNING):
inf_table.parse(db)

assert len(caplog.records) == 1
assert 'testcls' in caplog.records[0].message

def test_skip_library_with_unsupported_module_type(empty_tree: Tree):
"""Library class INFs can specify what module types they support.
Expand Down

0 comments on commit b67b71f

Please sign in to comment.