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 HeaderName,
|
||||
ArrayRef<const char *> Args,
|
||||
bool AreSwiftArgs,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<unsigned> swiftVersion) = 0;
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -801,6 +801,7 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer,
|
||||
StringRef Name,
|
||||
StringRef HeaderName,
|
||||
ArrayRef<const char *> Args,
|
||||
bool AreSwiftArgs,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<unsigned> 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<const char *> 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;
|
||||
}
|
||||
|
||||
@@ -358,6 +358,7 @@ public:
|
||||
StringRef Name,
|
||||
StringRef HeaderName,
|
||||
ArrayRef<const char *> Args,
|
||||
bool AreSwiftArgs,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<unsigned> swiftVersion) override;
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ def line : Separate<["-"], "line">,
|
||||
HelpText<"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">,
|
||||
HelpText<"replace text ('text')">;
|
||||
def replace_EQ : Joined<["-"], "replace=">, Alias<replace>;
|
||||
|
||||
@@ -179,6 +179,11 @@ bool TestOptions::parseArgs(llvm::ArrayRef<const char *> Args) {
|
||||
break;
|
||||
}
|
||||
|
||||
case OPT_are_swift_args: {
|
||||
AreSwiftArgs = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case OPT_swift_version: {
|
||||
unsigned ver;
|
||||
if (StringRef(InputArg->getValue()).getAsInteger(10, ver)) {
|
||||
|
||||
@@ -77,6 +77,7 @@ struct TestOptions {
|
||||
std::string CachePath;
|
||||
llvm::SmallVector<std::string, 4> RequestOptions;
|
||||
llvm::ArrayRef<const char *> CompilerArgs;
|
||||
bool AreSwiftArgs;
|
||||
std::string USR;
|
||||
std::string SwiftName;
|
||||
std::string ObjCName;
|
||||
|
||||
@@ -580,6 +580,8 @@ static int handleTestInvocation(ArrayRef<const char *> 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);
|
||||
}
|
||||
|
||||
@@ -163,6 +163,7 @@ editorOpenInterface(StringRef Name, StringRef ModuleName,
|
||||
static sourcekitd_response_t
|
||||
editorOpenHeaderInterface(StringRef Name, StringRef HeaderName,
|
||||
ArrayRef<const char *> Args,
|
||||
bool AreSwiftArgs,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<unsigned> swiftVersion);
|
||||
|
||||
@@ -463,11 +464,13 @@ void handleRequestImpl(sourcekitd_object_t ReqObj, ResponseReceiver Rec) {
|
||||
int64_t SynthesizedExtension = false;
|
||||
Req.getInt64(KeySynthesizedExtension, SynthesizedExtension,
|
||||
/*isOptional=*/true);
|
||||
Optional<int64_t> AreSwiftArgs = Req.getOptionalInt64(KeyAreSwiftArgs);
|
||||
Optional<int64_t> swiftVerVal = Req.getOptionalInt64(KeySwiftVersion);
|
||||
Optional<unsigned> 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<const char *> Args,
|
||||
bool AreSwiftArgs,
|
||||
bool SynthesizedExtensions,
|
||||
Optional<unsigned> 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user