@@ -18,7 +18,7 @@ import SwiftSyntaxBuilder
18
18
import struct TSCUtility. Version
19
19
20
20
/// Add a target to a manifest's source code.
21
- public struct AddTarget {
21
+ public enum AddTarget {
22
22
/// The set of argument labels that can occur after the "targets"
23
23
/// argument in the Package initializers.
24
24
///
@@ -27,7 +27,7 @@ public struct AddTarget {
27
27
private static let argumentLabelsAfterTargets : Set < String > = [
28
28
" swiftLanguageVersions " ,
29
29
" cLanguageStandard " ,
30
- " cxxLanguageStandard "
30
+ " cxxLanguageStandard " ,
31
31
]
32
32
33
33
/// The kind of test harness to use. This isn't part of the manifest
@@ -85,7 +85,7 @@ public struct AddTarget {
85
85
target. dependencies. append ( contentsOf: macroTargetDependencies)
86
86
87
87
default :
88
- break ;
88
+ break
89
89
}
90
90
91
91
var newPackageCall = try packageCall. appendingToArrayArgument (
@@ -103,7 +103,7 @@ public struct AddTarget {
103
103
guard let outerDirectory else {
104
104
return PackageEditResult (
105
105
manifestEdits: [
106
- . replace( packageCall, with: newPackageCall. description)
106
+ . replace( packageCall, with: newPackageCall. description) ,
107
107
]
108
108
)
109
109
}
@@ -114,7 +114,7 @@ public struct AddTarget {
114
114
var auxiliaryFiles : AuxiliaryFiles = [ ]
115
115
116
116
// Add the primary source file. Every target type has this.
117
- addPrimarySourceFile (
117
+ self . addPrimarySourceFile (
118
118
outerPath: outerPath,
119
119
target: target,
120
120
configuration: configuration,
@@ -125,7 +125,7 @@ public struct AddTarget {
125
125
var extraManifestEdits : [ SourceEdit ] = [ ]
126
126
switch target. type {
127
127
case . macro:
128
- addProvidedMacrosSourceFile (
128
+ self . addProvidedMacrosSourceFile (
129
129
outerPath: outerPath,
130
130
target: target,
131
131
to: & auxiliaryFiles
@@ -135,7 +135,7 @@ public struct AddTarget {
135
135
newPackageCall = try AddPackageDependency
136
136
. addPackageDependencyLocal (
137
137
. swiftSyntax(
138
- configuration: installedSwiftPMConfiguration
138
+ configuration: installedSwiftPMConfiguration
139
139
) ,
140
140
to: newPackageCall
141
141
)
@@ -149,7 +149,7 @@ public struct AddTarget {
149
149
. positionAfterSkippingLeadingTrivia
150
150
extraManifestEdits. append (
151
151
SourceEdit (
152
- range: insertPos..< insertPos,
152
+ range: insertPos ..< insertPos,
153
153
replacement: newImport
154
154
)
155
155
)
@@ -158,12 +158,12 @@ public struct AddTarget {
158
158
}
159
159
}
160
160
161
- default : break ;
161
+ default : break
162
162
}
163
163
164
164
return PackageEditResult (
165
165
manifestEdits: [
166
- . replace( packageCall, with: newPackageCall. description)
166
+ . replace( packageCall, with: newPackageCall. description) ,
167
167
] + extraManifestEdits,
168
168
auxiliaryFiles: auxiliaryFiles
169
169
)
@@ -182,20 +182,18 @@ public struct AddTarget {
182
182
)
183
183
184
184
// Introduce imports for each of the dependencies that were specified.
185
- var importModuleNames = target. dependencies. map {
186
- $0. name
187
- }
185
+ var importModuleNames = target. dependencies. map ( \. name)
188
186
189
187
// Add appropriate test module dependencies.
190
188
if target. type == . test {
191
189
switch configuration. testHarness {
192
- case . none:
190
+ case . none:
193
191
break
194
192
195
193
case . xctest:
196
194
importModuleNames. append ( " XCTest " )
197
195
198
- case . swiftTesting:
196
+ case . swiftTesting:
199
197
importModuleNames. append ( " Testing " )
200
198
}
201
199
}
@@ -306,25 +304,25 @@ public struct AddTarget {
306
304
}
307
305
}
308
306
309
- fileprivate extension TargetDescription . Dependency {
307
+ extension TargetDescription . Dependency {
310
308
/// Retrieve the name of the dependency
311
- var name : String {
309
+ fileprivate var name : String {
312
310
switch self {
313
311
case . target( name: let name, condition: _) ,
314
- . byName( name: let name, condition: _) ,
315
- . product( name: let name, package : _, moduleAliases: _, condition: _) :
312
+ . byName( name: let name, condition: _) ,
313
+ . product( name: let name, package : _, moduleAliases: _, condition: _) :
316
314
name
317
315
}
318
316
}
319
317
}
320
318
321
319
/// The array of auxiliary files that can be added by a package editing
322
320
/// operation.
323
- fileprivate typealias AuxiliaryFiles = [ ( RelativePath , SourceFileSyntax ) ]
321
+ private typealias AuxiliaryFiles = [ ( RelativePath , SourceFileSyntax ) ]
324
322
325
- fileprivate extension AuxiliaryFiles {
323
+ extension AuxiliaryFiles {
326
324
/// Add a source file to the list of auxiliary files.
327
- mutating func addSourceFile(
325
+ fileprivate mutating func addSourceFile(
328
326
path: RelativePath ,
329
327
sourceCode: SourceFileSyntax
330
328
) {
@@ -334,45 +332,42 @@ fileprivate extension AuxiliaryFiles {
334
332
335
333
/// The set of dependencies we need to introduce to a newly-created macro
336
334
/// target.
337
- fileprivate let macroTargetDependencies : [ TargetDescription . Dependency ] = [
335
+ private let macroTargetDependencies : [ TargetDescription . Dependency ] = [
338
336
. product( name: " SwiftCompilerPlugin " , package : " swift-syntax " ) ,
339
337
. product( name: " SwiftSyntaxMacros " , package : " swift-syntax " ) ,
340
338
]
341
339
342
340
/// The package dependency for swift-syntax, for use in macros.
343
- fileprivate extension PackageDependency {
341
+ extension MappablePackageDependency . Kind {
344
342
/// Source control URL for the swift-syntax package.
345
- static var swiftSyntaxURL : SourceControlURL {
343
+ fileprivate static var swiftSyntaxURL : SourceControlURL {
346
344
" https://github.com/swiftlang/swift-syntax.git "
347
345
}
348
346
349
347
/// Package dependency on the swift-syntax package.
350
- static func swiftSyntax(
351
- configuration: InstalledSwiftPMConfiguration
352
- ) -> PackageDependency {
348
+ fileprivate static func swiftSyntax(
349
+ configuration: InstalledSwiftPMConfiguration
350
+ ) -> MappablePackageDependency . Kind {
353
351
let swiftSyntaxVersionDefault = configuration
354
352
. swiftSyntaxVersionForMacroTemplate
355
353
let swiftSyntaxVersion = Version ( swiftSyntaxVersionDefault. description) !
356
354
357
355
return . sourceControl(
358
- identity: PackageIdentity ( url: swiftSyntaxURL) ,
359
- nameForTargetDependencyResolutionOnly: nil ,
360
- location: . remote( swiftSyntaxURL) ,
361
- requirement: . range( . upToNextMajor( from: swiftSyntaxVersion) ) ,
362
- productFilter: . everything,
363
- traits: [ ]
356
+ name: nil ,
357
+ location: self . swiftSyntaxURL. absoluteString,
358
+ requirement: . range( . upToNextMajor( from: swiftSyntaxVersion) )
364
359
)
365
360
}
366
361
}
367
362
368
- fileprivate extension TargetDescription {
369
- var sanitizedName : String {
370
- name
363
+ extension TargetDescription {
364
+ fileprivate var sanitizedName : String {
365
+ self . name
371
366
. spm_mangledToC99ExtendedIdentifier ( )
372
367
. localizedFirstWordCapitalized ( )
373
368
}
374
369
}
375
370
376
- fileprivate extension String {
377
- func localizedFirstWordCapitalized( ) -> String { prefix ( 1 ) . localizedCapitalized + dropFirst( ) }
371
+ extension String {
372
+ fileprivate func localizedFirstWordCapitalized( ) -> String { prefix ( 1 ) . localizedCapitalized + dropFirst( ) }
378
373
}
0 commit comments