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

Fix SwiftGen Plugin high CPU usage issue #46

Merged
merged 1 commit into from
Sep 8, 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 @@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there two configurations?

.map { $0.appending("swiftgen.yml") }

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you need to filter configuration locations

.filter { FileManager.default.fileExists(atPath: $0.string) }

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