Skip to content

Commit 972bd3c

Browse files
authored
Support for escaped paths in tools (shader-slang#1823)
* #include an absolute path didn't work - because paths were taken to always be relative. * Split out StringEscapeUtil. * Added StringEscapeUtil. * Fix typo in unix quoting type. * Small comment improvements. * Try to fix linux linking issue. * Fix typo. * Attempt to fix linux link issue. * Update VS proj even though nothing really changed. * Fix another typo issue. * Fix for windows issue. Fixed bug. * Make separate Utils for escaping. * Fix typo. * Split out into StringEscapeHandler. * Windows shell does handle removing quotes (so remove code to remove them). * Handle unescaping if not initiating using the shell. * Slight improvement around shell like decoding. * Simplify command extraction. * Add shared-library category type. * Fix bug in command extraction. * Typo in transcendental category. * Enable unit-test on in smoke test category. * Make parsing failing output as a failing test. * Fixes for transcendental tests. Disable tests that do not work. * Changed category parsing. * Removed the TestResult parameter from _gatherTestsForFile. Made testsList only output. * Remove testing if all tests were disabled. * Fix typo. * Disable path canonical test on linux because CI issue.
1 parent 541d1ca commit 972bd3c

21 files changed

+962
-309
lines changed

build/visual-studio/core/core.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
<ClInclude Include="..\..\..\source\core\slang-smart-pointer.h" />
211211
<ClInclude Include="..\..\..\source\core\slang-std-writers.h" />
212212
<ClInclude Include="..\..\..\source\core\slang-stream.h" />
213+
<ClInclude Include="..\..\..\source\core\slang-string-escape-util.h" />
213214
<ClInclude Include="..\..\..\source\core\slang-string-slice-pool.h" />
214215
<ClInclude Include="..\..\..\source\core\slang-string-util.h" />
215216
<ClInclude Include="..\..\..\source\core\slang-string.h" />
@@ -245,6 +246,7 @@
245246
<ClCompile Include="..\..\..\source\core\slang-shared-library.cpp" />
246247
<ClCompile Include="..\..\..\source\core\slang-std-writers.cpp" />
247248
<ClCompile Include="..\..\..\source\core\slang-stream.cpp" />
249+
<ClCompile Include="..\..\..\source\core\slang-string-escape-util.cpp" />
248250
<ClCompile Include="..\..\..\source\core\slang-string-slice-pool.cpp" />
249251
<ClCompile Include="..\..\..\source\core\slang-string-util.cpp" />
250252
<ClCompile Include="..\..\..\source\core\slang-string.cpp" />

build/visual-studio/core/core.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<ClInclude Include="..\..\..\source\core\slang-stream.h">
130130
<Filter>Header Files</Filter>
131131
</ClInclude>
132+
<ClInclude Include="..\..\..\source\core\slang-string-escape-util.h">
133+
<Filter>Header Files</Filter>
134+
</ClInclude>
132135
<ClInclude Include="..\..\..\source\core\slang-string-slice-pool.h">
133136
<Filter>Header Files</Filter>
134137
</ClInclude>
@@ -230,6 +233,9 @@
230233
<ClCompile Include="..\..\..\source\core\slang-stream.cpp">
231234
<Filter>Source Files</Filter>
232235
</ClCompile>
236+
<ClCompile Include="..\..\..\source\core\slang-string-escape-util.cpp">
237+
<Filter>Source Files</Filter>
238+
</ClCompile>
233239
<ClCompile Include="..\..\..\source\core\slang-string-slice-pool.cpp">
234240
<Filter>Source Files</Filter>
235241
</ClCompile>

build/visual-studio/slang-cpp-extractor/slang-cpp-extractor.vcxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@
186186
<ClCompile Include="..\..\..\tools\slang-cpp-extractor\unit-test.cpp" />
187187
</ItemGroup>
188188
<ItemGroup>
189-
<ProjectReference Include="..\core\core.vcxproj">
190-
<Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project>
191-
</ProjectReference>
192189
<ProjectReference Include="..\compiler-core\compiler-core.vcxproj">
193190
<Project>{12C1E89D-F5D0-41D3-8E8D-FB3F358F8126}</Project>
194191
</ProjectReference>
192+
<ProjectReference Include="..\core\core.vcxproj">
193+
<Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project>
194+
</ProjectReference>
195195
</ItemGroup>
196196
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
197197
<ImportGroup Label="ExtensionTargets">

premake5.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ tool "slang-cpp-extractor"
719719
uuid "CA8A30D1-8FA9-4330-B7F7-84709246D8DC"
720720
includedirs { "." }
721721

722-
links { "core", "compiler-core" }
722+
links { "compiler-core", "core" }
723723

724724
--
725725
-- `slang-generate` is a tool we use for source code generation on

source/compiler-core/slang-nvrtc-compiler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ SlangResult NVRTCDownstreamCompiler::compile(const CompileOptions& options, RefP
824824
}
825825
ScopeProgram scope(this, program);
826826

827-
List<const char*> dstOptions;
827+
List<const char*> dstOptions;
828828
dstOptions.setCount(cmdLine.m_args.getCount());
829829
for (Index i = 0; i < cmdLine.m_args.getCount(); ++i)
830830
{

source/compiler-core/slang-source-loc.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "slang-source-loc.h"
33

44
#include "../core/slang-string-util.h"
5+
#include "../core/slang-string-escape-util.h"
56

67
namespace Slang {
78

@@ -66,10 +67,7 @@ void PathInfo::appendDisplayName(StringBuilder& out) const
6667
case Type::FromString:
6768
case Type::FoundPath:
6869
{
69-
70-
out.appendChar('"');
71-
StringUtil::appendEscaped(foundPath.getUnownedSlice(), out);
72-
out.appendChar('"');
70+
StringEscapeUtil::appendQuoted(StringEscapeUtil::getHandler(StringEscapeUtil::Style::Cpp), foundPath.getUnownedSlice(), out);
7371
break;
7472
}
7573
default: break;

source/core/slang-process-util.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "slang-string.h"
66
#include "slang-list.h"
77

8+
#include "slang-string-escape-util.h"
9+
810
namespace Slang {
911

1012
struct CommandLine
@@ -80,6 +82,10 @@ struct ExecuteResult
8082

8183
struct ProcessUtil
8284
{
85+
/// The quoting style used for the command line on this target. Currently just uses Space,
86+
/// but in future may take into account platform sec
87+
static StringEscapeHandler* getEscapeHandler();
88+
8389
/// Get the suffix used on this platform
8490
static UnownedStringSlice getExecutableSuffix();
8591

@@ -89,9 +95,6 @@ struct ProcessUtil
8995
/// Execute the command line
9096
static SlangResult execute(const CommandLine& commandLine, ExecuteResult& outExecuteResult);
9197

92-
/// Append text escaped for using on a command line
93-
static void appendCommandLineEscaped(const UnownedStringSlice& slice, StringBuilder& out);
94-
9598
static uint64_t getClockFrequency();
9699

97100
static uint64_t getClockTick();
@@ -116,19 +119,21 @@ SLANG_INLINE Index CommandLine::findArgIndex(const UnownedStringSlice& slice) co
116119
// -----------------------------------------------------------------------
117120
SLANG_INLINE void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const char* pathPostfix)
118121
{
122+
auto escapeHandler = ProcessUtil::getEscapeHandler();
123+
119124
StringBuilder builder;
120125
builder << prefix;
121126
if (pathPostfix)
122127
{
123128
// Work out the path with the postfix
124129
StringBuilder fullPath;
125130
fullPath << path << pathPostfix;
126-
ProcessUtil::appendCommandLineEscaped(fullPath.getUnownedSlice(), builder);
131+
StringEscapeUtil::appendMaybeQuoted(escapeHandler, fullPath.getUnownedSlice(), builder);
127132
}
128133
else
129134
{
130-
ProcessUtil::appendCommandLineEscaped(path.getUnownedSlice(), builder);
131-
}
135+
StringEscapeUtil::appendMaybeQuoted(escapeHandler, path.getUnownedSlice(), builder);
136+
}
132137

133138
// This arg doesn't need subsequent escaping
134139
addEscapedArg(builder);

0 commit comments

Comments
 (0)