-
Notifications
You must be signed in to change notification settings - Fork 731
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
fix: Xcode integration for Swift Package Plugins #2554
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
84b274b
Improves shared code model and conforms to XcodeCommandPlugin
calvincestari ec77b99
Add Swift Package Manager test package
calvincestari 06b84a4
Add Swift Package Manager plugins test on CI
calvincestari eb163a8
Rename CI tests
calvincestari f388c2f
Remove CLI init and increase verbosity of generate
calvincestari c1c4846
Removes JS bundle from Swift package
calvincestari 8fffd65
Adds ignored options to CLI commands
calvincestari b966977
Updates package description to use local dependency path
calvincestari 2fc8659
Use correct target name
calvincestari 6f5c531
Adds documentation for Xcode plugin usage
calvincestari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,9 +62,6 @@ let package = Package( | |
exclude: [ | ||
"Info.plist", | ||
"Frontend/JavaScript", | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was forgotten about in #2548 resulting in a warning in Xcode. |
||
resources: [ | ||
.copy("Frontend/dist/ApolloCodegenFrontend.bundle.js"), | ||
]), | ||
.target( | ||
name: "ApolloSQLite", | ||
|
21 changes: 15 additions & 6 deletions
21
Plugins/ApolloCodegenPlugin-Fetch/ApolloCodegenPluginFetch.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main struct ApolloCodegenPluginFetch: CommandPlugin { | ||
@main struct ApolloCodegenPluginFetch: CodegenCommand { | ||
static var commandName: String = "fetch-schema" | ||
} | ||
|
||
extension ApolloCodegenPluginFetch: CommandPlugin { | ||
func performCommand(context: PluginContext, arguments: [String]) async throws { | ||
let process = Process() | ||
process.executableURL = try context.codegenExecutable | ||
process.arguments = ["fetch-schema"] + arguments | ||
try performCommand(contextProvider: context, arguments: arguments) | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
import XcodeProjectPlugin | ||
|
||
try process.run() | ||
process.waitUntilExit() | ||
extension ApolloCodegenPluginFetch: XcodeCommandPlugin { | ||
func performCommand(context: XcodePluginContext, arguments: [String]) throws { | ||
try performCommand(contextProvider: context, arguments: arguments) | ||
} | ||
} | ||
#endif |
1 change: 1 addition & 0 deletions
1
Plugins/ApolloCodegenPlugin-Fetch/Symbolic Links/SharedPackageFiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../SharedPackageFiles |
1 change: 0 additions & 1 deletion
1
Plugins/ApolloCodegenPlugin-Fetch/Symbolic Links/SharedPackagePluginExtensions
This file was deleted.
Oops, something went wrong.
21 changes: 15 additions & 6 deletions
21
Plugins/ApolloCodegenPlugin-Generate/ApolloCodegenPluginGenerate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main struct ApolloCodegenPluginGenerate: CommandPlugin { | ||
@main struct ApolloCodegenPluginGenerate: CodegenCommand { | ||
static var commandName: String = "generate" | ||
} | ||
|
||
extension ApolloCodegenPluginGenerate: CommandPlugin { | ||
func performCommand(context: PluginContext, arguments: [String]) async throws { | ||
let process = Process() | ||
process.executableURL = try context.codegenExecutable | ||
process.arguments = ["generate"] + arguments | ||
try performCommand(contextProvider: context, arguments: arguments) | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
import XcodeProjectPlugin | ||
|
||
try process.run() | ||
process.waitUntilExit() | ||
extension ApolloCodegenPluginGenerate: XcodeCommandPlugin { | ||
func performCommand(context: XcodePluginContext, arguments: [String]) throws { | ||
try performCommand(contextProvider: context, arguments: arguments) | ||
} | ||
} | ||
#endif |
1 change: 1 addition & 0 deletions
1
Plugins/ApolloCodegenPlugin-Generate/Symbolic Links/SharedPackageFiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../SharedPackageFiles |
1 change: 0 additions & 1 deletion
1
Plugins/ApolloCodegenPlugin-Generate/Symbolic Links/SharedPackagePluginExtensions
This file was deleted.
Oops, something went wrong.
21 changes: 15 additions & 6 deletions
21
Plugins/ApolloCodegenPlugin-Initialize/ApolloCodegenPluginInitialize.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
@main struct ApolloCodegenPluginInitialize: CommandPlugin { | ||
@main struct ApolloCodegenPluginInitialize: CodegenCommand { | ||
static var commandName: String = "init" | ||
} | ||
|
||
extension ApolloCodegenPluginInitialize: CommandPlugin { | ||
func performCommand(context: PluginContext, arguments: [String]) async throws { | ||
let process = Process() | ||
process.executableURL = try context.codegenExecutable | ||
process.arguments = ["init"] + arguments | ||
try performCommand(contextProvider: context, arguments: arguments) | ||
} | ||
} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
import XcodeProjectPlugin | ||
|
||
try process.run() | ||
process.waitUntilExit() | ||
extension ApolloCodegenPluginInitialize: XcodeCommandPlugin { | ||
func performCommand(context: XcodePluginContext, arguments: [String]) throws { | ||
try performCommand(contextProvider: context, arguments: arguments) | ||
} | ||
} | ||
#endif |
1 change: 1 addition & 0 deletions
1
Plugins/ApolloCodegenPlugin-Initialize/Symbolic Links/SharedPackageFiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../SharedPackageFiles |
1 change: 0 additions & 1 deletion
1
Plugins/ApolloCodegenPlugin-Initialize/Symbolic Links/SharedPackagePluginExtensions
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Foundation | ||
|
||
protocol CodegenCommand { | ||
static var commandName: String { get } | ||
|
||
func performCommand(contextProvider: PluginContextProvider, arguments: [String]) throws | ||
} | ||
|
||
extension CodegenCommand { | ||
func performCommand(contextProvider: PluginContextProvider, arguments: [String]) throws { | ||
let process = Process() | ||
process.executableURL = try contextProvider.codegenExecutable | ||
process.arguments = [Self.commandName] + arguments | ||
|
||
try process.run() | ||
process.waitUntilExit() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Plugins/SharedPackageFiles/PluginContext+codegenExecutableURL.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
import PackagePlugin | ||
|
||
protocol PluginContextProvider { | ||
func tool(named name: String) throws -> PackagePlugin.PluginContext.Tool | ||
} | ||
|
||
extension PluginContextProvider { | ||
var codegenExecutable: URL { | ||
get throws { | ||
let executable = try tool(named: "apollo-ios-cli") | ||
return URL(fileURLWithPath: executable.path.string) | ||
} | ||
} | ||
} | ||
|
||
extension PluginContext: PluginContextProvider {} | ||
|
||
#if canImport(XcodeProjectPlugin) | ||
import XcodeProjectPlugin | ||
|
||
extension XcodePluginContext: PluginContextProvider {} | ||
#endif |
11 changes: 0 additions & 11 deletions
11
Plugins/SharedPackagePluginExtensions/PluginContext+codegenExecutableURL.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import ArgumentParser | ||
|
||
/// Shared group of arguments that are sent by various automation tools, such as Xcode, but are | ||
/// ignored from input. | ||
struct IgnoredOptions: ParsableArguments { | ||
@Option( | ||
name: .long, | ||
help: ArgumentHelp( | ||
"Ignored - used by Xcode only.", | ||
discussion: """ | ||
Xcode will automatically include this option when calling any plugin command to pass the | ||
target name of the Swift package. This option is ignored and is not intended to be sent | ||
by anything other than Xcode. | ||
""", | ||
visibility: .hidden | ||
) | ||
) | ||
var target: String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "swiftpm-test", | ||
platforms: [.macOS(.v10_15)], | ||
products: [ | ||
.library( | ||
name: "swiftpm-test", | ||
targets: ["swiftpm-test"]), | ||
], | ||
dependencies: [ | ||
.package(name: "apollo-ios", path: "../../.."), | ||
], | ||
targets: [ | ||
.target( | ||
name: "swiftpm-test", | ||
dependencies: [ | ||
.product(name: "Apollo", package: "apollo-ios"), | ||
]), | ||
] | ||
) |
6 changes: 6 additions & 0 deletions
6
Tests/CodegenCLITests/swiftpm-test/Sources/swiftpm-test/swiftpm_test.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public struct swiftpm_test { | ||
public private(set) var text = "Hello, World!" | ||
|
||
public init() { | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Tests/CodegenCLITests/swiftpm-test/apollo-codegen-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"schemaName" : "NewTestSchema", | ||
"input" : { | ||
"operationSearchPaths" : [ | ||
"./graphql/**/*.graphql" | ||
], | ||
"schemaSearchPaths" : [ | ||
"./graphql/**/*.graphqls" | ||
] | ||
}, | ||
"output" : { | ||
"testMocks" : { | ||
"none" : { | ||
} | ||
}, | ||
"schemaTypes" : { | ||
"path" : "./NewTestSchema", | ||
"moduleType" : { | ||
"embeddedInTarget" : { | ||
"name": "swiftpm_test" | ||
} | ||
} | ||
}, | ||
"operations" : { | ||
"relative" : { | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query AllBooks { | ||
books { | ||
title | ||
author { | ||
name | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Tests/CodegenCLITests/swiftpm-test/graphql/schema.graphqls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
type Book { | ||
title: String | ||
author: Author | ||
} | ||
|
||
type Author { | ||
name: String | ||
books: [Book] | ||
} | ||
|
||
type Query { | ||
books: [Book] | ||
authors: [Author] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only test the
generate
command here because we needed have an existing JSON config file to prevent codegen finding all the test graphQL definition files in the.build
folder. We're going to fix that behaviour in #2552.