diff --git a/test/SourceKit/InterfaceGen/gen_header_swift_args.swift b/test/SourceKit/InterfaceGen/gen_header_swift_args.swift new file mode 100644 index 00000000000..c143c5b0927 --- /dev/null +++ b/test/SourceKit/InterfaceGen/gen_header_swift_args.swift @@ -0,0 +1,5 @@ +// REQUIRES: objc_interop +// RUN: %sourcekitd-test -req=interface-gen -are-swift-args -header %S/Inputs/header.h -- %s -enable-objc-interop -import-objc-header %S/Inputs/header.h > %t.response +// RUN: diff -u %S/gen_header.swift.response %t.response + +doSomethingInHead(1) diff --git a/tools/SourceKit/include/SourceKit/Core/LangSupport.h b/tools/SourceKit/include/SourceKit/Core/LangSupport.h index a02d1c6db87..0d1a3fd88c2 100644 --- a/tools/SourceKit/include/SourceKit/Core/LangSupport.h +++ b/tools/SourceKit/include/SourceKit/Core/LangSupport.h @@ -445,6 +445,7 @@ public: StringRef Name, StringRef HeaderName, ArrayRef Args, + bool AreSwiftArgs, bool SynthesizedExtensions, Optional swiftVersion) = 0; diff --git a/tools/SourceKit/include/SourceKit/Core/ProtocolUIDs.def b/tools/SourceKit/include/SourceKit/Core/ProtocolUIDs.def index 8fb92f0c425..aabf9a1a8c3 100644 --- a/tools/SourceKit/include/SourceKit/Core/ProtocolUIDs.def +++ b/tools/SourceKit/include/SourceKit/Core/ProtocolUIDs.def @@ -110,6 +110,7 @@ KEY(EnableDiagnostics, "key.enablediagnostics") KEY(GroupName, "key.groupname") KEY(ActionName, "key.actionname") KEY(SynthesizedExtension, "key.synthesizedextensions") +KEY(AreSwiftArgs, "key.areswiftargs") KEY(Names, "key.names") KEY(UIDs, "key.uids") diff --git a/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp b/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp index 4e640b21050..daa7c83c584 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp @@ -801,6 +801,7 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer, StringRef Name, StringRef HeaderName, ArrayRef Args, + bool AreSwiftArgs, bool SynthesizedExtensions, Optional swiftVersion) { CompilerInstance CI; @@ -810,13 +811,15 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer, CompilerInvocation Invocation; std::string Error; - if (getASTManager().initCompilerInvocation(Invocation, llvm::None, CI.getDiags(), + + ArrayRef SwiftArgs = AreSwiftArgs ? Args : llvm::None; + if (getASTManager().initCompilerInvocation(Invocation, SwiftArgs, CI.getDiags(), StringRef(), Error)) { Consumer.handleRequestError(Error.c_str()); return; } - if (initInvocationByClangArguments(Args, Invocation, Error)) { + if (!AreSwiftArgs && initInvocationByClangArguments(Args, Invocation, Error)) { Consumer.handleRequestError(Error.c_str()); return; } diff --git a/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h b/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h index e1b1176d890..23dffe35f1b 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h +++ b/tools/SourceKit/lib/SwiftLang/SwiftLangSupport.h @@ -358,6 +358,7 @@ public: StringRef Name, StringRef HeaderName, ArrayRef Args, + bool AreSwiftArgs, bool SynthesizedExtensions, Optional swiftVersion) override; diff --git a/tools/SourceKit/tools/sourcekitd-test/Options.td b/tools/SourceKit/tools/sourcekitd-test/Options.td index c2415817bc5..5217fa6e177 100644 --- a/tools/SourceKit/tools/sourcekitd-test/Options.td +++ b/tools/SourceKit/tools/sourcekitd-test/Options.td @@ -32,6 +32,9 @@ def line : Separate<["-"], "line">, HelpText<"line">; def line_EQ : Joined<["-"], "line=">, Alias; +def are_swift_args : Flag<["-"], "are-swift-args">, + HelpText<"Interpret the compiler arguments as Swift compiler arguments">; + def replace : Separate<["-"], "replace">, HelpText<"replace text ('text')">; def replace_EQ : Joined<["-"], "replace=">, Alias; diff --git a/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp b/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp index 2cd97ddd4e4..99bed112e36 100644 --- a/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp +++ b/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp @@ -179,6 +179,11 @@ bool TestOptions::parseArgs(llvm::ArrayRef Args) { break; } + case OPT_are_swift_args: { + AreSwiftArgs = true; + break; + } + case OPT_swift_version: { unsigned ver; if (StringRef(InputArg->getValue()).getAsInteger(10, ver)) { diff --git a/tools/SourceKit/tools/sourcekitd-test/TestOptions.h b/tools/SourceKit/tools/sourcekitd-test/TestOptions.h index fb06c473281..cd504babb7c 100644 --- a/tools/SourceKit/tools/sourcekitd-test/TestOptions.h +++ b/tools/SourceKit/tools/sourcekitd-test/TestOptions.h @@ -77,6 +77,7 @@ struct TestOptions { std::string CachePath; llvm::SmallVector RequestOptions; llvm::ArrayRef CompilerArgs; + bool AreSwiftArgs; std::string USR; std::string SwiftName; std::string ObjCName; diff --git a/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp b/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp index f2e15f10250..ddb658b2b96 100644 --- a/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp +++ b/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp @@ -580,6 +580,8 @@ static int handleTestInvocation(ArrayRef Args, sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestEditorOpenSwiftSourceInterface); } else { + if (Opts.AreSwiftArgs) + sourcekitd_request_dictionary_set_int64(Req, KeyAreSwiftArgs, true); sourcekitd_request_dictionary_set_uid(Req, KeyRequest, RequestEditorOpenHeaderInterface); } diff --git a/tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp b/tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp index 7560c15620d..5b1c8b8a804 100644 --- a/tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp +++ b/tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp @@ -163,6 +163,7 @@ editorOpenInterface(StringRef Name, StringRef ModuleName, static sourcekitd_response_t editorOpenHeaderInterface(StringRef Name, StringRef HeaderName, ArrayRef Args, + bool AreSwiftArgs, bool SynthesizedExtensions, Optional swiftVersion); @@ -463,11 +464,13 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) { int64_t SynthesizedExtension = false; Req.getInt64(KeySynthesizedExtension, SynthesizedExtension, /*isOptional=*/true); + Optional AreSwiftArgs = Req.getOptionalInt64(KeyAreSwiftArgs); Optional swiftVerVal = Req.getOptionalInt64(KeySwiftVersion); Optional swiftVer; if (swiftVerVal.hasValue()) swiftVer = *swiftVerVal; return Rec(editorOpenHeaderInterface(*Name, *HeaderName, Args, + AreSwiftArgs.getValueOr(false), SynthesizedExtension, swiftVer)); } @@ -1999,6 +2002,7 @@ static sourcekitd_response_t editorConvertMarkupToXML(StringRef Source) { static sourcekitd_response_t editorOpenHeaderInterface(StringRef Name, StringRef HeaderName, ArrayRef Args, + bool AreSwiftArgs, bool SynthesizedExtensions, Optional swiftVersion) { SKEditorConsumer EditC(/*EnableSyntaxMap=*/true, @@ -2006,7 +2010,7 @@ editorOpenHeaderInterface(StringRef Name, StringRef HeaderName, /*EnableDiagnostics=*/false, /*SyntacticOnly=*/false); LangSupport &Lang = getGlobalContext().getSwiftLangSupport(); - Lang.editorOpenHeaderInterface(EditC, Name, HeaderName, Args, + Lang.editorOpenHeaderInterface(EditC, Name, HeaderName, Args, AreSwiftArgs, SynthesizedExtensions, swiftVersion); return EditC.createResponse(); }