summaryrefslogtreecommitdiffstats
path: root/Source/cmcmd.cxx
diff options
context:
space:
mode:
authorJamie Snape <jamie.snape@kitware.com>2017-01-23 19:47:13 (GMT)
committerJamie Snape <jamie.snape@kitware.com>2017-01-23 19:47:13 (GMT)
commit0618ddf6b1da3a886f12b6ad2b19da49b2f87e28 (patch)
treeadb7c502f13bd571ff192e644de923f195b8fc81 /Source/cmcmd.cxx
parent7b4514fb33cf256ef165b2b28ba4affd1930a957 (diff)
downloadCMake-0618ddf6b1da3a886f12b6ad2b19da49b2f87e28.zip
CMake-0618ddf6b1da3a886f12b6ad2b19da49b2f87e28.tar.gz
CMake-0618ddf6b1da3a886f12b6ad2b19da49b2f87e28.tar.bz2
Add properties to run the cpplint style checker with the compiler
Create a `<LANG>_CPPLINT` target property (initialized by a `CMAKE_<LANG>_CPPLINT` variable) to specify a `cpplint` style checker command line to be run along with the compiler.
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r--Source/cmcmd.cxx42
1 files changed, 37 insertions, 5 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 5b12a75..823b38f 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -276,7 +276,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
if (args[1] == "__run_iwyu") {
if (args.size() < 3) {
std::cerr << "__run_iwyu Usage: -E __run_iwyu [--iwyu=/path/iwyu]"
- " [--tidy=/path/tidy] -- compile command\n";
+ " [--cpplint=/path/cpplint] [--tidy=/path/tidy]"
+ " -- compile command\n";
return 1;
}
bool doing_options = true;
@@ -285,6 +286,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::string tidy;
std::string sourceFile;
std::string lwyu;
+ std::string cpplint;
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
std::string const& arg = args[cc];
if (arg == "--") {
@@ -297,6 +299,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
sourceFile = arg.substr(9);
} else if (doing_options && cmHasLiteralPrefix(arg, "--lwyu=")) {
lwyu = arg.substr(7);
+ } else if (doing_options && cmHasLiteralPrefix(arg, "--cpplint=")) {
+ cpplint = arg.substr(10);
} else if (doing_options) {
std::cerr << "__run_iwyu given unknown argument: " << arg << "\n";
return 1;
@@ -304,12 +308,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
orig_cmd.push_back(arg);
}
}
- if (tidy.empty() && iwyu.empty() && lwyu.empty()) {
- std::cerr << "__run_iwyu missing --tidy= or --iwyu=\n";
+ if (tidy.empty() && iwyu.empty() && lwyu.empty() && cpplint.empty()) {
+ std::cerr << "__run_iwyu missing --cpplint=, --iwyu=, --lwyu=, and/or"
+ " --tidy=\n";
return 1;
}
- if (!tidy.empty() && sourceFile.empty()) {
- std::cerr << "__run_iwyu --tidy= requires --source=\n";
+ if ((!cpplint.empty() || !tidy.empty()) && sourceFile.empty()) {
+ std::cerr << "__run_iwyu --cpplint= and/or __run_iwyu --tidy="
+ " require --source=\n";
return 1;
}
if (orig_cmd.empty() && lwyu.empty()) {
@@ -403,6 +409,32 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::cerr << "Warning: " << stdOut;
}
}
+
+ if (!cpplint.empty()) {
+ // Construct the cpplint command line.
+ std::vector<std::string> cpplint_cmd;
+ cmSystemTools::ExpandListArgument(cpplint, cpplint_cmd, true);
+ cpplint_cmd.push_back(sourceFile);
+
+ // Run the cpplint command line. Capture its output.
+ std::string stdOut;
+ if (!cmSystemTools::RunSingleCommand(cpplint_cmd, &stdOut, &stdOut,
+ &ret, CM_NULLPTR,
+ cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << cpplint_cmd[0] << "': " << stdOut
+ << "\n";
+ return 1;
+ }
+
+ // Output the output from cpplint to stderr
+ std::cerr << stdOut;
+
+ // If cpplint exited with an error do the same.
+ if (ret != 0) {
+ return ret;
+ }
+ }
+
ret = 0;
// Now run the real compiler command and return its result value.
if (lwyu.empty() &&