diff options
author | Brad King <brad.king@kitware.com> | 2016-05-06 18:19:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-06 18:25:55 (GMT) |
commit | 64b5520346c75ec479042a114390a0bf71909723 (patch) | |
tree | bea1373e84594ba036fe50eea3eab86375d63aa6 /Source/cmGlobalNinjaGenerator.cxx | |
parent | 73601ff831faa80a188e5997ee048b6986b00a5c (diff) | |
download | CMake-64b5520346c75ec479042a114390a0bf71909723.zip CMake-64b5520346c75ec479042a114390a0bf71909723.tar.gz CMake-64b5520346c75ec479042a114390a0bf71909723.tar.bz2 |
Isolate formatted streaming blocks with clang-format off/on
The clang-format tool can do a good job formatting most code, but
well-organized streaming blocks are best left manually formatted.
Find blocks of the form
os <<
"...\n"
"...\n"
;
using the command
$ git ls-files -z -- Source |
egrep -v -z '^Source/kwsys/' |
xargs -0 pcregrep -M --color=always -B 1 -A 1 -n \
'<<[^\n]*\n(^ *("[^\n]*("|<<|;)$|;)\n){2,}'
Find blocks of the form
os << "...\n"
<< "...\n"
<< "...\n";
using the command
$ git ls-files -z -- Source |
egrep -v -z '^Source/kwsys/' |
xargs -0 pcregrep -M --color=always -B 1 -A 1 -n \
'<<[^\n]*\n(^ *<<[^\n]*(\\n"|<<|;)$\n){2,}'
Surround such blocks with the pair
/* clang-format off */
...
/* clang-format on */
in order to protect them from update by clang-format. Use the C-style
`/*...*/` comments instead of C++-style `//...` comments in order to
prevent them from ever being swallowed by re-formatting of surrounding
comments.
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index a8a7262..953df6b 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -820,11 +820,13 @@ void cmGlobalNinjaGenerator::OpenRulesFileStream() this->WriteDisclaimer(*this->RulesFileStream); // Write comment about this file. + /* clang-format off */ *this->RulesFileStream << "# This file contains all the rules used to get the outputs files\n" << "# built from the input files.\n" << "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n" ; + /* clang-format on */ } void cmGlobalNinjaGenerator::CloseRulesFileStream() @@ -891,6 +893,7 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand( } + /* clang-format off */ *this->CompileCommandsStream << "\n{\n" << " \"directory\": \"" << cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n" @@ -899,6 +902,7 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand( << " \"file\": \"" << cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n" << "}"; + /* clang-format on */ } void cmGlobalNinjaGenerator::CloseCompileCommandsStream() @@ -1149,9 +1153,11 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) //dependencies that we have no rule for cmGlobalNinjaGenerator::WriteDivider(os); + /* clang-format off */ os << "# Unknown Build Time Dependencies.\n" << "# Tell Ninja that they may appear as side effects of build rules\n" << "# otherwise ordered by order-only dependencies.\n\n"; + /* clang-format on */ //get the list of files that cmake itself has generated as a //product of configuration. @@ -1256,6 +1262,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) if (!warnExplicitDepends.empty()) { std::ostringstream w; + /* clang-format off */ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0058) << "\n" "This project specifies custom command DEPENDS on files " "in the build tree that are not specified as the OUTPUT or " @@ -1269,6 +1276,7 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os) "Project authors should add the missing BYPRODUCTS or OUTPUT " "options to the custom commands that produce these files." ; + /* clang-format on */ this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } } |