Skip to content

Commit

Permalink
workaround: not to use SwiftGenPlugin package to avoid high cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ry-itto committed Aug 29, 2022
1 parent ec0808f commit 471c982
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.

This file was deleted.

15 changes: 13 additions & 2 deletions app-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var package = Package(
.library(name: "Strings", targets: ["Strings"]),
],
dependencies: [
.package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.2"),
],
targets: [
.target(
Expand All @@ -33,7 +32,7 @@ var package = Package(
.process("Resources"),
],
plugins: [
.plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin"),
.plugin(name: "SwiftGenPlugin"),
]
),
.target(
Expand All @@ -57,11 +56,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") }

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
)
}
}
}

0 comments on commit 471c982

Please sign in to comment.