Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape paths in depfiles. #6569

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tools/clang/test/DXC/Inputs/include/dependency6 $#[].h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef DEPENDENCY_6_H_
#define DEPENDENCY_6_H_

// Empty

#endif // DEPENDENCY_6_H_
25 changes: 18 additions & 7 deletions tools/clang/test/DXC/dump_dependency.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
// RUN: %dxc /T ps_6_0 %s -I %S/Inputs /MD
// RUN: FileCheck --input-file=%S/dump_dependency.d %s

// CHECK-DAG:dependency0.h
// CHECK-DAG:dependency1.h
// CHECK-DAG:dependency2.h
// CHECK-DAG:dependency3.h
// CHECK-DAG:dependency4.h
// CHECK-DAG:dependency5.h
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dump_dependency.hlsl:{{[ ]}}
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency0.h \
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency1.h \
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency2.h \
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency3.h \
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency4.h \
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency5.h \
// CHECK-DAG:{{^([a-zA-Z]\\:\\\\|/|\\\\)}}
// CHECK-DAG:dependency6\ $$\#\[\].h
// CHECK-NOT:\

// RUN: rm %S/dump_dependency.d


#include "include/dependency0.h"
#include "include/dependency2.h"
#include "include/dependency6 $#[].h"

float4 main() : SV_Target
{
Expand Down
32 changes: 27 additions & 5 deletions tools/clang/tools/dxcompiler/dxcompilerobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,16 +887,38 @@ class DxcCompiler : public IDxcCompiler3,
preprocessAction.Execute();
preprocessAction.EndSourceFile();

outStream << (opts.OutputObject.empty() ? opts.InputFile
: opts.OutputObject);
auto writeEscapedPath = [](auto &stream, auto const &path) {
for (auto p : path) {
switch (p) {
case ':':
case ' ':
case '#':
case '[':
case ']':
case '\\':
stream << '\\';
break;
case '$':
stream << '$';
break;
}
stream << p;
}
};

writeEscapedPath(outStream, opts.OutputObject.empty()
? opts.InputFile
: opts.OutputObject);

bool firstDependency = true;
for (auto &dependency : dependencyCollector->getDependencies()) {
if (firstDependency) {
outStream << ": " << dependency;
outStream << ": ";
firstDependency = false;
continue;
} else {
outStream << " \\\n ";
}
outStream << " \\\n " << dependency;
writeEscapedPath(outStream, dependency);
}
outStream << "\n";
outStream.flush();
Expand Down
Loading