Skip to content
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

[iOS] Not to use SwiftGenPlugin package to avoid high cpu usage #88

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@
"version" : "0.4.0"
}
},
{
"identity" : "swiftgenplugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SwiftGen/SwiftGenPlugin",
"state" : {
"revision" : "879b85a470cacd70c19e22eb7e11a3aed66f4068",
"version" : "6.6.2"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
Expand Down
15 changes: 13 additions & 2 deletions app-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var package = Package(
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "0.39.1"),
.package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.2"),
],
targets: [
.target(
Expand All @@ -42,7 +41,7 @@ var package = Package(
.process("Resources"),
],
plugins: [
.plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin"),
.plugin(name: "SwiftGenPlugin"),
]
),
.target(
Expand All @@ -67,11 +66,23 @@ var package = Package(
.target(name: "SwiftLintBinary"),
]
),
.plugin(
name: "SwiftGenPlugin",
capability: .buildTool(),
dependencies: [
.target(name: "swiftgen"),
]
),
.binaryTarget(
name: "SwiftLintBinary",
url: "https://github.com/realm/SwiftLint/releases/download/0.48.0/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "9c255e797260054296f9e4e4cd7e1339a15093d75f7c4227b9568d63edddba50"
),
.binaryTarget(
name: "swiftgen",
url: "https://github.com/SwiftGen/SwiftGen/releases/download/6.6.2/swiftgen-6.6.2.artifactbundle.zip",
checksum: "7586363e24edcf18c2da3ef90f379e9559c1453f48ef5e8fbc0b818fbbc3a045"
),
]
)

Expand Down
30 changes: 30 additions & 0 deletions app-ios/Plugins/SwiftGenPlugin/Plugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation
import PackagePlugin

@main
struct SwiftGenPlugins: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
let configurations: [Path] = [context.package.directory, target.directory]
.map { $0.appending("swiftgen.yml") }
Comment on lines +7 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey 👋 Thanks for this temporary workaround, it worked great in Xcode 13. However, in Xcode 14 we experience issues, because it is looking for the swiftgen.yml config file in both places and if one of them doesn't exist, the whole command fails.

The solution is to add .filter { FileManager.default.fileExists(atPath: $0.string) }.
Thanks to @Carrione for this idea! 🚀

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pchmelar NP :)


return try configurations.map { configuration in
return Command.prebuildCommand(
displayName: "SwiftGen",
executable: try context.tool(named: "swiftgen").path,
arguments: [
"config",
"run",
"--verbose",
"--config", "\(configuration)"
],
environment: [
"PROJECT_DIR": context.package.directory,
"TARGET_NAME": target.name,
"PRODUCT_MODULE_NAME": (target as? SourceModuleTarget)?.moduleName ?? "",
"DERIVED_SOURCES_DIR": context.pluginWorkDirectory
],
outputFilesDirectory: context.pluginWorkDirectory
)
}
}
}