Skip to content

Commit

Permalink
[clang-tidy] Pass absolute path to OptionsProvider::getOptions/getRaw…
Browse files Browse the repository at this point in the history
…Options.

Summary:
Although there is no guarantee of getOptions/getRawOptions receiving an
absolute path, we try to make it if possible. So FileOptionProvider subclasses
don't have to convert the path to an absolute path.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D22154

llvm-svn: 275051
  • Loading branch information
hokein committed Jul 11, 2016
1 parent cba9f80 commit d121875
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 0 additions & 9 deletions clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
Expand Up @@ -218,15 +218,6 @@ FileOptionsProvider::FileOptionsProvider(
std::vector<OptionsSource>
FileOptionsProvider::getRawOptions(StringRef FileName) {
DEBUG(llvm::dbgs() << "Getting options for file " << FileName << "...\n");
SmallString<256> FilePath(FileName);

if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
llvm::errs() << "Can't make absolute path from " << FileName << ": "
<< EC.message() << "\n";
// FIXME: Figure out what to do.
} else {
FileName = FilePath;
}

std::vector<OptionsSource> RawOptions =
DefaultOptionsProvider::getRawOptions(FileName);
Expand Down
10 changes: 8 additions & 2 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Expand Up @@ -313,13 +313,19 @@ static int clangTidyMain(int argc, const char **argv) {
if (!PathList.empty()) {
FileName = PathList.front();
}
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);

SmallString<256> FilePath(FileName);
if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
llvm::errs() << "Can't make absolute path from " << FileName << ": "
<< EC.message() << "\n";
}
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);

if (ExplainConfig) {
//FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
RawOptions = OptionsProvider->getRawOptions(FileName);
RawOptions = OptionsProvider->getRawOptions(FilePath);
for (const std::string &Check : EnabledChecks) {
for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/test/clang-tidy/list-checks.cpp
@@ -0,0 +1,5 @@
// REQUIRES: shell
// RUN: mkdir -p %T/clang-tidy/list-checks/
// RUN: echo '{Checks: "-*,google-*"}' > %T/clang-tidy/.clang-tidy
// RUN: cd %T/clang-tidy/list-checks
// RUN: clang-tidy -list-checks | grep "^ *google-"

0 comments on commit d121875

Please sign in to comment.