aboutsummaryrefslogtreecommitdiff
path: root/src/Ninja.cpp
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-09-24 15:19:56 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-09-24 15:25:04 +0200
commit0ebcfc62e435d352b4a2035ac1791b867228194d (patch)
tree9ac0ec31283ab4e67b60df60edc88bb6e8b310d3 /src/Ninja.cpp
parent2698cbc14f8a2a108a3252f03e053cb47b8b5101 (diff)
Escape input arg, which usually is a filename
Diffstat (limited to 'src/Ninja.cpp')
-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())
{