From e920a296d19e49086650ab5b5e1c0fa687d5224b Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Thu, 10 Nov 2022 17:42:28 -0500 Subject: [PATCH] path_utilities.py: Prevent path case modification in GetContainingModules() Closes #204 Updates `Edk2Path.GetContainingModules()` to preserve case the case for each absolute path returned in the list of absolute paths. This allows callers dependent on case comparison to get the expected result. Signed-off-by: Michael Kubacki --- edk2toollib/uefi/edk2/path_utilities.py | 2 +- edk2toollib/uefi/edk2/test_path_utilities.py | 64 ++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/edk2toollib/uefi/edk2/path_utilities.py b/edk2toollib/uefi/edk2/path_utilities.py index ac213edc..0972b47a 100644 --- a/edk2toollib/uefi/edk2/path_utilities.py +++ b/edk2toollib/uefi/edk2/path_utilities.py @@ -296,7 +296,7 @@ def GetContainingModules(self, input_path: str) -> list[str]: (list[str]): Absolute paths of .inf files that could be the containing module. """ - input_path = Path(os.path.normcase(input_path)) + input_path = Path(input_path) if not input_path.is_absolute(): # Todo: Return a more specific exception type when # https://github.com/tianocore/edk2-pytool-library/issues/184 is diff --git a/edk2toollib/uefi/edk2/test_path_utilities.py b/edk2toollib/uefi/edk2/test_path_utilities.py index dbc6360b..e379bcf9 100644 --- a/edk2toollib/uefi/edk2/test_path_utilities.py +++ b/edk2toollib/uefi/edk2/test_path_utilities.py @@ -497,6 +497,70 @@ def test_get_containing_module_with_infs_in_other_temp_dirs(self): if os.path.isfile(other_inf): os.remove(other_inf) + def test_get_containing_modules_path_format(self): + """Test that get containing modules returns the exact expected path. + + Note: GetContainingModules() only accepts absolute paths. + + File layout: + root/ <-- Current working directory (self.tmp) + folder_ws <-- Workspace directory + pp1 <-- Package Path 1 + PPTestPkg <-- An edk2 package + PPTestPkg.DEC + module1 + module1.INF + module2 + module2.INF + X64 + TestFile.c + WSTestPkg <-- An edk2 package + WSTestPkg.dec + module1 + module1.inf + module2 + module2.inf + X64 + TestFile.c + """ + # /folder_ws/ + ws_rel = "folder_ws" + # /folder_ws/pp1/ + folder_pp_rel = "pp1" + # /folder_ws/WSTestPkg/ + ws_p_name = "WSTestPkg" + # /folder_ws/pp1/PPTestPkg + pp_p_name = "PPTestPkg" + + # Create /folder_ws/ + ws_abs = os.path.join(self.tmp, ws_rel) + os.mkdir(ws_abs) + + # Create /folder_ws/pp1/ + folder_pp1_abs = os.path.join(ws_abs, folder_pp_rel) + os.mkdir(folder_pp1_abs) + + # Create /folder_ws/WSTestPkg/ + ws_pkg_abs = self._make_edk2_package_helper(ws_abs, ws_p_name) + + # Create /folder_ws/pp1/PPTestPkg + pp_pkg_abs = self._make_edk2_package_helper(folder_pp1_abs, pp_p_name, extension_case_lower=False) + pathobj = Edk2Path(ws_abs, [folder_pp1_abs]) + + # Check the case and location of the absolute path + p = os.path.join(pp_pkg_abs, "module1", "module1.INF") + expected_module_inf = p + actual_module_inf_list = pathobj.GetContainingModules(p) + self.assertEqual(len(actual_module_inf_list), 1) + self.assertEqual(expected_module_inf, actual_module_inf_list[0]) + + # Check the case and location of the absolute path + p = os.path.join(ws_pkg_abs, "module2", "X64", "TestFile.c") + expected_module_inf = os.path.join(ws_pkg_abs, "module2", "module2.inf") + actual_module_inf_list = pathobj.GetContainingModules(p) + self.assertEqual(len(actual_module_inf_list), 1) + self.assertEqual(expected_module_inf, actual_module_inf_list[0]) + def test_get_containing_module(self): ''' test basic usage of GetContainingModule with packages path nested inside the workspace