Skip to content

Commit

Permalink
Merged PR 4958: Add a flag to support applying Uncrustify in place
Browse files Browse the repository at this point in the history
To simplify automatic formatting of new code, this feature lets a local dev supply the
`UNCRUSTIFY_IN_PLACE=TRUE` parameter on the command line to automatically
format any failing files.

See readme for details.
  • Loading branch information
Bret Barkelew authored and kenlautner committed May 5, 2023
1 parent 4ae00ba commit 8427e3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .pytool/Plugin/UncrustifyCheck/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ plugin execution.
By default, files in paths matched in a .gitignore file or a recognized git submodule are excluded. If this option
is `True`, the plugin will not attempt to recognize these files and exclude them.

### `UNCRUSTIFY_IN_PLACE=TRUE`

MU_CHANGE - Feature added.

Mu adds support for passing this parameter on the command line when running `stuart_ci_build`. If passed, it will
cause any changes to be made in-place to the files in the workspace, enabling the caller to easily format any failing
code before submitting a PR.

While this can also be set as an environment variable, it is recommended to only use it
as a CLI paramter.

_NOTE:_ This is _not_ an option in the config `yaml`. It is an option passed directly into the tool.

## High-Level Plugin Operation

This plugin generates two main sets of temporary files:
Expand Down
13 changes: 12 additions & 1 deletion .pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def RunBuildPlugin(self, package_rel_path: str, edk2_path: Edk2Path, package_con
"""
try:
# Initialize plugin and check pre-requisites.
self._env = environment_config # MU_CHANGE - Add "UNCRUSTIFY_IN_PLACE" option.
self._initialize_environment_info(
package_rel_path, edk2_path, package_config, tc)
self._initialize_configuration()
Expand Down Expand Up @@ -268,10 +269,20 @@ def _execute_uncrustify(self) -> None:
"""
Executes Uncrustify with the initialized configuration.
"""
# MU_CHANGE [BEGIN] - Add "UNCRUSTIFY_IN_PLACE" option.
output = StringIO()
params = ['-c', self._app_config_file]
params += ['-F', self._app_input_file_path]
params += ['--if-changed']
if self._env.GetValue("UNCRUSTIFY_IN_PLACE", "FALSE") == "TRUE":
params += ['--replace', '--no-backup']
else:
params += ['--suffix', UncrustifyCheck.FORMATTED_FILE_EXTENSION]
self._app_exit_code = RunCmd(
self._app_path,
f"-c {self._app_config_file} -F {self._app_input_file_path} --if-changed --suffix {UncrustifyCheck.FORMATTED_FILE_EXTENSION}", outstream=output)
" ".join(params),
outstream=output)
# MU_CHANGE [END] - Add "UNCRUSTIFY_IN_PLACE" option.
self._app_output = output.getvalue().strip().splitlines()

def _get_files_ignored_in_config(self):
Expand Down

0 comments on commit 8427e3c

Please sign in to comment.