[driver] Separate "delegate to the migrator with swift-update" and "get compiler fixits with swift-fixit" functionalities.

Swift SVN r27139
This commit is contained in:
Argyrios Kyrtzidis
2015-04-08 22:02:23 +00:00
parent bd14e0cc4c
commit 623b9827b4
11 changed files with 29 additions and 13 deletions

View File

@@ -68,6 +68,9 @@ public:
/// Invoke swift-update with the compiler frontend options.
UpdateCode,
/// Invoke swift-fixit with the compiler frontend options.
FixCode,
};
/// The mode in which the driver should invoke the frontend.
@@ -118,7 +121,7 @@ public:
enum class DriverKind {
Interactive, // swift
Batch, // swiftc
UpdateCode, // swift-update
FixCode, // swift-fixit
AutolinkExtract, // swift-autolink-extract
};

View File

@@ -84,7 +84,7 @@ def driver_use_frontend_path : Separate<["-"], "driver-use-frontend-path">,
HelpText<"Use the given executable to perform compilations">;
def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
HelpText<"Set the driver mode to either 'swift' or 'swiftc' or 'swift-update'">;
HelpText<"Set the driver mode to either 'swift' or 'swiftc' or 'swift-fixit'">;
def help : Flag<["-", "--"], "help">,
Flags<[FrontendOption, AutolinkExtractOption]>,

View File

@@ -93,7 +93,8 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
llvm::StringSwitch<Optional<DriverKind>>(DriverName)
.Case("swift", DriverKind::Interactive)
.Case("swiftc", DriverKind::Batch)
.Case("swift-update", DriverKind::UpdateCode)
.Case("swift-fixit", DriverKind::FixCode)
.Case("swift-update", DriverKind::FixCode) // FIXME: remove once fully transitioned.
.Case("swift-autolink-extract", DriverKind::AutolinkExtract)
.Default(None);
@@ -1027,6 +1028,7 @@ void Driver::buildActions(const ToolChain &TC,
ActionList CompileActions;
switch (OI.CompilerMode) {
case OutputInfo::Mode::StandardCompile:
case OutputInfo::Mode::FixCode:
case OutputInfo::Mode::UpdateCode: {
for (const InputPair &Input : Inputs) {
types::ID InputType = Input.first;
@@ -1831,7 +1833,7 @@ void Driver::printHelp(bool ShowHidden) const {
ExcludedFlagsBitmask |= options::NoInteractiveOption;
break;
case DriverKind::Batch:
case DriverKind::UpdateCode:
case DriverKind::FixCode:
case DriverKind::AutolinkExtract:
ExcludedFlagsBitmask |= options::NoBatchOption;
break;

View File

@@ -156,6 +156,10 @@ Job *Swift::constructJob(const JobAction &JA, std::unique_ptr<JobList> Inputs,
SmallString<128> SwiftUpdatePath = llvm::sys::path::parent_path(Exec);
llvm::sys::path::append(SwiftUpdatePath, "swift-update");
Exec = Args.MakeArgString(SwiftUpdatePath.str());
} else if (OI.CompilerMode == OutputInfo::Mode::FixCode) {
SmallString<128> SwiftFixPath = llvm::sys::path::parent_path(Exec);
llvm::sys::path::append(SwiftFixPath, "swift-fixit");
Exec = Args.MakeArgString(SwiftFixPath.str());
} else {
// Invoke ourselves in -frontend mode.
Arguments.push_back("-frontend");

View File

@@ -1,4 +1,4 @@
// RUN: %swift-update -c -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia -emit-module-doc-path %t.doc -emit-module-path %t.mod
// RUN: %swift-fixit -c -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia -emit-module-doc-path %t.doc -emit-module-path %t.mod
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
// RUN: FileCheck --input-file=%t.deserialized_diagnostics.txt %s

View File

@@ -1,4 +1,4 @@
// RUN: %swift-update -c -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia -emit-module-doc-path %t.doc -emit-module-path %t.mod
// RUN: %swift-fixit -c -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia -emit-module-doc-path %t.doc -emit-module-path %t.mod
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
// RUN: FileCheck --input-file=%t.deserialized_diagnostics.txt %s

View File

@@ -1,4 +1,4 @@
// RUN: not %swift-update -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia
// RUN: not %swift-fixit -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
// RUN: FileCheck --input-file=%t.deserialized_diagnostics.txt %s

View File

@@ -1,4 +1,4 @@
// RUN: not %swift-update -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia
// RUN: not %swift-fixit -target %target-triple %s -o %t.remap -serialize-diagnostics-path %t.dia
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
// RUN: FileCheck --input-file=%t.deserialized_diagnostics.txt %s

View File

@@ -20,6 +20,10 @@ add_custom_command(TARGET swift POST_BUILD
COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "swift" "swiftc"
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
add_custom_command(TARGET swift POST_BUILD
COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "swift" "swift-fixit"
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
add_custom_command(TARGET swift POST_BUILD
COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "swift" "swift-autolink-extract"
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
@@ -50,6 +54,9 @@ swift_install_in_component(compiler
swift_install_in_component(compiler
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc"
DESTINATION "bin")
swift_install_in_component(compiler
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swift-fixit"
DESTINATION "bin")
if(SWIFT_HOST_VARIANT STREQUAL "LINUX")
# No need for this on other platforms.

View File

@@ -48,8 +48,8 @@ std::string getExecutablePath(const char *FirstArg) {
extern int frontend_main(ArrayRef<const char *> Args, const char *Argv0,
void *MainAddr);
/// Run 'swift-update'.
extern int update_main(ArrayRef<const char *> Args, const char *Argv0,
/// Run 'swift-fixit'.
extern int fixit_main(ArrayRef<const char *> Args, const char *Argv0,
void *MainAddr);
/// Run 'swift-autolink-extract'.
@@ -93,8 +93,8 @@ int main(int argc_, const char **argv_) {
Driver TheDriver(Path, llvm::sys::path::stem(argv[0]), argv, Diags);
switch (TheDriver.getDriverKind()) {
case Driver::DriverKind::UpdateCode:
return update_main(TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
case Driver::DriverKind::FixCode:
return fixit_main(TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
argv[0],
(void *)(intptr_t)getExecutablePath);
case Driver::DriverKind::AutolinkExtract:

View File

@@ -108,7 +108,7 @@ private:
} // anonymous namespace
int update_main(ArrayRef<const char *> Args, const char *Argv0, void *MainAddr){
int fixit_main(ArrayRef<const char *> Args, const char *Argv0, void *MainAddr){
CompilerInstance Instance;
PrintingDiagnosticConsumer PDC;
Instance.addDiagnosticConsumer(&PDC);