summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-09-24 18:36:03 +0000
committerAlexander Kornienko <alexfh@google.com>2014-09-24 18:36:03 +0000
commite995154ac2f15f58d701f2251da417aac4da9d3c (patch)
tree6aaf8242d5c80cb85a2fc449da3c93a89853f8c4 /clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
parent7827217131ffe946e2b44eb87b66cb13a36fb98d (diff)
downloadbcm5719-llvm-e995154ac2f15f58d701f2251da417aac4da9d3c.tar.gz
bcm5719-llvm-e995154ac2f15f58d701f2251da417aac4da9d3c.zip
Provide user name in ClangTidyOptions.
Summary: This adds the ClangTidyOptions::User field and fills it from the USER or the USERNAME environment variable, if possible. The FileOptionsProvider now takes "default" options instead of "fallback" options, as it now uses these when an option is not set in the configuration file (one exception is the checks list). Reviewers: bkramer, klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5440 llvm-svn: 218402
Diffstat (limited to 'clang-tools-extra/clang-tidy/ClangTidyOptions.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/ClangTidyOptions.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 148593dabd5..a4bfe0488c1 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -85,6 +85,7 @@ template <> struct MappingTraits<ClangTidyOptions> {
IO.mapOptional("Checks", Options.Checks);
IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
IO.mapOptional("AnalyzeTemporaryDtors", Options.AnalyzeTemporaryDtors);
+ IO.mapOptional("User", Options.User);
IO.mapOptional("CheckOptions", NOpts->Options);
}
};
@@ -109,6 +110,8 @@ ClangTidyOptions::mergeWith(const ClangTidyOptions &Other) const {
Result.HeaderFilterRegex = Other.HeaderFilterRegex;
if (Other.AnalyzeTemporaryDtors)
Result.AnalyzeTemporaryDtors = Other.AnalyzeTemporaryDtors;
+ if (Other.User)
+ Result.User = Other.User;
for (const auto &KeyValue : Other.CheckOptions)
Result.CheckOptions[KeyValue.first] = KeyValue.second;
@@ -118,11 +121,11 @@ ClangTidyOptions::mergeWith(const ClangTidyOptions &Other) const {
FileOptionsProvider::FileOptionsProvider(
const ClangTidyGlobalOptions &GlobalOptions,
- const ClangTidyOptions &FallbackOptions,
+ const ClangTidyOptions &DefaultOptions,
const ClangTidyOptions &OverrideOptions)
- : DefaultOptionsProvider(GlobalOptions, FallbackOptions),
+ : DefaultOptionsProvider(GlobalOptions, DefaultOptions),
OverrideOptions(OverrideOptions) {
- CachedOptions[""] = FallbackOptions.mergeWith(OverrideOptions);
+ CachedOptions[""] = DefaultOptions.mergeWith(OverrideOptions);
}
static const char ConfigFileName[] = ".clang-tidy";
@@ -177,7 +180,6 @@ llvm::ErrorOr<ClangTidyOptions>
FileOptionsProvider::TryReadConfigFile(StringRef Directory) {
assert(!Directory.empty());
- ClangTidyOptions Options = DefaultOptionsProvider::getOptions(Directory);
if (!llvm::sys::fs::is_directory(Directory))
return make_error_code(llvm::errc::not_a_directory);
@@ -201,9 +203,15 @@ FileOptionsProvider::TryReadConfigFile(StringRef Directory) {
// redirection.
if ((*Text)->getBuffer().empty())
return make_error_code(llvm::errc::no_such_file_or_directory);
- if (std::error_code EC = parseConfiguration((*Text)->getBuffer(), Options))
- return EC;
- return Options.mergeWith(OverrideOptions);
+ llvm::ErrorOr<ClangTidyOptions> ParsedOptions =
+ parseConfiguration((*Text)->getBuffer());
+ if (ParsedOptions) {
+ ClangTidyOptions Defaults = DefaultOptionsProvider::getOptions(Directory);
+ // Only use checks from the config file.
+ Defaults.Checks = None;
+ return Defaults.mergeWith(*ParsedOptions).mergeWith(OverrideOptions);
+ }
+ return ParsedOptions.getError();
}
/// \brief Parses -line-filter option and stores it to the \c Options.
@@ -214,11 +222,13 @@ std::error_code parseLineFilter(StringRef LineFilter,
return Input.error();
}
-std::error_code parseConfiguration(StringRef Config,
- clang::tidy::ClangTidyOptions &Options) {
+llvm::ErrorOr<ClangTidyOptions> parseConfiguration(StringRef Config) {
llvm::yaml::Input Input(Config);
+ ClangTidyOptions Options;
Input >> Options;
- return Input.error();
+ if (Input.error())
+ return Input.error();
+ return Options;
}
std::string configurationAsText(const ClangTidyOptions &Options) {
OpenPOWER on IntegriCloud