mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[interface-gen] Support passing Swift compiler arguments for header file interface generation
Resolves rdar://problem/33249361.
This commit is contained in:
5
test/SourceKit/InterfaceGen/gen_header_swift_args.swift
Normal file
5
test/SourceKit/InterfaceGen/gen_header_swift_args.swift
Normal file
@@ -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)
|
||||||
@@ -445,6 +445,7 @@ public:
|
|||||||
StringRef Name,
|
StringRef Name,
|
||||||
StringRef HeaderName,
|
StringRef HeaderName,
|
||||||
ArrayRef<const char *> Args,
|
ArrayRef<const char *> Args,
|
||||||
|
bool AreSwiftArgs,
|
||||||
bool SynthesizedExtensions,
|
bool SynthesizedExtensions,
|
||||||
Optional<unsigned> swiftVersion) = 0;
|
Optional<unsigned> swiftVersion) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ KEY(EnableDiagnostics, "key.enablediagnostics")
|
|||||||
KEY(GroupName, "key.groupname")
|
KEY(GroupName, "key.groupname")
|
||||||
KEY(ActionName, "key.actionname")
|
KEY(ActionName, "key.actionname")
|
||||||
KEY(SynthesizedExtension, "key.synthesizedextensions")
|
KEY(SynthesizedExtension, "key.synthesizedextensions")
|
||||||
|
KEY(AreSwiftArgs, "key.areswiftargs")
|
||||||
|
|
||||||
KEY(Names, "key.names")
|
KEY(Names, "key.names")
|
||||||
KEY(UIDs, "key.uids")
|
KEY(UIDs, "key.uids")
|
||||||
|
|||||||
@@ -801,6 +801,7 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer,
|
|||||||
StringRef Name,
|
StringRef Name,
|
||||||
StringRef HeaderName,
|
StringRef HeaderName,
|
||||||
ArrayRef<const char *> Args,
|
ArrayRef<const char *> Args,
|
||||||
|
bool AreSwiftArgs,
|
||||||
bool SynthesizedExtensions,
|
bool SynthesizedExtensions,
|
||||||
Optional<unsigned> swiftVersion) {
|
Optional<unsigned> swiftVersion) {
|
||||||
CompilerInstance CI;
|
CompilerInstance CI;
|
||||||
@@ -810,13 +811,15 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer,
|
|||||||
|
|
||||||
CompilerInvocation Invocation;
|
CompilerInvocation Invocation;
|
||||||
std::string Error;
|
std::string Error;
|
||||||
if (getASTManager().initCompilerInvocation(Invocation, llvm::None, CI.getDiags(),
|
|
||||||
|
ArrayRef<const char *> SwiftArgs = AreSwiftArgs ? Args : llvm::None;
|
||||||
|
if (getASTManager().initCompilerInvocation(Invocation, SwiftArgs, CI.getDiags(),
|
||||||
StringRef(), Error)) {
|
StringRef(), Error)) {
|
||||||
Consumer.handleRequestError(Error.c_str());
|
Consumer.handleRequestError(Error.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initInvocationByClangArguments(Args, Invocation, Error)) {
|
if (!AreSwiftArgs && initInvocationByClangArguments(Args, Invocation, Error)) {
|
||||||
Consumer.handleRequestError(Error.c_str());
|
Consumer.handleRequestError(Error.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ public:
|
|||||||
StringRef Name,
|
StringRef Name,
|
||||||
StringRef HeaderName,
|
StringRef HeaderName,
|
||||||
ArrayRef<const char *> Args,
|
ArrayRef<const char *> Args,
|
||||||
|
bool AreSwiftArgs,
|
||||||
bool SynthesizedExtensions,
|
bool SynthesizedExtensions,
|
||||||
Optional<unsigned> swiftVersion) override;
|
Optional<unsigned> swiftVersion) override;
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ def line : Separate<["-"], "line">,
|
|||||||
HelpText<"line">;
|
HelpText<"line">;
|
||||||
def line_EQ : Joined<["-"], "line=">, Alias<line>;
|
def line_EQ : Joined<["-"], "line=">, Alias<line>;
|
||||||
|
|
||||||
|
def are_swift_args : Flag<["-"], "are-swift-args">,
|
||||||
|
HelpText<"Interpret the compiler arguments as Swift compiler arguments">;
|
||||||
|
|
||||||
def replace : Separate<["-"], "replace">,
|
def replace : Separate<["-"], "replace">,
|
||||||
HelpText<"replace text ('text')">;
|
HelpText<"replace text ('text')">;
|
||||||
def replace_EQ : Joined<["-"], "replace=">, Alias<replace>;
|
def replace_EQ : Joined<["-"], "replace=">, Alias<replace>;
|
||||||
|
|||||||
@@ -179,6 +179,11 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case OPT_are_swift_args: {
|
||||||
|
AreSwiftArgs = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case OPT_swift_version: {
|
case OPT_swift_version: {
|
||||||
unsigned ver;
|
unsigned ver;
|
||||||
if (StringRef(InputArg->getValue()).getAsInteger(10, ver)) {
|
if (StringRef(InputArg->getValue()).getAsInteger(10, ver)) {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ struct TestOptions {
|
|||||||
std::string CachePath;
|
std::string CachePath;
|
||||||
llvm::SmallVector<std::string, 4> RequestOptions;
|
llvm::SmallVector<std::string, 4> RequestOptions;
|
||||||
llvm::ArrayRef<const char *> CompilerArgs;
|
llvm::ArrayRef<const char *> CompilerArgs;
|
||||||
|
bool AreSwiftArgs;
|
||||||
std::string USR;
|
std::string USR;
|
||||||
std::string SwiftName;
|
std::string SwiftName;
|
||||||
std::string ObjCName;
|
std::string ObjCName;
|
||||||
|
|||||||
@@ -580,6 +580,8 @@ static int handleTestInvocation(ArrayRef<const char *> Args,
|
|||||||
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
|
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
|
||||||
RequestEditorOpenSwiftSourceInterface);
|
RequestEditorOpenSwiftSourceInterface);
|
||||||
} else {
|
} else {
|
||||||
|
if (Opts.AreSwiftArgs)
|
||||||
|
sourcekitd_request_dictionary_set_int64(Req, KeyAreSwiftArgs, true);
|
||||||
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
|
sourcekitd_request_dictionary_set_uid(Req, KeyRequest,
|
||||||
RequestEditorOpenHeaderInterface);
|
RequestEditorOpenHeaderInterface);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ editorOpenInterface(StringRef Name, StringRef ModuleName,
|
|||||||
static sourcekitd_response_t
|
static sourcekitd_response_t
|
||||||
editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
|
editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
|
||||||
ArrayRef<const char *> Args,
|
ArrayRef<const char *> Args,
|
||||||
|
bool AreSwiftArgs,
|
||||||
bool SynthesizedExtensions,
|
bool SynthesizedExtensions,
|
||||||
Optional<unsigned> swiftVersion);
|
Optional<unsigned> swiftVersion);
|
||||||
|
|
||||||
@@ -463,11 +464,13 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
|
|||||||
int64_t SynthesizedExtension = false;
|
int64_t SynthesizedExtension = false;
|
||||||
Req.getInt64(KeySynthesizedExtension, SynthesizedExtension,
|
Req.getInt64(KeySynthesizedExtension, SynthesizedExtension,
|
||||||
/*isOptional=*/true);
|
/*isOptional=*/true);
|
||||||
|
Optional<int64_t> AreSwiftArgs = Req.getOptionalInt64(KeyAreSwiftArgs);
|
||||||
Optional<int64_t> swiftVerVal = Req.getOptionalInt64(KeySwiftVersion);
|
Optional<int64_t> swiftVerVal = Req.getOptionalInt64(KeySwiftVersion);
|
||||||
Optional<unsigned> swiftVer;
|
Optional<unsigned> swiftVer;
|
||||||
if (swiftVerVal.hasValue())
|
if (swiftVerVal.hasValue())
|
||||||
swiftVer = *swiftVerVal;
|
swiftVer = *swiftVerVal;
|
||||||
return Rec(editorOpenHeaderInterface(*Name, *HeaderName, Args,
|
return Rec(editorOpenHeaderInterface(*Name, *HeaderName, Args,
|
||||||
|
AreSwiftArgs.getValueOr(false),
|
||||||
SynthesizedExtension, swiftVer));
|
SynthesizedExtension, swiftVer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1999,6 +2002,7 @@ static sourcekitd_response_t editorConvertMarkupToXML(StringRef Source) {
|
|||||||
static sourcekitd_response_t
|
static sourcekitd_response_t
|
||||||
editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
|
editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
|
||||||
ArrayRef<const char *> Args,
|
ArrayRef<const char *> Args,
|
||||||
|
bool AreSwiftArgs,
|
||||||
bool SynthesizedExtensions,
|
bool SynthesizedExtensions,
|
||||||
Optional<unsigned> swiftVersion) {
|
Optional<unsigned> swiftVersion) {
|
||||||
SKEditorConsumer EditC(/*EnableSyntaxMap=*/true,
|
SKEditorConsumer EditC(/*EnableSyntaxMap=*/true,
|
||||||
@@ -2006,7 +2010,7 @@ editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
|
|||||||
/*EnableDiagnostics=*/false,
|
/*EnableDiagnostics=*/false,
|
||||||
/*SyntacticOnly=*/false);
|
/*SyntacticOnly=*/false);
|
||||||
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
|
LangSupport &Lang = getGlobalContext().getSwiftLangSupport();
|
||||||
Lang.editorOpenHeaderInterface(EditC, Name, HeaderName, Args,
|
Lang.editorOpenHeaderInterface(EditC, Name, HeaderName, Args, AreSwiftArgs,
|
||||||
SynthesizedExtensions, swiftVersion);
|
SynthesizedExtensions, swiftVersion);
|
||||||
return EditC.createResponse();
|
return EditC.createResponse();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user