Skip to content

Commit

Permalink
Merge pull request #175 from scribd/stephane/objc_container_names
Browse files Browse the repository at this point in the history
Add new configuration parameter `project_name`.
  • Loading branch information
Stephane Magne authored Sep 22, 2022
2 parents c52da97 + 81bf92e commit b289f08
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 42 deletions.
44 changes: 13 additions & 31 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,12 @@
"version": "0.9.1"
}
},
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "7cd2f8cacc4d22f21bc0b2309c3b18acf7957b66",
"version": "1.2.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "c228db5d2ad1b01ebc84435e823e6cca4e3db98b",
"version": "1.2.0"
}
},
{
"package": "Meta",
"repositoryURL": "https://github.com/scribd/Meta.git",
"state": {
"branch": "master",
"revision": "a955d8dfbaaf6416922967d190580ea5a4571288",
"revision": "ac1103cdc06d31cee65d8b802f21a45e00271a18",
"version": null
}
},
Expand All @@ -51,8 +33,8 @@
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "b02b00b30b6353632aa4a5fb6124f8147f7140c0",
"version": "8.0.5"
"revision": "7a46a5fc86cb917f69e3daf79fcb045283d8f008",
"version": "8.1.2"
}
},
{
Expand All @@ -69,26 +51,26 @@
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
"version": "2.2.0"
"revision": "09b3becb37cb2163919a3842a4c5fa6ec7130792",
"version": "2.2.1"
}
},
{
"package": "Rainbow",
"repositoryURL": "https://github.com/onevcat/Rainbow",
"state": {
"branch": null,
"revision": "9c52c1952e9b2305d4507cf473392ac2d7c9b155",
"version": "3.1.5"
"revision": "626c3d4b6b55354b4af3aa309f998fae9b31a3d9",
"version": "3.2.0"
}
},
{
"package": "ShellOut",
"repositoryURL": "https://github.com/JohnSundell/ShellOut.git",
"state": {
"branch": null,
"revision": "4ebf25863deb9c3c02696704fc3d39736183f258",
"version": "2.2.1"
"revision": "e1577acf2b6e90086d01a6d5e2b8efdaae033568",
"version": "2.3.0"
}
},
{
Expand All @@ -105,17 +87,17 @@
"repositoryURL": "https://github.com/kylef/Spectre.git",
"state": {
"branch": null,
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
"version": "0.9.0"
"revision": "f79d4ecbf8bc4e1579fbd86c3e1d652fb6876c53",
"version": "0.9.2"
}
},
{
"package": "SWXMLHash",
"repositoryURL": "https://github.com/drmohundro/SWXMLHash.git",
"state": {
"branch": null,
"revision": "a4931e5c3bafbedeb1601d3bb76bbe835c6d475a",
"version": "5.0.1"
"revision": "9183170d20857753d4f331b0ca63f73c60764bf3",
"version": "5.0.2"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion Sample/.api.weaver.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
project_name: API
main_output_path: API/Generated
input_paths:
- API
ignored_paths:
- API/Generated
- API/Generated
4 changes: 3 additions & 1 deletion Sample/.sample.weaver.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
project_name: Sample
platform: iOS
main_output_path: Sample/Generated
input_paths:
- Sample
ignored_paths:
- Sample/Generated
- Sample/Generated
2 changes: 1 addition & 1 deletion Sample/API/Generated/Weaver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import UIKit

// swiftlint:disable all
/// This file is generated by Weaver 1.1.2
/// This file is generated by Weaver 1.1.3
/// DO NOT EDIT!

final class MainDependencyContainer {
Expand Down
5 changes: 3 additions & 2 deletions Sample/Sample/Generated/Weaver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import Foundation
import UIKit

// swiftlint:disable all
/// This file is generated by Weaver 1.1.2
/// This file is generated by Weaver 1.1.3
/// DO NOT EDIT!

@objc final class MainDependencyContainer: NSObject {
@objc(SampleIOSMainDependencyContainer)
final class MainDependencyContainer: NSObject {

private let provider: Provider

Expand Down
33 changes: 29 additions & 4 deletions Sources/WeaverCodeGen/SwiftGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public final class SwiftGenerator {

private let testableImports: [String]?

private let projectName: String?

private let platform: Platform?

private let version: String

private let swiftlintDisableAll: Bool
Expand All @@ -27,13 +31,17 @@ public final class SwiftGenerator {

public init(dependencyGraph: DependencyGraph,
inspector: Inspector,
projectName: String?,
platform: Platform?,
version: String,
testableImports: [String]?,
swiftlintDisableAll: Bool,
importFilter: @escaping ImportFilter) throws {

self.dependencyGraph = dependencyGraph
self.inspector = inspector
self.projectName = projectName
self.platform = platform
self.version = version
self.testableImports = testableImports?.filter(importFilter)
self.swiftlintDisableAll = swiftlintDisableAll
Expand All @@ -45,9 +53,22 @@ public final class SwiftGenerator {
if let file = _file {
return file
}

let objcPrefix: String?
if let projectName = projectName {
if let platform = platform {
objcPrefix = "\(projectName.typeCase)\(platform.rawValue.typeCase)"
} else {
objcPrefix = "\(projectName.typeCase)"
}
} else {
objcPrefix = nil
}

let file = try MetaWeaverFile(
dependencyGraph,
inspector,
objcPrefix,
version,
testableImports,
swiftlintDisableAll,
Expand Down Expand Up @@ -179,7 +200,9 @@ private final class MetaWeaverFile {
private let dependencyGraph: DependencyGraph

private let inspector: Inspector


private let objcPrefix: String?

private let version: String

private let testableImports: [String]?
Expand Down Expand Up @@ -209,13 +232,15 @@ private final class MetaWeaverFile {

init(_ dependencyGraph: DependencyGraph,
_ inspector: Inspector,
_ objcPrefix: String?,
_ version: String,
_ testableImports: [String]?,
_ swiftlintDisableAll: Bool,
_ importFilter: @escaping SwiftGenerator.ImportFilter) throws {

self.dependencyGraph = dependencyGraph
self.inspector = inspector
self.objcPrefix = objcPrefix
self.version = version
self.testableImports = testableImports
self.swiftlintDisableAll = swiftlintDisableAll
Expand Down Expand Up @@ -318,10 +343,10 @@ private final class MetaWeaverFile {
// MARK: - MainDependencyContainer

private extension MetaWeaverFile {

func mainDependencyContainer() throws -> Type {
return Type(identifier: .mainDependencyContainer)
.with(objc: doesSupportObjc)
.with(objc: doesSupportObjc, prefix: objcPrefix)
.adding(inheritedType: doesSupportObjc ? .nsObject : nil)
.adding(member: EmptyLine())
.adding(member: Property(variable: Variable(name: "provider").with(immutable: true).with(type: .provider)).with(accessLevel: .private))
Expand Down Expand Up @@ -950,7 +975,7 @@ static func _pushDynamicResolver<Resolver>(_ resolver: Resolver) {
builderReference = .named(customBuilder) | .call(Tuple()
.adding(parameter: TupleParameter(value:
(containsAmbiguousDeclarations ? Variable.__self.reference + Variable.proxySelf.reference : Reference.named("_inputContainer")) |
.as | target.type.inputDependencyResolverTypeID.reference
.as(.strict(target.type.inputDependencyResolverTypeID))
))
)
shouldUnwrapResolverReference = containsAmbiguousDeclarations
Expand Down
8 changes: 7 additions & 1 deletion Sources/WeaverCommand/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Darwin
import PathKit
import Rainbow

private let version = "1.1.2"
private let version = "1.1.3"

// MARK: - Linker

Expand Down Expand Up @@ -101,6 +101,7 @@ private extension Platform {
// MARK: - Parameters

private enum Parameters {
static let projectName = Option<String?>("project-name", default: nil, description: "Project's name.")
static let projectPath = Option<Path?>("project-path", default: nil, description: "Project's directory.")
static let configPath = Option<Path?>("config-path", default: nil, description: "Configuration path.")
static let mainOutputPath = Option<Path?>("main-output-path", default: nil, description: "Where the main swift files will be generated.")
Expand All @@ -124,6 +125,7 @@ public let weaverCommand = Group {

$0.command(
"swift",
Parameters.projectName,
Parameters.projectPath,
Parameters.configPath,
Parameters.mainOutputPath,
Expand All @@ -139,6 +141,7 @@ public let weaverCommand = Group {
Parameters.includedImports,
Parameters.excludedImports)
{
projectName,
projectPath,
configPath,
mainOutputPath,
Expand All @@ -158,6 +161,7 @@ public let weaverCommand = Group {
configPath: configPath,
inputPathStrings: inputPaths.isEmpty ? nil : inputPaths,
ignoredPathStrings: ignoredPaths.isEmpty ? nil : ignoredPaths,
projectName: projectName,
projectPath: projectPath,
mainOutputPath: mainOutputPath,
testsOutputPath: testsOutputPath,
Expand Down Expand Up @@ -208,6 +212,8 @@ public let weaverCommand = Group {
let generator = try SwiftGenerator(
dependencyGraph: dependencyGraph,
inspector: inspector,
projectName: projectName ?? configuration.projectName,
platform: Platform(platform) ?? configuration.platform,
version: version,
testableImports: configuration.testableImports,
swiftlintDisableAll: configuration.swiftlintDisableAll,
Expand Down
10 changes: 9 additions & 1 deletion Sources/WeaverCommand/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import WeaverCodeGen
// MARK: - Configuration

struct Configuration {


let projectName: String?
let projectPath: Path
let mainOutputPath: Path
let testsOutputPath: Path
Expand All @@ -31,6 +32,7 @@ struct Configuration {

private init(inputPathStrings: [String]?,
ignoredPathStrings: [String]?,
projectName: String?,
projectPath: Path?,
mainOutputPath: Path?,
testsOutputPath: Path?,
Expand All @@ -46,6 +48,7 @@ struct Configuration {
self.inputPathStrings = inputPathStrings ?? Defaults.inputPathStrings
self.ignoredPathStrings = ignoredPathStrings ?? []

self.projectName = projectName
let projectPath = projectPath ?? Defaults.projectPath
self.projectPath = projectPath

Expand All @@ -69,6 +72,7 @@ struct Configuration {
init(configPath: Path? = nil,
inputPathStrings: [String]? = nil,
ignoredPathStrings: [String]? = nil,
projectName: String? = nil,
projectPath: Path? = nil,
mainOutputPath: Path? = nil,
testsOutputPath: Path? = nil,
Expand Down Expand Up @@ -97,6 +101,7 @@ struct Configuration {
configuration = Configuration(
inputPathStrings: inputPathStrings,
ignoredPathStrings: ignoredPathStrings,
projectName: projectName,
projectPath: projectPath,
mainOutputPath: mainOutputPath,
testsOutputPath: testsOutputPath,
Expand All @@ -113,6 +118,7 @@ struct Configuration {

self.inputPathStrings = inputPathStrings ?? configuration.inputPathStrings
self.ignoredPathStrings = ignoredPathStrings ?? configuration.ignoredPathStrings
self.projectName = projectName ?? configuration.projectName
self.projectPath = projectPath
self.mainOutputPath = mainOutputPath ?? configuration.mainOutputPath
self.testsOutputPath = testsOutputPath ?? configuration.testsOutputPath
Expand Down Expand Up @@ -181,6 +187,7 @@ extension Configuration {
extension Configuration: Decodable {

private enum Keys: String, CodingKey {
case projectName = "project_name"
case projectPath = "project_path"
case mainOutputPath = "main_output_path"
case testsOutputPath = "tests_output_path"
Expand Down Expand Up @@ -208,6 +215,7 @@ extension Configuration: Decodable {
self.init(
inputPathStrings: try container.decodeIfPresent([String].self, forKey: .inputPaths),
ignoredPathStrings: try container.decodeIfPresent([String].self, forKey: .ignoredPaths),
projectName: try container.decodeIfPresent(String.self, forKey: .projectName),
projectPath: nil,
mainOutputPath: try container.decodeIfPresent(Path.self, forKey: .mainOutputPath),
testsOutputPath: try container.decodeIfPresent(Path.self, forKey: .testsOutputPath),
Expand Down

0 comments on commit b289f08

Please sign in to comment.