aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Ninja.cpp53
1 files changed, 50 insertions, 3 deletions
diff --git a/src/Ninja.cpp b/src/Ninja.cpp
index 9b9e177..778e701 100644
--- a/src/Ninja.cpp
+++ b/src/Ninja.cpp
@@ -72,6 +72,32 @@ namespace ninja
return true;
}
+ static std::string escape(const std::string &str)
+ {
+ std::string result;
+ result.reserve(str.size());
+ for(char c : str)
+ {
+ if(c == '"')
+ result += "\\\"";
+ else
+ result += c;
+ }
+ return '"' + result + '"';
+ }
+
+ static std::string combine_escape(const std::vector<std::string> &strs)
+ {
+ std::string result;
+ for(const std::string &str : strs)
+ {
+ if(!result.empty())
+ result += ' ';
+ result += escape(str);
+ }
+ return result;
+ }
+
NinjaVariable::NinjaVariable(const std::string &_name) :
name(_name)
{
@@ -93,6 +119,11 @@ namespace ninja
{
delete rule.second;
}
+
+ for(NinjaBuild *build : builds)
+ {
+ delete build;
+ }
}
NinjaBuild* NinjaRule::build(const std::string &in, const std::string &out, const std::vector<ninja::NinjaArgValue> &additionalArgs, const std::vector<NinjaBuild*> &dependsOnBuilds)
@@ -100,6 +131,11 @@ namespace ninja
return buildFile->build(this, in, out, additionalArgs, dependsOnBuilds);
}
+ NinjaBuild* NinjaRule::build(const std::vector<std::string> &in, const std::string &out, const std::vector<ninja::NinjaArgValue> &additionalArgs, const std::vector<NinjaBuild*> &dependsOnBuilds)
+ {
+ return buildFile->build(this, in, out, additionalArgs, dependsOnBuilds);
+ }
+
void NinjaBuildFile::defineGlobalVariable(const std::string &name, const std::string &value)
{
if(!isValidName(name))
@@ -127,7 +163,14 @@ namespace ninja
NinjaBuild* NinjaBuildFile::build(const NinjaRule *rule, const std::string &in, const std::string &out, const std::vector<ninja::NinjaArgValue> &additionalArgs, const std::vector<NinjaBuild*> &dependsOnBuilds)
{
- NinjaBuild *build = new NinjaBuild { rule, in, out, additionalArgs, dependsOnBuilds };
+ NinjaBuild *build = new NinjaBuild { rule, { in }, escape(out), additionalArgs, dependsOnBuilds };
+ builds.push_back(build);
+ return build;
+ }
+
+ NinjaBuild* NinjaBuildFile::build(const NinjaRule *rule, const std::vector<std::string> &in, const std::string &out, const std::vector<ninja::NinjaArgValue> &additionalArgs, const std::vector<NinjaBuild*> &dependsOnBuilds)
+ {
+ NinjaBuild *build = new NinjaBuild { rule, in, escape(out), additionalArgs, dependsOnBuilds };
builds.push_back(build);
return build;
}
@@ -157,10 +200,14 @@ namespace ninja
result += "\n depfile = ";
result += rule.second->depFile;
}
+ if(!rule.second->deps.empty())
+ {
+ result += "\n deps = ";
+ result += rule.second->deps;
+ }
result += "\n\n";
}
- // TODO: enclose all names with quotes to escape whitespace?
for(const NinjaBuild *build : builds)
{
result += "build ";
@@ -168,7 +215,7 @@ namespace ninja
result += ": ";
result += build->rule->name;
result += ' ';
- result += build->in;
+ result += combine_escape(build->in);
if(!build->dependsOnBuilds.empty())
{