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

Edk2Path: Add an env variable to allow nested packages #199

Merged
merged 4 commits into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions edk2toollib/uefi/edk2/path_utilities.py
Expand Up @@ -100,17 +100,31 @@ def __init__(self, ws: os.PathLike, package_path_list: Iterable[os.PathLike],
package_path_packages[package_path] = \
[Path(p).parent for p in package_path.glob('**/*.dec')]

ignore_nested_packages = False
makubacki marked this conversation as resolved.
Show resolved Hide resolved
if "STUART_IGNORE_EDK_NESTED_PACKAGES" in os.environ and \
os.environ["STUART_IGNORE_EDK_NESTED_PACKAGES"].strip().lower() == \
makubacki marked this conversation as resolved.
Show resolved Hide resolved
"true":
ignore_nested_packages = True

for package_path, packages in package_path_packages.items():
for i, package in enumerate(packages):
for j in range(i + 1, len(packages)):
comp_package = packages[j]

if (package.is_relative_to(comp_package)
or comp_package.is_relative_to(package)):
raise Exception(
f"Nested packages not allowed. The packages "
f"[{str(package)}] and [{str(comp_package)}] are "
f"nested")
if ignore_nested_packages:
self.logger.log(
logging.WARNING,
f"Nested packages not allowed. The packages "
f"[{str(package)}] and [{str(comp_package)}] are "
f"nested.")
makubacki marked this conversation as resolved.
Show resolved Hide resolved
else:
raise Exception(
f"Nested packages not allowed. The packages "
f"[{str(package)}] and [{str(comp_package)}] are "
f"nested. Set the \"STUART_IGNORE_EDK_NESTED_PACKAGES\" "
f"environment variable to \"true\" as a temporary workaround "
f"until you fix the packages so they are no longer nested.")

def GetEdk2RelativePathFromAbsolutePath(self, abspath):
"""Given an absolute path return a edk2 path relative to workspace or packagespath.
Expand Down
6 changes: 6 additions & 0 deletions edk2toollib/uefi/edk2/test_path_utilities.py
Expand Up @@ -811,9 +811,15 @@ def test_get_relative_path_with_nested_packages(self):
pp2_name = "PPTestPkg2"
self._make_edk2_package_helper(folder_pp2_abs, pp2_name)

# Nested packages should raise an exception by default
self.assertRaises(Exception, Edk2Path, folder_ws_abs, [folder_pp1_abs])
self.assertRaises(Exception, Edk2Path, folder_ws_abs, [folder_pp1_abs, folder_pp2_abs])

# Nested packages should no longer raise an exception
makubacki marked this conversation as resolved.
Show resolved Hide resolved
os.environ["STUART_IGNORE_EDK_NESTED_PACKAGES"] = "true"
Edk2Path(folder_ws_abs, [folder_pp1_abs])
Edk2Path(folder_ws_abs, [folder_pp1_abs, folder_pp2_abs])

def test_get_relative_path_when_folder_is_next_to_package(self):
''' test usage of GetEdk2RelativePathFromAbsolutePath when a folder containing a package is in the same
directory as a different package. This test ensures the correct value is returned regardless the order of
Expand Down