This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] New argument --language to add_new_check.py
ClosedPublic

Authored by benhamilton on Oct 20 2017, 1:33 PM.

Details

Summary

Currently, add_new_check.py assumes all checks are for C++ code.

This adds a new argument --language=[LANG] to add_new_check.py
so authors of new checks can specify that the test file should
be in a different language.

For example, authors can pass --language=objc for Objective-C
clang-tidy checks.

Diff Detail

Repository
rL LLVM

Event Timeline

benhamilton created this revision.Oct 20 2017, 1:33 PM
alexfh edited edge metadata.Oct 20 2017, 2:26 PM

A higher-level option - language (maybe with an optional standard, e.g. c++11 or c11) - would probably be more useful, since we could also use it to modify the template of the check to bail out on other languages.

A higher-level option - language (maybe with an optional standard, e.g. c++11 or c11) - would probably be more useful, since we could also use it to modify the template of the check to bail out on other languages.

I like that — is there a list of all the language options I can steal here?

benhamilton retitled this revision from [clang-tidy] New argument --test-extension to add_new_check.py to [clang-tidy] New argument --language to add_new_check.py.Oct 20 2017, 2:34 PM
benhamilton edited the summary of this revision. (Show Details)
  • Use --language flag instead, support c, c++, objc, objc++

Went ahead and did that, supporting c, c++, objc, objc++.

alexfh added inline comments.Oct 20 2017, 2:47 PM
clang-tidy/add_new_check.py
345–352 ↗(On Diff #119715)

Should this be done in write_test instead?

Wizard added inline comments.Oct 20 2017, 3:03 PM
clang-tidy/add_new_check.py
310 ↗(On Diff #119715)

If we are using this flag, do we need to somehow explicitly pass the language arg when run clang-tidy towards files?

alexfh added inline comments.Oct 20 2017, 3:09 PM
clang-tidy/add_new_check.py
310 ↗(On Diff #119715)

The intention is that this flag instructs the script to create the test file with the corresponding extension, and the check_clang_tidy.py script we use for testing (and the clang-tidy tool itself) will detect the language based on the extension.

Does it answer your question?

Wizard added inline comments.Oct 20 2017, 3:10 PM
clang-tidy/add_new_check.py
310 ↗(On Diff #119715)

My bad. Did not notice that this flag is only for adding a new check.

  • @alexfh: Move language -> test extension map into write_test()
alexfh added inline comments.Oct 24 2017, 4:25 PM
clang-tidy/add_new_check.py
227–234 ↗(On Diff #119852)

Just noticed: the list of the languages is also used in the documentation of the corresponding option below. Maybe make this a map of language -> extension and feed its keys to the choices argument of parser.add_argument?

Sorry for not noticing this earlier.

benhamilton updated this revision to Diff 120264.EditedOct 25 2017, 8:24 AM
  • @alexfh: Move language -> test extension map into a dict, use keys to specify arg
benhamilton marked an inline comment as done.Oct 25 2017, 8:25 AM

BTW, it'd be nice to get an accept, @alexfh !

alexfh accepted this revision.Jan 31 2018, 1:49 PM

LG. Sorry, this got lost under my vacation heap of mail.

This revision is now accepted and ready to land.Jan 31 2018, 1:49 PM
This revision was automatically updated to reflect the committed changes.