[PATCH] D72940: Add a support for clang tidy to import another configurations files from .clang-tidy
ido via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 11:11:40 PST 2020
ykfre created this revision.
ykfre added a reviewer: clang-tools-extra.
ykfre added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.
add ConfigurationsFilesToImport option - to make it possible to import another configurations files from .clang-tidy, So there will be no need
to duplicate anymore the configuration file among projects, and it will be possible to just point the configuration file to some config in a share.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72940
Files:
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.h
clang-tools-extra/docs/clang-tidy/index.rst
Index: clang-tools-extra/docs/clang-tidy/index.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -242,7 +242,9 @@
Configuration files:
clang-tidy attempts to read configuration for each source file from a
.clang-tidy file located in the closest parent directory of the source
- file. If any configuration options have a corresponding command-line
+ file. This file can also imports configuration from another configuration file,
+ using ConfigurationsFilesToImport option.
+ If any configuration options have a corresponding command-line
option, command-line option takes precedence. The effective
configuration can be inspected using -dump-config:
@@ -251,6 +253,7 @@
Checks: '-*,some-check'
WarningsAsErrors: ''
HeaderFilterRegex: ''
+ ConfigurationsFilesToImport: ['yaml1FilePath', 'yaml2FilePath']
FormatStyle: none
User: user
CheckOptions:
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -73,6 +73,9 @@
/// Output warnings from system headers matching \c HeaderFilterRegex.
llvm::Optional<bool> SystemHeaders;
+ /// Clang tidy configurations files to import.
+ llvm::Optional<std::vector<std::string>> ConfigurationsFilesToImport;
+
/// Format code around applied fixes with clang-format using this
/// style.
///
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -92,6 +92,7 @@
IO.mapOptional("CheckOptions", NOpts->Options);
IO.mapOptional("ExtraArgs", Options.ExtraArgs);
IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
+ IO.mapOptional("ConfigurationsFilesToImport", Options.ConfigurationsFilesToImport);
}
};
@@ -325,12 +326,34 @@
}
llvm::ErrorOr<ClangTidyOptions> parseConfiguration(StringRef Config) {
- llvm::yaml::Input Input(Config);
- ClangTidyOptions Options;
- Input >> Options;
- if (Input.error())
- return Input.error();
- return Options;
+ ClangTidyOptions Options;
+ llvm::yaml::Input Input(Config);
+
+ Input >> Options;
+ if (Input.error())
+ return Input.error();
+ if (!Options.ConfigurationsFilesToImport.hasValue()) {
+ return Options;
+ }
+ for (const auto& file : *Options.ConfigurationsFilesToImport)
+ {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = llvm::MemoryBuffer::getFile(file);
+ if (std::error_code EC = Text.getError()) {
+ llvm::errs() << "Can't read " << file << ": " << EC.message()
+ << "\n";
+ return EC;
+ }
+ Config = Text->get()->getBuffer();
+ auto ReturnedOptions = parseConfiguration(Config);
+ if (ReturnedOptions)
+ {
+ Options = ReturnedOptions->mergeWith(Options);
+ }
+ else {
+ return ReturnedOptions;
+ }
+ }
+ return Options;
}
std::string configurationAsText(const ClangTidyOptions &Options) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72940.238835.patch
Type: text/x-patch
Size: 3303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200117/4ff6bcb1/attachment.bin>
More information about the cfe-commits
mailing list