Skip to content

Commit 9eeabc9

Browse files
Jason Mittertreinerjrose-apple
authored andcommitted
Allow Arguments in -driver-use-frontend-path (#22596)
Windows doesn't know what a shebang is, so it's unable to run tests that use -driver-use-frontend-path with a script. This allows the script interpreter to be run as the executable with the script as its first argument. e.g. --driver-use-frontend-path "python;my-script.py"
1 parent 3f9cb36 commit 9eeabc9

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

include/swift/Driver/Driver.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class Driver {
165165
/// The original path to the executable.
166166
std::string DriverExecutable;
167167

168+
// Extra args to pass to the driver executable
169+
SmallVector<std::string, 2> DriverExecutableArgs;
170+
168171
DriverKind driverKind = DriverKind::Interactive;
169172

170173
/// Default target triple.
@@ -191,7 +194,11 @@ class Driver {
191194
const std::string &getSwiftProgramPath() const {
192195
return DriverExecutable;
193196
}
194-
197+
198+
ArrayRef<std::string> getSwiftProgramArgs() const {
199+
return DriverExecutableArgs;
200+
}
201+
195202
DriverKind getDriverKind() const { return driverKind; }
196203

197204
ArrayRef<const char *> getArgsWithoutProgramNameAndDriverMode(

include/swift/Option/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def driver_skip_execution : Flag<["-"], "driver-skip-execution">,
9797
HelpText<"Skip execution of subtasks when performing compilation">;
9898
def driver_use_frontend_path : Separate<["-"], "driver-use-frontend-path">,
9999
InternalDebugOpt,
100-
HelpText<"Use the given executable to perform compilations">;
100+
HelpText<"Use the given executable to perform compilations. Arguments can be passed as a ';' separated list">;
101101
def driver_show_incremental : Flag<["-"], "driver-show-incremental">,
102102
InternalDebugOpt,
103103
HelpText<"With -v, dump information about why files are being rebuilt">;

lib/Driver/Driver.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2003,8 +2003,16 @@ bool Driver::handleImmediateArgs(const ArgList &Args, const ToolChain &TC) {
20032003
SuppressNoInputFilesError = true;
20042004
}
20052005

2006-
if (const Arg *A = Args.getLastArg(options::OPT_driver_use_frontend_path))
2006+
if (const Arg *A = Args.getLastArg(options::OPT_driver_use_frontend_path)) {
20072007
DriverExecutable = A->getValue();
2008+
std::string commandString =
2009+
Args.getLastArgValue(options::OPT_driver_use_frontend_path);
2010+
SmallVector<StringRef, 10> commandArgs;
2011+
StringRef(commandString).split(commandArgs, ';', -1, false);
2012+
DriverExecutable = commandArgs[0];
2013+
DriverExecutableArgs.assign(std::begin(commandArgs) + 1,
2014+
std::end(commandArgs));
2015+
}
20082016

20092017
return true;
20102018
}

lib/Driver/ToolChains.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ ToolChain::constructInvocation(const CompileJobAction &job,
268268
ArgStringList &Arguments = II.Arguments;
269269
II.allowsResponseFiles = true;
270270

271+
for (auto &s : getDriver().getSwiftProgramArgs())
272+
Arguments.push_back(s.c_str());
271273
Arguments.push_back("-frontend");
272274

273275
{
@@ -595,6 +597,8 @@ ToolChain::constructInvocation(const InterpretJobAction &job,
595597
ArgStringList &Arguments = II.Arguments;
596598
II.allowsResponseFiles = true;
597599

600+
for (auto &s : getDriver().getSwiftProgramArgs())
601+
Arguments.push_back(s.c_str());
598602
Arguments.push_back("-frontend");
599603
Arguments.push_back("-interpret");
600604

@@ -631,6 +635,8 @@ ToolChain::constructInvocation(const BackendJobAction &job,
631635
assert(context.Args.hasArg(options::OPT_embed_bitcode));
632636
ArgStringList Arguments;
633637

638+
for (auto &s : getDriver().getSwiftProgramArgs())
639+
Arguments.push_back(s.c_str());
634640
Arguments.push_back("-frontend");
635641

636642
// Determine the frontend mode option.
@@ -773,6 +779,8 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
773779
ArgStringList &Arguments = II.Arguments;
774780
II.allowsResponseFiles = true;
775781

782+
for (auto &s : getDriver().getSwiftProgramArgs())
783+
Arguments.push_back(s.c_str());
776784
Arguments.push_back("-frontend");
777785

778786
Arguments.push_back("-merge-modules");
@@ -853,6 +861,8 @@ ToolChain::constructInvocation(const ModuleWrapJobAction &job,
853861
ArgStringList &Arguments = II.Arguments;
854862
II.allowsResponseFiles = true;
855863

864+
for (auto &s : getDriver().getSwiftProgramArgs())
865+
Arguments.push_back(s.c_str());
856866
Arguments.push_back("-modulewrap");
857867

858868
addInputsOfType(Arguments, context.Inputs, context.Args,
@@ -896,6 +906,8 @@ ToolChain::constructInvocation(const REPLJobAction &job,
896906
}
897907

898908
ArgStringList FrontendArgs;
909+
for (auto &s : getDriver().getSwiftProgramArgs())
910+
FrontendArgs.push_back(s.c_str());
899911
addCommonFrontendArgs(*this, context.OI, context.Output, context.Args,
900912
FrontendArgs);
901913
context.Args.AddLastArg(FrontendArgs, options::OPT_import_objc_header);
@@ -976,6 +988,8 @@ ToolChain::constructInvocation(const GeneratePCHJobAction &job,
976988
ArgStringList &Arguments = II.Arguments;
977989
II.allowsResponseFiles = true;
978990

991+
for (auto &s : getDriver().getSwiftProgramArgs())
992+
Arguments.push_back(s.c_str());
979993
Arguments.push_back("-frontend");
980994

981995
addCommonFrontendArgs(*this, context.OI, context.Output, context.Args,

test/Driver/Dependencies/chained.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
// RUN: cp -r %S/Inputs/chained/* %t
55
// RUN: touch -t 201401240005 %t/*
66

7-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
7+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
88

99
// CHECK-FIRST-NOT: warning
1010
// CHECK-FIRST: Handled main.swift
1111
// CHECK-FIRST: Handled other.swift
1212
// CHECK-FIRST: Handled yet-another.swift
1313

14-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-SECOND %s
14+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-SECOND %s
1515

1616
// CHECK-SECOND-NOT: Handled
1717

1818
// RUN: touch -t 201401240006 %t/other.swift
19-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
19+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
2020

2121
// CHECK-THIRD: Handled other.swift
2222
// CHECK-THIRD-DAG: Handled main.swift
2323
// CHECK-THIRD-DAG: Handled yet-another.swift
2424

2525
// RUN: touch -t 201401240007 %t/other.swift
26-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./other.swift ./main.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
26+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./other.swift ./main.swift ./yet-another.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
2727

2828
// RUN: touch -t 201401240008 %t/other.swift
29-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./yet-another.swift ./other.swift ./main.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
29+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./yet-another.swift ./other.swift ./main.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
3030

3131
// RUN: touch -t 201401240009 %t/other.swift
32-
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./other.swift ./yet-another.swift ./main.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s
32+
// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path "%{python};%S/Inputs/update-dependencies.py" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./other.swift ./yet-another.swift ./main.swift -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-THIRD %s

0 commit comments

Comments
 (0)