Skip to content

Commit

Permalink
Merge pull request KhronosGroup#2906 from apanteleev/escape-deps
Browse files Browse the repository at this point in the history
Make depfiles compatible with Windows paths
  • Loading branch information
greg-lunarg authored Mar 23, 2022
2 parents 610fd6e + d44871c commit 6d93773
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions StandAlone/StandAlone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,17 +1168,40 @@ struct ShaderCompUnit {
}
};

// Writes a string into a depfile, escaping some special characters following the Makefile rules.
static void writeEscapedDepString(std::ofstream& file, const std::string& str)
{
for (char c : str) {
switch (c) {
case ' ':
case ':':
case '#':
case '[':
case ']':
case '\\':
file << '\\';
break;
case '$':
file << '$';
break;
}
file << c;
}
}

// Writes a depfile similar to gcc -MMD foo.c
bool writeDepFile(std::string depfile, std::vector<std::string>& binaryFiles, const std::vector<std::string>& sources)
{
std::ofstream file(depfile);
if (file.fail())
return false;

for (auto it = binaryFiles.begin(); it != binaryFiles.end(); it++) {
file << *it << ":";
for (auto it = sources.begin(); it != sources.end(); it++) {
file << " " << *it;
for (auto binaryFile = binaryFiles.begin(); binaryFile != binaryFiles.end(); binaryFile++) {
writeEscapedDepString(file, *binaryFile);
file << ":";
for (auto sourceFile = sources.begin(); sourceFile != sources.end(); sourceFile++) {
file << " ";
writeEscapedDepString(file, *sourceFile);
}
file << std::endl;
}
Expand Down

0 comments on commit 6d93773

Please sign in to comment.