Skip to content

Commit

Permalink
Fix SwiftGen Plugin high CPU usage issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pchmelar committed Sep 8, 2022
1 parent f2d0b5d commit c4ed67c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,6 @@
"revision" : "b8230909dedc640294d7324d37f4c91ad3dcf177",
"version" : "1.20.1"
}
},
{
"identity" : "swiftgenplugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SwiftGen/SwiftGenPlugin",
"state" : {
"revision" : "879b85a470cacd70c19e22eb7e11a3aed66f4068",
"version" : "6.6.2"
}
}
],
"version" : 2
Expand Down
17 changes: 14 additions & 3 deletions ios/PresentationLayer/UIToolkit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "Utilities", path: "../DomainLayer/Utilities"),
.package(url: "https://github.com/SwiftGen/SwiftGenPlugin", .upToNextMajor(from: "6.6.0"))
.package(name: "Utilities", path: "../DomainLayer/Utilities")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -34,8 +33,20 @@ let package = Package(
"swiftgen.yml"
],
plugins: [
.plugin(name: "SwiftGenPlugin", package: "SwiftGenPlugin")
.plugin(name: "SwiftGenPlugin")
]
),
.plugin(
name: "SwiftGenPlugin",
capability: .buildTool(),
dependencies: [
.target(name: "swiftgen")
]
),
.binaryTarget(
name: "swiftgen",
url: "https://github.com/SwiftGen/SwiftGen/releases/download/6.6.2/swiftgen-6.6.2.artifactbundle.zip",
checksum: "7586363e24edcf18c2da3ef90f379e9559c1453f48ef5e8fbc0b818fbbc3a045"
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by Petr Chmelar on 08.09.2022
// Copyright © 2022 Matee. All rights reserved.
//

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 c4ed67c

Please sign in to comment.