diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-05-09 19:15:56 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-05-10 18:22:26 (GMT) |
commit | a173a1173e06dad812afe17c9751cb7c2f94eda4 (patch) | |
tree | 08c54a94b347c88fa5077865366601c9d5604370 /Source/cmGlobalNinjaGenerator.cxx | |
parent | 741fb95f660c73035a26b572dfcd3d628d324d57 (diff) | |
download | CMake-a173a1173e06dad812afe17c9751cb7c2f94eda4.zip CMake-a173a1173e06dad812afe17c9751cb7c2f94eda4.tar.gz CMake-a173a1173e06dad812afe17c9751cb7c2f94eda4.tar.bz2 |
Ninja: Simplify cmGlobalNinjaGenerator::WriteRule method
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 76 |
1 files changed, 31 insertions, 45 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 4fa6ee6..06234aa 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -332,71 +332,57 @@ void cmGlobalNinjaGenerator::WriteRule( const std::string& rspfile, const std::string& rspcontent, const std::string& restat, bool generator) { + // -- Parameter checks // Make sure the rule has a name. if (name.empty()) { - cmSystemTools::Error("No name given for WriteRuleStatement! called " - "with comment: " + + cmSystemTools::Error("No name given for WriteRule! called with comment: " + comment); return; } // Make sure a command is given. if (command.empty()) { - cmSystemTools::Error("No command given for WriteRuleStatement! called " - "with comment: " + - comment); + cmSystemTools::Error( + "No command given for WriteRule! called with comment: " + comment); return; } - cmGlobalNinjaGenerator::WriteComment(os, comment); - - // Write the rule. - os << "rule " << name << "\n"; - - // Write the depfile if any. - if (!depfile.empty()) { - cmGlobalNinjaGenerator::Indent(os, 1); - os << "depfile = " << depfile << "\n"; - } - - // Write the deptype if any. - if (!deptype.empty()) { - cmGlobalNinjaGenerator::Indent(os, 1); - os << "deps = " << deptype << "\n"; + // Make sure response file content is given + if (!rspfile.empty() && rspcontent.empty()) { + cmSystemTools::Error("rspfile but no rspfile_content given for WriteRule! " + "called with comment: " + + comment); + return; } - // Write the command. - cmGlobalNinjaGenerator::Indent(os, 1); - os << "command = " << command << "\n"; - - // Write the description if any. - if (!description.empty()) { - cmGlobalNinjaGenerator::Indent(os, 1); - os << "description = " << description << "\n"; - } + // -- Write rule + // Write rule intro + cmGlobalNinjaGenerator::WriteComment(os, comment); + os << "rule " << name << '\n'; - if (!rspfile.empty()) { - if (rspcontent.empty()) { - cmSystemTools::Error("No rspfile_content given!" + comment); - return; + // Write rule key/value pairs + auto writeKV = [&os](const char* key, std::string const& value) { + if (!value.empty()) { + cmGlobalNinjaGenerator::Indent(os, 1); + os << key << " = " << value << '\n'; } - cmGlobalNinjaGenerator::Indent(os, 1); - os << "rspfile = " << rspfile << "\n"; - cmGlobalNinjaGenerator::Indent(os, 1); - os << "rspfile_content = " << rspcontent << "\n"; - } + }; - if (!restat.empty()) { - cmGlobalNinjaGenerator::Indent(os, 1); - os << "restat = " << restat << "\n"; + writeKV("depfile", depfile); + writeKV("deps", deptype); + writeKV("command", command); + writeKV("description", description); + if (!rspfile.empty()) { + writeKV("rspfile", rspfile); + writeKV("rspfile_content", rspcontent); } - + writeKV("restat", restat); if (generator) { - cmGlobalNinjaGenerator::Indent(os, 1); - os << "generator = 1\n"; + writeKV("generator", "1"); } - os << "\n"; + // Finish rule + os << '\n'; } void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os, |