diff --git a/.pytool/Plugin/UncrustifyCheck/Readme.md b/.pytool/Plugin/UncrustifyCheck/Readme.md index 0c46fd241a..efe7a573e4 100644 --- a/.pytool/Plugin/UncrustifyCheck/Readme.md +++ b/.pytool/Plugin/UncrustifyCheck/Readme.md @@ -41,6 +41,7 @@ The plugin can be configured with a few optional configuration options. "AdditionalIncludePaths": [], # Additional paths to check formatting (wildcards supported). "AuditOnly": False, # Don't fail the build if there are errors. Just log them. "ConfigFilePath": "", # Custom path to an Uncrustify config file. + "IgnoreFiles": [], # A list of file patterns to ignore. "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignored. "OutputFileDiffs": True, # Output chunks of formatting diffs in the test case log. # This can significantly slow down the plugin on very large packages. @@ -67,6 +68,12 @@ the test as skipped. This allows visibility into the failures without breaking t When specified in the config file, this is a package relative path to the Uncrustify configuration file. +### `IgnoreFiles` + +This option supports .gitignore file and folder matching strings including wildcards. + +The files specified by this configuration option will not be processed by Uncrustify. + ### `IgnoreStandardPaths` This plugin by default will check the below standard paths. A package configuration file can specify any of these paths diff --git a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py index 6920580646..22cca0ff11 100644 --- a/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py +++ b/.pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py @@ -18,6 +18,7 @@ from edk2toolext.environment.plugin_manager import PluginManager from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin from edk2toolext.environment.plugintypes.uefi_helper_plugin import HelperFunctions from edk2toolext.environment.var_dict import VarDict +from edk2toollib.gitignore_parser import parse_gitignore_lines from edk2toollib.log.junit_report_format import JunitReportTestCase from edk2toollib.uefi.edk2.path_utilities import Edk2Path from edk2toollib.utility_functions import RunCmd @@ -273,6 +274,24 @@ class UncrustifyCheck(ICiBuildPlugin): f"-c {self._app_config_file} -F {self._app_input_file_path} --if-changed --suffix {UncrustifyCheck.FORMATTED_FILE_EXTENSION}", outstream=output) self._app_output = output.getvalue().strip().splitlines() + def _get_files_ignored_in_config(self): + """" + Returns a function that returns true if a given file string path is ignored in the plugin configuration file and false otherwise. + """ + ignored_files = [] + if "IgnoreFiles" in self._package_config: + ignored_files = self._package_config["IgnoreFiles"] + + # Pass "Package configuration file" as the source file path since + # the actual configuration file name is unknown to this plugin and + # this provides a generic description of the file that provided + # the ignore file content. + # + # This information is only used for reporting (not used here) and + # the ignore lines are being passed directly as they are given to + # this plugin. + return parse_gitignore_lines(ignored_files, "Package configuration file", self._abs_workspace_path) + def _get_git_ignored_paths(self) -> List[str]: """" Returns a list of file absolute path strings to all files ignored in this git repository. @@ -465,6 +484,19 @@ class UncrustifyCheck(ICiBuildPlugin): self._abs_file_paths_to_format.extend( [str(path.resolve()) for path in pathlib.Path(self._abs_package_path).rglob(path)]) + # Remove files ignore in the plugin configuration file + plugin_ignored_files = list(filter(self._get_files_ignored_in_config(), self._abs_file_paths_to_format)) + + if plugin_ignored_files: + logging.info( + f"{self._package_name} file count before plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}") + for path in plugin_ignored_files: + if path in self._abs_file_paths_to_format: + logging.info(f" File ignored in plugin config file: {path}") + self._abs_file_paths_to_format.remove(path) + logging.info( + f"{self._package_name} file count after plugin ignore file exclusion: {len(self._abs_file_paths_to_format)}") + if not "SkipGitExclusions" in self._package_config or not self._package_config["SkipGitExclusions"]: # Remove files ignored by git logging.info(