Hiralo updated this revision to Diff 301065. Hiralo added a comment. Latest patch with Lit test-case.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89936/new/ https://reviews.llvm.org/D89936 Files: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp Index: clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp @@ -0,0 +1,9 @@ +// REQUIRES: shell +// RUN: clang-tidy --config-file=%S/Inputs/config-file/config-file %T/read-file-config/test.cpp | grep "warning: .*\[hicpp-uppercase-literal-suffix\]$" + +void f() { + unsigned long c = 100ull; + int x; + x = 1; + x = 2; +} Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file @@ -0,0 +1 @@ +Checks: "-*,hicpp-uppercase-literal-suffix" Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -73,6 +73,14 @@ )"), cl::init(""), cl::cat(ClangTidyCategory)); +static cl::opt<std::string> ConfigFile("config-file", cl::desc(R"( +Specify full path of .clang-tidy or custom config file. +For example, --config-file=/some/path/myTidyConfig +Note: this option is mutually exclusive to --config and --checks options. +)"), + cl::init(""), + cl::cat(ClangTidyCategory)); + static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"( Upgrades warnings to errors. Same format as '-checks'. @@ -302,6 +310,30 @@ if (UseColor.getNumOccurrences() > 0) OverrideOptions.UseColor = UseColor; + if (!ConfigFile.empty()) { + if (!Config.empty()) { + llvm::errs() << "Error: --config-file and --config are mutually " + "exclusive. Specify only one.\n"; + return nullptr; + } + + if (!Checks.empty()) { + llvm::errs() << "Error: --config-file and --checks are mutually " + "exclusive. Specify only one.\n"; + return nullptr; + } + + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = + llvm::MemoryBuffer::getFile(ConfigFile.c_str()); + if (std::error_code EC = Text.getError()) { + llvm::errs() << "Can't read config-file '" << ConfigFile + << "': " << EC.message() << "\n"; + return nullptr; + } + + Config.assign((*Text)->getBuffer()); + } + if (!Config.empty()) { if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig = parseConfiguration(Config)) {
Index: clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp @@ -0,0 +1,9 @@ +// REQUIRES: shell +// RUN: clang-tidy --config-file=%S/Inputs/config-file/config-file %T/read-file-config/test.cpp | grep "warning: .*\[hicpp-uppercase-literal-suffix\]$" + +void f() { + unsigned long c = 100ull; + int x; + x = 1; + x = 2; +} Index: clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file @@ -0,0 +1 @@ +Checks: "-*,hicpp-uppercase-literal-suffix" Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -73,6 +73,14 @@ )"), cl::init(""), cl::cat(ClangTidyCategory)); +static cl::opt<std::string> ConfigFile("config-file", cl::desc(R"( +Specify full path of .clang-tidy or custom config file. +For example, --config-file=/some/path/myTidyConfig +Note: this option is mutually exclusive to --config and --checks options. +)"), + cl::init(""), + cl::cat(ClangTidyCategory)); + static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"( Upgrades warnings to errors. Same format as '-checks'. @@ -302,6 +310,30 @@ if (UseColor.getNumOccurrences() > 0) OverrideOptions.UseColor = UseColor; + if (!ConfigFile.empty()) { + if (!Config.empty()) { + llvm::errs() << "Error: --config-file and --config are mutually " + "exclusive. Specify only one.\n"; + return nullptr; + } + + if (!Checks.empty()) { + llvm::errs() << "Error: --config-file and --checks are mutually " + "exclusive. Specify only one.\n"; + return nullptr; + } + + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text = + llvm::MemoryBuffer::getFile(ConfigFile.c_str()); + if (std::error_code EC = Text.getError()) { + llvm::errs() << "Can't read config-file '" << ConfigFile + << "': " << EC.message() << "\n"; + return nullptr; + } + + Config.assign((*Text)->getBuffer()); + } + if (!Config.empty()) { if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig = parseConfiguration(Config)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits