Skip to content

Commit 7d941e8

Browse files
Merge pull request #2178 from plugdata-team/heavy-path-escape
Heavy path escape
2 parents 74062a4 + 5867c32 commit 7d941e8

File tree

9 files changed

+119
-105
lines changed

9 files changed

+119
-105
lines changed

Source/Heavy/CppExporter.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,37 @@ class CppExporter final : public ExporterBase {
2929
projectCopyrightValue = tree.getProperty("projectCopyrightValue");
3030
}
3131

32-
bool performExport(String pdPatch, String const outdir, String name, String const copyright, StringArray searchPaths) override
32+
bool performExport(String const& pdPatch, String const& outdir, String const& name, String const& copyright, StringArray const& searchPaths) override
3333
{
3434
exportingView->showState(ExportingProgressView::Exporting);
3535

36-
StringArray args = { heavyExecutable.getFullPathName(), pdPatch, "-o" + outdir };
36+
#if JUCE_WINDOWS
37+
auto const heavyPath = heavyExecutable.getFullPathName().replaceCharacter('\\', '/');
38+
#else
39+
auto const heavyPath = heavyExecutable.getFullPathName();
40+
#endif
41+
StringArray args = { heavyPath.quoted(), pdPatch.quoted(), "-o", outdir.quoted() };
3742

38-
name = name.replaceCharacter('-', '_');
3943
args.add("-n" + name);
4044

4145
if (copyright.isNotEmpty()) {
4246
args.add("--copyright");
43-
args.add("\"" + copyright + "\"");
47+
args.add(copyright.quoted());
4448
}
4549

4650
args.add("-v");
4751

48-
String paths = "-p";
52+
args.add("-p");
4953
for (auto& path : searchPaths) {
50-
paths += " " + path;
54+
args.add(path);
5155
}
5256

53-
args.add(paths);
54-
5557
if (shouldQuit)
5658
return true;
5759

58-
auto compileString = args.joinIntoString(" ");
59-
exportingView->logToConsole("Command: " + compileString + "\n");
60-
start(compileString);
60+
auto const command = args.joinIntoString(" ");
61+
exportingView->logToConsole("Command: " + command + "\n");
62+
Toolchain::startShellScript(command, this);
6163

6264
waitForProcessToFinish(-1);
6365
exportingView->flushConsole();

Source/Heavy/DPFExporter.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,22 @@ class DPFExporter final : public ExporterBase {
132132
}
133133
}
134134

135-
bool performExport(String pdPatch, String outdir, String name, String copyright, StringArray searchPaths) override
135+
bool performExport(String const& pdPatch, String const& outdir, String const& name, String const& copyright, StringArray const& searchPaths) override
136136
{
137137
exportingView->showState(ExportingProgressView::Exporting);
138138

139-
StringArray args = { heavyExecutable.getFullPathName(), pdPatch, "-o" + outdir };
139+
#if JUCE_WINDOWS
140+
auto const heavyPath = heavyExecutable.getFullPathName().replaceCharacter('\\', '/');
141+
#else
142+
auto const heavyPath = heavyExecutable.getFullPathName();
143+
#endif
144+
StringArray args = { heavyPath.quoted(), pdPatch.quoted(), "-o", outdir.quoted() };
140145

141-
name = name.replaceCharacter('-', '_');
142146
args.add("-n" + name);
143147

144148
if (copyright.isNotEmpty()) {
145149
args.add("--copyright");
146-
args.add("\"" + copyright + "\"");
150+
args.add(copyright.quoted());
147151
}
148152

149153
auto makerName = getValue<String>(makerNameValue);
@@ -211,19 +215,17 @@ class DPFExporter final : public ExporterBase {
211215
args.add("-v");
212216
args.add("-gdpf");
213217

214-
String paths = "-p";
218+
args.add("-p");
215219
for (auto& path : searchPaths) {
216-
paths += " " + path;
220+
args.add(path);
217221
}
218222

219-
args.add(paths);
220-
221223
if (shouldQuit)
222224
return true;
223225

224-
auto compileString = args.joinIntoString(" ");
225-
exportingView->logToConsole("Command: " + compileString + "\n");
226-
start(compileString);
226+
auto const command = args.joinIntoString(" ");
227+
exportingView->logToConsole("Command: " + command + "\n");
228+
Toolchain::startShellScript(command, this);
227229

228230
waitForProcessToFinish(-1);
229231
exportingView->flushConsole();
@@ -268,8 +270,8 @@ class DPFExporter final : public ExporterBase {
268270
auto path = "export PATH=\"$PATH:" + Toolchain::dir.getChildFile("bin").getFullPathName().replaceCharacter('\\', '/') + "\"\n";
269271
auto cc = "CC=" + Toolchain::dir.getChildFile("bin").getChildFile("gcc.exe").getFullPathName().replaceCharacter('\\', '/') + " ";
270272
auto cxx = "CXX=" + Toolchain::dir.getChildFile("bin").getChildFile("g++.exe").getFullPathName().replaceCharacter('\\', '/') + " ";
271-
272-
Toolchain::startShellScript(path + cc + cxx + make.getFullPathName().replaceCharacter('\\', '/') + " -j4 -f " + makefile.getFullPathName().replaceCharacter('\\', '/'), this);
273+
auto shell = " SHELL=" + Toolchain::dir.getChildFile("bin").getChildFile("bash.exe").getFullPathName().replaceCharacter('\\', '/').quoted();
274+
Toolchain::startShellScript(path + cc + cxx + make.getFullPathName().replaceCharacter('\\', '/') + " -j4 -f " + makefile.getFullPathName().replaceCharacter('\\', '/') + shell, this);
273275

274276
#else // Linux or BSD
275277
auto prepareEnvironmentScript = Toolchain::dir.getChildFile("scripts").getChildFile("anywhere-setup.sh").getFullPathName() + "\n";

Source/Heavy/DaisyExporter.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class DaisyExporter final : public ExporterBase {
237237
return getExitCode();
238238
}
239239

240-
bool performExport(String pdPatch, String outdir, String name, String copyright, StringArray searchPaths) override
240+
bool performExport(String const& pdPatch, String const& outdir, String const& name, String const& copyright, StringArray const& searchPaths) override
241241
{
242242
auto target = getValue<int>(targetBoardValue) - 1;
243243
bool compile = getValue<int>(exportTypeValue) - 1;
@@ -248,15 +248,19 @@ class DaisyExporter final : public ExporterBase {
248248
auto rate = getValue<int>(samplerateValue) - 1;
249249
auto size = getValue<int>(patchSizeValue);
250250
auto appType = getValue<int>(appTypeValue);
251+
252+
#if JUCE_WINDOWS
253+
auto const heavyPath = heavyExecutable.getFullPathName().replaceCharacter('\\', '/');
254+
#else
255+
auto const heavyPath = heavyExecutable.getFullPathName();
256+
#endif
257+
StringArray args = { heavyPath.quoted(), pdPatch.quoted(), "-o", outdir.quoted() };
251258

252-
StringArray args = { heavyExecutable.getFullPathName(), pdPatch, "-o" + outdir };
253-
254-
name = name.replaceCharacter('-', '_');
255259
args.add("-n" + name);
256260

257261
if (copyright.isNotEmpty()) {
258262
args.add("--copyright");
259-
args.add("\"" + copyright + "\"");
263+
args.add(copyright.quoted());
260264
}
261265

262266
// set board definition
@@ -331,21 +335,19 @@ class DaisyExporter final : public ExporterBase {
331335

332336
metaJson->setProperty("daisy", metaDaisy);
333337
auto metaJsonFile = createMetaJson(metaJson);
334-
args.add("-m" + metaJsonFile.getFullPathName());
338+
args.add("-m" + metaJsonFile.getFullPathName().quoted());
335339

336340
args.add("-v");
337341
args.add("-gdaisy");
338342

339-
String paths = "-p";
343+
args.add("-p");
340344
for (auto& path : searchPaths) {
341-
paths += " " + path;
345+
args.add(path);
342346
}
343347

344-
args.add(paths);
345-
346-
auto compileString = args.joinIntoString(" ");
347-
exportingView->logToConsole("Command: " + compileString + "\n");
348-
start(compileString);
348+
auto const command = args.joinIntoString(" ");
349+
exportingView->logToConsole("Command: " + command + "\n");
350+
Toolchain::startShellScript(command, this);
349351
waitForProcessToFinish(-1);
350352
exportingView->flushConsole();
351353

@@ -385,15 +387,16 @@ class DaisyExporter final : public ExporterBase {
385387
#if JUCE_WINDOWS
386388
auto buildScript = make.getFullPathName().replaceCharacter('\\', '/')
387389
+ " -j4 -f "
388-
+ sourceDir.getChildFile("Makefile").getFullPathName().replaceCharacter('\\', '/')
390+
+ sourceDir.getChildFile("Makefile").getFullPathName().replaceCharacter('\\', '/').quoted()
391+
+ " SHELL=" + Toolchain::dir.getChildFile("bin").getChildFile("bash.exe").getFullPathName().replaceCharacter('\\', '/').quoted()
389392
+ " GCC_PATH="
390393
+ gccPath.replaceCharacter('\\', '/')
391394
+ " PROJECT_NAME=" + name;
392395

393396
Toolchain::startShellScript(buildScript, this);
394397
#else
395398
String buildScript = make.getFullPathName()
396-
+ " -j4 -f " + sourceDir.getChildFile("Makefile").getFullPathName()
399+
+ " -j4 -f " + sourceDir.getChildFile("Makefile").getFullPathName().quoted()
397400
+ " GCC_PATH=" + gccPath
398401
+ " PROJECT_NAME=" + name;
399402

Source/Heavy/ExporterBase.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ struct ExporterBase : public Component
127127

128128
void startExport(File const& outDir)
129129
{
130+
#if JUCE_WINDOWS
131+
auto const patchPath = patchFile.getFullPathName().replaceCharacter('\\', '/');
132+
auto const& outPath = outDir.getFullPathName().replaceCharacter('\\', '/');
133+
#else
130134
auto patchPath = patchFile.getFullPathName();
131135
auto const& outPath = outDir.getFullPathName();
136+
#endif
137+
132138
auto projectTitle = projectNameValue.toString();
133139
auto projectCopyright = projectCopyrightValue.toString();
134140

@@ -138,33 +144,35 @@ struct ExporterBase : public Component
138144
else
139145
projectTitle = "Untitled";
140146
}
147+
projectTitle = projectTitle.replaceCharacter('-', '_');
141148

142149
// Add original file location to search paths
143-
auto searchPaths = StringArray { realPatchFile.getParentDirectory().getFullPathName() };
144-
150+
auto searchPaths = StringArray {};
151+
if (realPatchFile.existsAsFile() && !realPatchFile.isRoot()) // Make sure file actually exists
152+
{
153+
#if JUCE_WINDOWS
154+
searchPaths.add(realPatchFile.getParentDirectory().getFullPathName().replaceCharacter('\\', '/').quoted());
155+
#else
156+
searchPaths.add(realPatchFile.getParentDirectory().getFullPathName().quoted());
157+
#endif
158+
}
145159
editor->pd->setThis();
146160

147161
// Get pd's search paths
148162
char* paths[1024];
149163
int numItems;
150164
pd::Interface::getSearchPaths(paths, &numItems);
151165

152-
if (realPatchFile.existsAsFile()) {
153-
searchPaths.add(realPatchFile.getParentDirectory().getFullPathName());
154-
}
155-
156166
for (int i = 0; i < numItems; i++) {
157-
searchPaths.add(paths[i]);
167+
searchPaths.add(String(paths[i]).quoted());
158168
}
159169

160170
// Make sure we don't add the file location twice
161171
searchPaths.removeDuplicates(false);
162-
163172
addJob([this, patchPath, outPath, projectTitle, projectCopyright, searchPaths]() mutable {
164173
exportingView->monitorProcessOutput(this);
165-
166174
exportingView->showState(ExportingProgressView::Exporting);
167-
175+
168176
auto const result = performExport(patchPath, outPath, projectTitle, projectCopyright, searchPaths);
169177

170178
if (shouldQuit)
@@ -223,5 +231,5 @@ struct ExporterBase : public Component
223231
}
224232

225233
private:
226-
virtual bool performExport(String pdPatch, String outdir, String name, String copyright, StringArray searchPaths) = 0;
234+
virtual bool performExport(String const& pdPatch, String const& outdir, String const& name, String const& copyright, StringArray const& searchPaths) = 0;
227235
};

Source/Heavy/OWLExporter.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,37 +86,38 @@ class OWLExporter : public ExporterBase {
8686
storeSlotProperty->setEnabled(exportType == 4);
8787
}
8888

89-
bool performExport(String pdPatch, String outdir, String name, String copyright, StringArray searchPaths) override
89+
bool performExport(String const& pdPatch, String const& outdir, String const& name, String const& copyright, StringArray const& searchPaths) override
9090
{
9191
auto target = getValue<int>(targetBoardValue);
9292
bool compile = getValue<int>(exportTypeValue) - 1;
9393
bool load = getValue<int>(exportTypeValue) == 3;
9494
bool store = getValue<int>(exportTypeValue) == 4;
9595
int slot = getValue<int>(storeSlotValue);
9696

97-
StringArray args = { heavyExecutable.getFullPathName(), pdPatch, "-o" + outdir };
97+
#if JUCE_WINDOWS
98+
auto const heavyPath = heavyExecutable.getFullPathName().replaceCharacter('\\', '/');
99+
#else
100+
auto const heavyPath = heavyExecutable.getFullPathName();
101+
#endif
102+
StringArray args = { heavyPath.quoted(), pdPatch.quoted(), "-o", outdir.quoted() };
98103

99-
name = name.replaceCharacter('-', '_');
100104
args.add("-n" + name);
101105

102106
if (copyright.isNotEmpty()) {
103107
args.add("--copyright");
104-
args.add("\"" + copyright + "\"");
108+
args.add(copyright.quoted());
105109
}
106110

107111
args.add("-v");
108112
args.add("-gOWL");
109113

110-
String paths = "-p";
114+
args.add("-p");
111115
for (auto& path : searchPaths) {
112-
paths += " " + path;
116+
args.add(path);
113117
}
114118

115-
args.add(paths);
116-
117-
auto compileString = args.joinIntoString(" ");
118-
exportingView->logToConsole("Command: " + compileString + "\n");
119-
start(compileString);
119+
exportingView->logToConsole("Command: " + args.joinIntoString(" ") + "\n");
120+
start(args);
120121

121122
waitForProcessToFinish(-1);
122123
exportingView->flushConsole();
@@ -164,7 +165,8 @@ class OWLExporter : public ExporterBase {
164165
+ " BUILD=../"
165166
+ " PATCHNAME=" + name
166167
+ " PATCHCLASS=HeavyPatch"
167-
+ " PATCHFILE=HeavyOWL_" + name + ".hpp";
168+
+ " PATCHFILE=HeavyOWL_" + name + ".hpp"
169+
+ " SHELL=" + Toolchain::dir.getChildFile("bin").getChildFile("bash.exe").getFullPathName().replaceCharacter('\\', '/').quoted();
168170
#else
169171
buildScript += make.getFullPathName()
170172
+ " -j4"

Source/Heavy/PdExporter.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,38 @@ class PdExporter final : public ExporterBase {
6161
}
6262
}
6363

64-
bool performExport(String pdPatch, String const outdir, String name, String const copyright, StringArray searchPaths) override
64+
bool performExport(String const& pdPatch, String const& outdir, String const &name, String const& copyright, StringArray const& searchPaths) override
6565
{
6666
exportingView->showState(ExportingProgressView::Exporting);
6767

68-
StringArray args = { heavyExecutable.getFullPathName(), pdPatch, "-o" + outdir };
68+
#if JUCE_WINDOWS
69+
auto const heavyPath = heavyExecutable.getFullPathName().replaceCharacter('\\', '/');
70+
#else
71+
auto const heavyPath = heavyExecutable.getFullPathName();
72+
#endif
73+
StringArray args = { heavyPath.quoted(), pdPatch.quoted(), "-o", outdir.quoted() };
6974

70-
name = name.replaceCharacter('-', '_');
7175
args.add("-n" + name);
7276

7377
if (copyright.isNotEmpty()) {
7478
args.add("--copyright");
75-
args.add("\"" + copyright + "\"");
79+
args.add(copyright.quoted());
7680
}
7781

7882
args.add("-v");
7983
args.add("-gpdext");
8084

81-
String paths = "-p";
85+
args.add("-p");
8286
for (auto& path : searchPaths) {
83-
paths += " " + path;
87+
args.add(path);
8488
}
8589

86-
args.add(paths);
87-
8890
if (shouldQuit)
8991
return true;
9092

91-
auto compileString = args.joinIntoString(" ");
92-
exportingView->logToConsole("Command: " + compileString + "\n");
93-
start(compileString);
93+
auto const command = args.joinIntoString(" ");
94+
exportingView->logToConsole("Command: " + command + "\n");
95+
Toolchain::startShellScript(command, this);
9496

9597
waitForProcessToFinish(-1);
9698
exportingView->flushConsole();
@@ -130,8 +132,9 @@ class PdExporter final : public ExporterBase {
130132
auto cc = "CC=" + Toolchain::dir.getChildFile("bin").getChildFile("gcc.exe").getFullPathName().replaceCharacter('\\', '/') + " ";
131133
auto cxx = "CXX=" + Toolchain::dir.getChildFile("bin").getChildFile("g++.exe").getFullPathName().replaceCharacter('\\', '/') + " ";
132134
auto pdbindir = "PDBINDIR=\"" + pdDll.getFullPathName().replaceCharacter('\\', '/') + "\" ";
135+
auto shell = " SHELL=" + Toolchain::dir.getChildFile("bin").getChildFile("bash.exe").getFullPathName().replaceCharacter('\\', '/').quoted();
133136

134-
Toolchain::startShellScript(path + cc + cxx + pdbindir + make.getFullPathName().replaceCharacter('\\', '/') + " -j4", this);
137+
Toolchain::startShellScript(path + cc + cxx + pdbindir + make.getFullPathName().replaceCharacter('\\', '/') + " -j4" + shell, this);
135138

136139
#else // Linux or BSD
137140
auto prepareEnvironmentScript = Toolchain::dir.getChildFile("scripts").getChildFile("anywhere-setup.sh").getFullPathName() + "\n";

Source/Heavy/Toolchain.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ class ToolchainInstaller final : public Component
326326
int statusCode = 0;
327327

328328
#if JUCE_WINDOWS
329-
String downloadSize = "1.2 GB";
329+
String downloadSize = "1.13 GB";
330330
#elif JUCE_MAC
331-
String downloadSize = "457 MB";
331+
String downloadSize = "460 MB";
332332
#else
333-
String downloadSize = "1.1 GB";
333+
String downloadSize = "799 MB";
334334
#endif
335335

336336
class ToolchainInstallerButton final : public Component {

0 commit comments

Comments
 (0)