Skip to content

Commit b289f08

Browse files
author
Stephane Magne
authored
Merge pull request #175 from scribd/stephane/objc_container_names
Add new configuration parameter `project_name`.
2 parents c52da97 + 81bf92e commit b289f08

File tree

8 files changed

+67
-42
lines changed

8 files changed

+67
-42
lines changed

Package.resolved

+13-31
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,12 @@
1919
"version": "0.9.1"
2020
}
2121
},
22-
{
23-
"package": "CwlCatchException",
24-
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
25-
"state": {
26-
"branch": null,
27-
"revision": "7cd2f8cacc4d22f21bc0b2309c3b18acf7957b66",
28-
"version": "1.2.0"
29-
}
30-
},
31-
{
32-
"package": "CwlPreconditionTesting",
33-
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
34-
"state": {
35-
"branch": null,
36-
"revision": "c228db5d2ad1b01ebc84435e823e6cca4e3db98b",
37-
"version": "1.2.0"
38-
}
39-
},
4022
{
4123
"package": "Meta",
4224
"repositoryURL": "https://github.com/scribd/Meta.git",
4325
"state": {
4426
"branch": "master",
45-
"revision": "a955d8dfbaaf6416922967d190580ea5a4571288",
27+
"revision": "ac1103cdc06d31cee65d8b802f21a45e00271a18",
4628
"version": null
4729
}
4830
},
@@ -51,8 +33,8 @@
5133
"repositoryURL": "https://github.com/Quick/Nimble.git",
5234
"state": {
5335
"branch": null,
54-
"revision": "b02b00b30b6353632aa4a5fb6124f8147f7140c0",
55-
"version": "8.0.5"
36+
"revision": "7a46a5fc86cb917f69e3daf79fcb045283d8f008",
37+
"version": "8.1.2"
5638
}
5739
},
5840
{
@@ -69,26 +51,26 @@
6951
"repositoryURL": "https://github.com/Quick/Quick.git",
7052
"state": {
7153
"branch": null,
72-
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
73-
"version": "2.2.0"
54+
"revision": "09b3becb37cb2163919a3842a4c5fa6ec7130792",
55+
"version": "2.2.1"
7456
}
7557
},
7658
{
7759
"package": "Rainbow",
7860
"repositoryURL": "https://github.com/onevcat/Rainbow",
7961
"state": {
8062
"branch": null,
81-
"revision": "9c52c1952e9b2305d4507cf473392ac2d7c9b155",
82-
"version": "3.1.5"
63+
"revision": "626c3d4b6b55354b4af3aa309f998fae9b31a3d9",
64+
"version": "3.2.0"
8365
}
8466
},
8567
{
8668
"package": "ShellOut",
8769
"repositoryURL": "https://github.com/JohnSundell/ShellOut.git",
8870
"state": {
8971
"branch": null,
90-
"revision": "4ebf25863deb9c3c02696704fc3d39736183f258",
91-
"version": "2.2.1"
72+
"revision": "e1577acf2b6e90086d01a6d5e2b8efdaae033568",
73+
"version": "2.3.0"
9274
}
9375
},
9476
{
@@ -105,17 +87,17 @@
10587
"repositoryURL": "https://github.com/kylef/Spectre.git",
10688
"state": {
10789
"branch": null,
108-
"revision": "f14ff47f45642aa5703900980b014c2e9394b6e5",
109-
"version": "0.9.0"
90+
"revision": "f79d4ecbf8bc4e1579fbd86c3e1d652fb6876c53",
91+
"version": "0.9.2"
11092
}
11193
},
11294
{
11395
"package": "SWXMLHash",
11496
"repositoryURL": "https://github.com/drmohundro/SWXMLHash.git",
11597
"state": {
11698
"branch": null,
117-
"revision": "a4931e5c3bafbedeb1601d3bb76bbe835c6d475a",
118-
"version": "5.0.1"
99+
"revision": "9183170d20857753d4f331b0ca63f73c60764bf3",
100+
"version": "5.0.2"
119101
}
120102
},
121103
{

Sample/.api.weaver.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
project_name: API
12
main_output_path: API/Generated
23
input_paths:
34
- API
45
ignored_paths:
5-
- API/Generated
6+
- API/Generated

Sample/.sample.weaver.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
project_name: Sample
2+
platform: iOS
13
main_output_path: Sample/Generated
24
input_paths:
35
- Sample
46
ignored_paths:
5-
- Sample/Generated
7+
- Sample/Generated

Sample/API/Generated/Weaver.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import UIKit
33

44
// swiftlint:disable all
5-
/// This file is generated by Weaver 1.1.2
5+
/// This file is generated by Weaver 1.1.3
66
/// DO NOT EDIT!
77

88
final class MainDependencyContainer {

Sample/Sample/Generated/Weaver.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import Foundation
33
import UIKit
44

55
// swiftlint:disable all
6-
/// This file is generated by Weaver 1.1.2
6+
/// This file is generated by Weaver 1.1.3
77
/// DO NOT EDIT!
88

9-
@objc final class MainDependencyContainer: NSObject {
9+
@objc(SampleIOSMainDependencyContainer)
10+
final class MainDependencyContainer: NSObject {
1011

1112
private let provider: Provider
1213

Sources/WeaverCodeGen/SwiftGenerator.swift

+29-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public final class SwiftGenerator {
1818

1919
private let testableImports: [String]?
2020

21+
private let projectName: String?
22+
23+
private let platform: Platform?
24+
2125
private let version: String
2226

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

2832
public init(dependencyGraph: DependencyGraph,
2933
inspector: Inspector,
34+
projectName: String?,
35+
platform: Platform?,
3036
version: String,
3137
testableImports: [String]?,
3238
swiftlintDisableAll: Bool,
3339
importFilter: @escaping ImportFilter) throws {
3440

3541
self.dependencyGraph = dependencyGraph
3642
self.inspector = inspector
43+
self.projectName = projectName
44+
self.platform = platform
3745
self.version = version
3846
self.testableImports = testableImports?.filter(importFilter)
3947
self.swiftlintDisableAll = swiftlintDisableAll
@@ -45,9 +53,22 @@ public final class SwiftGenerator {
4553
if let file = _file {
4654
return file
4755
}
56+
57+
let objcPrefix: String?
58+
if let projectName = projectName {
59+
if let platform = platform {
60+
objcPrefix = "\(projectName.typeCase)\(platform.rawValue.typeCase)"
61+
} else {
62+
objcPrefix = "\(projectName.typeCase)"
63+
}
64+
} else {
65+
objcPrefix = nil
66+
}
67+
4868
let file = try MetaWeaverFile(
4969
dependencyGraph,
5070
inspector,
71+
objcPrefix,
5172
version,
5273
testableImports,
5374
swiftlintDisableAll,
@@ -179,7 +200,9 @@ private final class MetaWeaverFile {
179200
private let dependencyGraph: DependencyGraph
180201

181202
private let inspector: Inspector
182-
203+
204+
private let objcPrefix: String?
205+
183206
private let version: String
184207

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

210233
init(_ dependencyGraph: DependencyGraph,
211234
_ inspector: Inspector,
235+
_ objcPrefix: String?,
212236
_ version: String,
213237
_ testableImports: [String]?,
214238
_ swiftlintDisableAll: Bool,
215239
_ importFilter: @escaping SwiftGenerator.ImportFilter) throws {
216240

217241
self.dependencyGraph = dependencyGraph
218242
self.inspector = inspector
243+
self.objcPrefix = objcPrefix
219244
self.version = version
220245
self.testableImports = testableImports
221246
self.swiftlintDisableAll = swiftlintDisableAll
@@ -318,10 +343,10 @@ private final class MetaWeaverFile {
318343
// MARK: - MainDependencyContainer
319344

320345
private extension MetaWeaverFile {
321-
346+
322347
func mainDependencyContainer() throws -> Type {
323348
return Type(identifier: .mainDependencyContainer)
324-
.with(objc: doesSupportObjc)
349+
.with(objc: doesSupportObjc, prefix: objcPrefix)
325350
.adding(inheritedType: doesSupportObjc ? .nsObject : nil)
326351
.adding(member: EmptyLine())
327352
.adding(member: Property(variable: Variable(name: "provider").with(immutable: true).with(type: .provider)).with(accessLevel: .private))
@@ -950,7 +975,7 @@ static func _pushDynamicResolver<Resolver>(_ resolver: Resolver) {
950975
builderReference = .named(customBuilder) | .call(Tuple()
951976
.adding(parameter: TupleParameter(value:
952977
(containsAmbiguousDeclarations ? Variable.__self.reference + Variable.proxySelf.reference : Reference.named("_inputContainer")) |
953-
.as | target.type.inputDependencyResolverTypeID.reference
978+
.as(.strict(target.type.inputDependencyResolverTypeID))
954979
))
955980
)
956981
shouldUnwrapResolverReference = containsAmbiguousDeclarations

Sources/WeaverCommand/Command.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Darwin
1313
import PathKit
1414
import Rainbow
1515

16-
private let version = "1.1.2"
16+
private let version = "1.1.3"
1717

1818
// MARK: - Linker
1919

@@ -101,6 +101,7 @@ private extension Platform {
101101
// MARK: - Parameters
102102

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

125126
$0.command(
126127
"swift",
128+
Parameters.projectName,
127129
Parameters.projectPath,
128130
Parameters.configPath,
129131
Parameters.mainOutputPath,
@@ -139,6 +141,7 @@ public let weaverCommand = Group {
139141
Parameters.includedImports,
140142
Parameters.excludedImports)
141143
{
144+
projectName,
142145
projectPath,
143146
configPath,
144147
mainOutputPath,
@@ -158,6 +161,7 @@ public let weaverCommand = Group {
158161
configPath: configPath,
159162
inputPathStrings: inputPaths.isEmpty ? nil : inputPaths,
160163
ignoredPathStrings: ignoredPaths.isEmpty ? nil : ignoredPaths,
164+
projectName: projectName,
161165
projectPath: projectPath,
162166
mainOutputPath: mainOutputPath,
163167
testsOutputPath: testsOutputPath,
@@ -208,6 +212,8 @@ public let weaverCommand = Group {
208212
let generator = try SwiftGenerator(
209213
dependencyGraph: dependencyGraph,
210214
inspector: inspector,
215+
projectName: projectName ?? configuration.projectName,
216+
platform: Platform(platform) ?? configuration.platform,
211217
version: version,
212218
testableImports: configuration.testableImports,
213219
swiftlintDisableAll: configuration.swiftlintDisableAll,

Sources/WeaverCommand/Configuration.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import WeaverCodeGen
1414
// MARK: - Configuration
1515

1616
struct Configuration {
17-
17+
18+
let projectName: String?
1819
let projectPath: Path
1920
let mainOutputPath: Path
2021
let testsOutputPath: Path
@@ -31,6 +32,7 @@ struct Configuration {
3132

3233
private init(inputPathStrings: [String]?,
3334
ignoredPathStrings: [String]?,
35+
projectName: String?,
3436
projectPath: Path?,
3537
mainOutputPath: Path?,
3638
testsOutputPath: Path?,
@@ -46,6 +48,7 @@ struct Configuration {
4648
self.inputPathStrings = inputPathStrings ?? Defaults.inputPathStrings
4749
self.ignoredPathStrings = ignoredPathStrings ?? []
4850

51+
self.projectName = projectName
4952
let projectPath = projectPath ?? Defaults.projectPath
5053
self.projectPath = projectPath
5154

@@ -69,6 +72,7 @@ struct Configuration {
6972
init(configPath: Path? = nil,
7073
inputPathStrings: [String]? = nil,
7174
ignoredPathStrings: [String]? = nil,
75+
projectName: String? = nil,
7276
projectPath: Path? = nil,
7377
mainOutputPath: Path? = nil,
7478
testsOutputPath: Path? = nil,
@@ -97,6 +101,7 @@ struct Configuration {
97101
configuration = Configuration(
98102
inputPathStrings: inputPathStrings,
99103
ignoredPathStrings: ignoredPathStrings,
104+
projectName: projectName,
100105
projectPath: projectPath,
101106
mainOutputPath: mainOutputPath,
102107
testsOutputPath: testsOutputPath,
@@ -113,6 +118,7 @@ struct Configuration {
113118

114119
self.inputPathStrings = inputPathStrings ?? configuration.inputPathStrings
115120
self.ignoredPathStrings = ignoredPathStrings ?? configuration.ignoredPathStrings
121+
self.projectName = projectName ?? configuration.projectName
116122
self.projectPath = projectPath
117123
self.mainOutputPath = mainOutputPath ?? configuration.mainOutputPath
118124
self.testsOutputPath = testsOutputPath ?? configuration.testsOutputPath
@@ -181,6 +187,7 @@ extension Configuration {
181187
extension Configuration: Decodable {
182188

183189
private enum Keys: String, CodingKey {
190+
case projectName = "project_name"
184191
case projectPath = "project_path"
185192
case mainOutputPath = "main_output_path"
186193
case testsOutputPath = "tests_output_path"
@@ -208,6 +215,7 @@ extension Configuration: Decodable {
208215
self.init(
209216
inputPathStrings: try container.decodeIfPresent([String].self, forKey: .inputPaths),
210217
ignoredPathStrings: try container.decodeIfPresent([String].self, forKey: .ignoredPaths),
218+
projectName: try container.decodeIfPresent(String.self, forKey: .projectName),
211219
projectPath: nil,
212220
mainOutputPath: try container.decodeIfPresent(Path.self, forKey: .mainOutputPath),
213221
testsOutputPath: try container.decodeIfPresent(Path.self, forKey: .testsOutputPath),

0 commit comments

Comments
 (0)