Ninja: Backslash rules for Windows

Generally these are only required in build statements, as Ninja wants
to be able to chop paths up.  But it doesn't hurt to also try to use
them in command line arguments.
This commit is contained in:
Peter Collingbourne 2012-02-19 01:50:53 +00:00
parent 9362440a0b
commit cea03e632b
5 changed files with 25 additions and 15 deletions

View File

@ -84,6 +84,15 @@ std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit)
return result;
}
std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path)
{
std::string result = path;
#ifdef _WIN32
cmSystemTools::ReplaceString(result, "/", "\\");
#endif
return EncodeLiteral(result);
}
void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
const std::string& comment,
const std::string& rule,
@ -122,7 +131,7 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
for(cmNinjaDeps::const_iterator i = outputs.begin();
i != outputs.end();
++i)
builds << " " << EncodeIdent(*i, os);
builds << " " << EncodeIdent(EncodePath(*i), os);
builds << ":";
// Write the rule.
@ -132,7 +141,7 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
for(cmNinjaDeps::const_iterator i = explicitDeps.begin();
i != explicitDeps.end();
++i)
builds << " " << EncodeIdent(*i, os);
builds << " " << EncodeIdent(EncodePath(*i), os);
// Write implicit dependencies.
if(!implicitDeps.empty())
@ -141,7 +150,7 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
for(cmNinjaDeps::const_iterator i = implicitDeps.begin();
i != implicitDeps.end();
++i)
builds << " " << EncodeIdent(*i, os);
builds << " " << EncodeIdent(EncodePath(*i), os);
}
// Write order-only dependencies.
@ -151,7 +160,7 @@ void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
for(cmNinjaDeps::const_iterator i = orderOnlyDeps.begin();
i != orderOnlyDeps.end();
++i)
builds << " " << EncodeIdent(*i, os);
builds << " " << EncodeIdent(EncodePath(*i), os);
}
builds << "\n";

View File

@ -59,6 +59,7 @@ public:
static std::string EncodeIdent(const std::string &ident, std::ostream &vars);
static std::string EncodeLiteral(const std::string &lit);
static std::string EncodePath(const std::string &path);
/**
* Write the given @a comment to the output stream @a os. It

View File

@ -28,6 +28,9 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator()
, HomeRelativeOutputPath("")
{
this->IsMakefileGenerator = true;
#ifdef _WIN32
this->WindowsShell = true;
#endif
}
//----------------------------------------------------------------------------
@ -256,9 +259,11 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
std::string cmLocalNinjaGenerator::ConvertToNinjaPath(const char *path)
{
return this->Convert(path,
cmLocalGenerator::HOME_OUTPUT,
cmLocalGenerator::MAKEFILE);
std::string convPath = this->Convert(path, cmLocalGenerator::HOME_OUTPUT);
#ifdef _WIN32
cmSystemTools::ReplaceString(convPath, "/", "\\");
#endif
return convPath;
}
void

View File

@ -212,13 +212,6 @@ ComputeDefines(cmSourceFile *source, const std::string& language)
return defines;
}
std::string cmNinjaTargetGenerator::ConvertToNinjaPath(const char *path) const
{
return this->LocalGenerator->Convert(path,
cmLocalGenerator::HOME_OUTPUT,
cmLocalGenerator::MAKEFILE);
}
cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
{
// Static libraries never depend on other targets for linking.

View File

@ -75,7 +75,9 @@ protected:
std::string ComputeDefines(cmSourceFile *source,
const std::string& language);
std::string ConvertToNinjaPath(const char *path) const;
std::string ConvertToNinjaPath(const char *path) const {
return this->GetLocalGenerator()->ConvertToNinjaPath(path);
}
cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
return this->GetLocalGenerator()->MapToNinjaPath();
}