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 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
39 changes: 34 additions & 5 deletions edk2toollib/uefi/edk2/path_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,46 @@ 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')]

# Note: The ability to ignore this function raising an exception on
# nested packages is temporary. Do not plan on this variable
# being available long-term and try to resolve the nested
# packages problem right away.
#
# Removal is tracked in the following GitHub issue:
# https://github.com/tianocore/edk2-pytool-library/issues/200
ignore_nested_packages = False
makubacki marked this conversation as resolved.
Show resolved Hide resolved
if "PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES" in os.environ and \
os.environ["PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES"].strip().lower() == \
"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
self.logger.log(
logging.WARNING,
"Note 1: Nested packages are being ignored right now because the "
"\"PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES\" environment variable "
"is set. Do not depend on this variable long-term.")
self.logger.log(
logging.WARNING,
"Note 2: Some pytool features may not work as expected with nested packages.")
else:
raise Exception(
f"Nested packages not allowed. The packages "
f"[{str(package)}] and [{str(comp_package)}] are "
f"nested. Set the \"PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_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
11 changes: 11 additions & 0 deletions edk2toollib/uefi/edk2/test_path_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,20 @@ 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
# Note: These tests can be removed when support for
# PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES is removed.
os.environ["PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES"] = "true"
Edk2Path(folder_ws_abs, [folder_pp1_abs])
Edk2Path(folder_ws_abs, [folder_pp1_abs, folder_pp2_abs])

# Remove the environment variable now that the test above is complete
os.environ.pop("PYTOOL_TEMPORARILY_IGNORE_NESTED_EDK_PACKAGES")

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