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

Allow correct languages on uncrustify #272

Merged
merged 2 commits into from
Mar 2, 2021

Conversation

MiguelCompany
Copy link
Contributor

When running uncrustify -h it does not show C++ as a valid option for -l.

This PR changes the valid options on --language to C and CPP

Signed-off-by: Miguel Company MiguelCompany@eprosima.com

@mm318
Copy link
Member

mm318 commented Jan 25, 2021

Is ament_uncrustify not translating C++ to CPP when passing it to uncrustify?

@@ -65,7 +65,7 @@ def main(argv=sys.argv[1:]):
help='Exclude specific file names and directory names from the check')
parser.add_argument(
'--language',
choices=['C', 'C++'],
choices=['C', 'CPP'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the C++ here is meant for uncrustify. I think it's meant for ament_uncrustify, and making this change will break the dictionary here.

Can you double check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mm318, can you confirm the link to the dictionary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind.

@claireyywang claireyywang removed their assignment Feb 18, 2021
@audrow
Copy link
Contributor

audrow commented Feb 27, 2021

After spending some time going through the code and trying uncrustify, I don't believe that this change breaks any dictionary.

@MiguelCompany I also think that the following line should also be changed:

args.paths, {'C': c_extensions, 'C++': cpp_extensions},

Following the code

The language is only used here:

files_by_language = get_files(
args.paths, {'C': c_extensions, 'C++': cpp_extensions},
excludes=args.exclude, language=args.language)

get_files creates a dictionary where the language is the value. It optionally uses the supplied language.

extensions_with_dot_to_language = {
f'.{extension}': language or ext_language
for ext_language, extensions in extension_types.items()
for extension in extensions
}

This is ultimately used in grouping the files by language (file type is key, a list of files is the value):

language = extensions_with_dot_to_language.get(ext, None)
if language is not None:
files[language].append(
os.path.normpath(os.path.join(dirpath, filename)))

The uncrustify is invoked on each group of languages:

output_files = invoke_uncrustify(
uncrustify_bin, input_files, args, language, temp_path, suffix)

The actual command used to call uncrustify then appends all of the files as the last argument:

cmd = [uncrustify_bin, '-c', args.config_file]
if language:
cmd += ['-l', language]
cmd += [
'--prefix', temp_path,
'--suffix', suffix]
cmd.extend(input_files)
subprocess.check_output(cmd, cwd=cwd, stderr=subprocess.STDOUT)

@audrow audrow self-assigned this Feb 27, 2021
Copy link
Contributor

@audrow audrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @MiguelCompany. I think this is a good fix.

I think that the change should also be added in one other place in the file. See #272 (comment).

@mm318
Copy link
Member

mm318 commented Feb 27, 2021

So following the code, the value of args.language will be passed to uncrustify?

@audrow
Copy link
Contributor

audrow commented Feb 27, 2021

the value of args.language will be passed to uncrustify

Correct, as the language (-l), if it is supplied. If not, the file extensions will be used. If I understand correctly, C++ isn't a valid language specifier for uncrustify (CPP is), but it still uses the supplied config file, so uncrustify will seem to handle the C++ correctly regardless of it ignoring the language specifier.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
@MiguelCompany
Copy link
Contributor Author

Thanks for the PR @MiguelCompany. I think this is a good fix.

I think that the change should also be added in one other place in the file. See #272 (comment).

I rebased, fixed DCO and also updated the dictionary key from C++ to CPP

@audrow
Copy link
Contributor

audrow commented Mar 1, 2021

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@audrow
Copy link
Contributor

audrow commented Mar 2, 2021

@mm318, does it look good to you, too?

@audrow audrow requested a review from mm318 March 2, 2021 00:58
Copy link
Member

@mm318 mm318 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, looks good to me!

@audrow audrow merged commit 477cb73 into ament:master Mar 2, 2021
@audrow
Copy link
Contributor

audrow commented Mar 2, 2021

@MiguelCompany, thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants