aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Fischer <greg@lunarg.com>2022-03-23 11:43:43 -0600
committerGitHub <noreply@github.com>2022-03-23 11:43:43 -0600
commit6d937739953b871453dbca46d91268901ac51b85 (patch)
tree4841b84d1007086237958f01d9e23add57135ff7
parent610fd6edf366ae7356e13d05bb98d901fdfe8ca8 (diff)
parentd44871ca085f572b1d6d0a1cb25d7cd4c8f78a5d (diff)
downloadglslang-6d937739953b871453dbca46d91268901ac51b85.tar.gz
Merge pull request #2906 from apanteleev/escape-deps
Make depfiles compatible with Windows paths
-rw-r--r--StandAlone/StandAlone.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp
index bda4ee78..f5dd3bb1 100644
--- a/StandAlone/StandAlone.cpp
+++ b/StandAlone/StandAlone.cpp
@@ -1168,6 +1168,27 @@ 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)
{
@@ -1175,10 +1196,12 @@ bool writeDepFile(std::string depfile, std::vector<std::string>& binaryFiles, co
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;
}