Skip to content

Commit d857e20

Browse files
committed
[CHERRY-PICK] .pytool/ImageValidation: Print invalid dir paths (#1142)
- Print directory paths considered invalid to aid debugging - Build native OS file paths using os.path.join for walk dirs - Clean up trailing whitespace throughout the file - [ ] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? - Local build with the plugin - Tested invalid directory printing by adding an invalid arch to `TARGET_ARCH` (so the directory doesn't exist in build output). N/A - Minor tweaks Signed-off-by: Michael Kubacki <[email protected]> (cherry picked from commit 66f3d70)
1 parent 5724e5f commit d857e20

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

.pytool/Plugin/ImageValidation/ImageValidation.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class TestImageBase(TestInterface):
2828
"""Image base verification test.
29-
29+
3030
Checks the image base of the binary by accessing the optional
3131
header, then the image base. This value must be the same value
3232
as specified in the config file.
@@ -43,14 +43,14 @@ def name(self) -> str:
4343

4444
def execute(self, pe: PE, config_data: dict) -> Result:
4545
"""Executes the test on the pefile.
46-
46+
4747
Arguments:
4848
pe (PE): a parsed PE/COFF image file
4949
config_data (dict): the configuration data for the test
50-
50+
5151
Returns:
5252
(Result): SKIP, WARN, FAIL, PASS
53-
"""
53+
"""
5454
target_requirements = config_data["TARGET_REQUIREMENTS"]
5555

5656
required_base = target_requirements.get("IMAGE_BASE")
@@ -62,7 +62,7 @@ def execute(self, pe: PE, config_data: dict) -> Result:
6262
except Exception:
6363
logging.warning("Image Base not found in Optional Header")
6464
return Result.WARN
65-
65+
6666
if image_base != required_base:
6767
logging.error(
6868
f'[{Result.FAIL}]: Image Base address Expected: {hex(required_base)}, Found: {hex(image_base)}'
@@ -148,7 +148,7 @@ def do_post_build(self, thebuilder):
148148
env_vars = thebuilder.env.GetAllBuildKeyValues()
149149
dsc_parser.SetEdk2Path(edk2)
150150
dsc_parser.SetInputVars(env_vars).ParseFile(ActiveDsc)
151-
151+
152152
env_vars.update(dsc_parser.LocalVars)
153153
fdf_parser.SetEdk2Path(edk2)
154154
fdf_parser.SetInputVars(env_vars).ParseFile(ActiveFdf)
@@ -183,7 +183,7 @@ def do_post_build(self, thebuilder):
183183
result = Result.PASS
184184
for arch in thebuilder.env.GetValue("TARGET_ARCH").split():
185185
efi_path_list = self._walk_directory_for_extension(
186-
['.efi'], f'{thebuilder.env.GetValue("BUILD_OUTPUT_BASE")}/{arch}')
186+
['.efi'], f'{os.path.join(thebuilder.env.GetValue("BUILD_OUTPUT_BASE"), arch)}')
187187

188188
for efi_path in efi_path_list:
189189
if os.path.basename(efi_path) in self.ignore_list:
@@ -276,12 +276,12 @@ def _walk_directory_for_extension(self, extensionlist: List[str], directory: os.
276276
raise TypeError("directory is None")
277277

278278
if not os.path.isabs(directory):
279-
logging.critical("Directory not abs path")
280-
raise ValueError("directory is not an absolute path")
279+
logging.critical(f"Directory {directory} not an abs path")
280+
raise ValueError(f"directory {directory} is not an absolute path")
281281

282282
if not os.path.isdir(directory):
283-
logging.critical("Invalid find directory to walk")
284-
raise ValueError("directory is not a valid directory path")
283+
logging.critical(f"Directory {directory} is invalid")
284+
raise ValueError(f"directory {directory} is not a valid directory path")
285285

286286
if ignorelist is not None:
287287
if not isinstance(ignorelist, list):

0 commit comments

Comments
 (0)