Skip to content

Allow Arguments in -driver-use-frontend-path #22596

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

Merged
merged 1 commit into from
Feb 20, 2019
Merged
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
9 changes: 8 additions & 1 deletion include/swift/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class Driver {
/// The original path to the executable.
std::string DriverExecutable;

// Extra args to pass to the driver executable
SmallVector<std::string, 2> DriverExecutableArgs;

DriverKind driverKind = DriverKind::Interactive;

/// Default target triple.
Expand All @@ -191,7 +194,11 @@ class Driver {
const std::string &getSwiftProgramPath() const {
return DriverExecutable;
}


ArrayRef<std::string> getSwiftProgramArgs() const {
return DriverExecutableArgs;
}

DriverKind getDriverKind() const { return driverKind; }

ArrayRef<const char *> getArgsWithoutProgramNameAndDriverMode(
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def driver_skip_execution : Flag<["-"], "driver-skip-execution">,
HelpText<"Skip execution of subtasks when performing compilation">;
def driver_use_frontend_path : Separate<["-"], "driver-use-frontend-path">,
InternalDebugOpt,
HelpText<"Use the given executable to perform compilations">;
HelpText<"Use the given executable to perform compilations. Arguments can be passed as a ';' separated list">;
def driver_show_incremental : Flag<["-"], "driver-show-incremental">,
InternalDebugOpt,
HelpText<"With -v, dump information about why files are being rebuilt">;
Expand Down
10 changes: 9 additions & 1 deletion lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,16 @@ bool Driver::handleImmediateArgs(const ArgList &Args, const ToolChain &TC) {
SuppressNoInputFilesError = true;
}

if (const Arg *A = Args.getLastArg(options::OPT_driver_use_frontend_path))
if (const Arg *A = Args.getLastArg(options::OPT_driver_use_frontend_path)) {
DriverExecutable = A->getValue();
std::string commandString =
Args.getLastArgValue(options::OPT_driver_use_frontend_path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you changed this from using getLastArg. (It's going to do two searches now…not that we're particularly efficient about that right now.)

SmallVector<StringRef, 10> commandArgs;
StringRef(commandString).split(commandArgs, ';', -1, false);
DriverExecutable = commandArgs[0];
DriverExecutableArgs.assign(std::begin(commandArgs) + 1,
std::end(commandArgs));
}

return true;
}
Expand Down
14 changes: 14 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ ToolChain::constructInvocation(const CompileJobAction &job,
ArgStringList &Arguments = II.Arguments;
II.allowsResponseFiles = true;

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());
Arguments.push_back("-frontend");

{
Expand Down Expand Up @@ -595,6 +597,8 @@ ToolChain::constructInvocation(const InterpretJobAction &job,
ArgStringList &Arguments = II.Arguments;
II.allowsResponseFiles = true;

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());
Arguments.push_back("-frontend");
Arguments.push_back("-interpret");

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

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());
Arguments.push_back("-frontend");

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

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());
Arguments.push_back("-frontend");

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

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());
Arguments.push_back("-modulewrap");

addInputsOfType(Arguments, context.Inputs, context.Args,
Expand Down Expand Up @@ -896,6 +906,8 @@ ToolChain::constructInvocation(const REPLJobAction &job,
}

ArgStringList FrontendArgs;
for (auto &s : getDriver().getSwiftProgramArgs())
FrontendArgs.push_back(s.c_str());
addCommonFrontendArgs(*this, context.OI, context.Output, context.Args,
FrontendArgs);
context.Args.AddLastArg(FrontendArgs, options::OPT_import_objc_header);
Expand Down Expand Up @@ -976,6 +988,8 @@ ToolChain::constructInvocation(const GeneratePCHJobAction &job,
ArgStringList &Arguments = II.Arguments;
II.allowsResponseFiles = true;

for (auto &s : getDriver().getSwiftProgramArgs())
Arguments.push_back(s.c_str());
Arguments.push_back("-frontend");

addCommonFrontendArgs(*this, context.OI, context.Output, context.Args,
Expand Down
12 changes: 6 additions & 6 deletions test/Driver/Dependencies/chained.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
// RUN: cp -r %S/Inputs/chained/* %t
// RUN: touch -t 201401240005 %t/*

// 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
// 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

// CHECK-FIRST-NOT: warning
// CHECK-FIRST: Handled main.swift
// CHECK-FIRST: Handled other.swift
// CHECK-FIRST: Handled yet-another.swift

// 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
// 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

// CHECK-SECOND-NOT: Handled

// RUN: touch -t 201401240006 %t/other.swift
// 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
// 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

// CHECK-THIRD: Handled other.swift
// CHECK-THIRD-DAG: Handled main.swift
// CHECK-THIRD-DAG: Handled yet-another.swift

// RUN: touch -t 201401240007 %t/other.swift
// 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
// 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

// RUN: touch -t 201401240008 %t/other.swift
// 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
// 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

// RUN: touch -t 201401240009 %t/other.swift
// 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
// 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