Skip to content

Commit cd7758e

Browse files
committed
[SwiftRefactor] PackageManifest: Replace custom types with a simple String
All of these types are simple placeholders already with one exception `RelativePath` which used to differentiate path separators on Windows and other platforms, which is not strictly necessary any longer.
1 parent de9afa3 commit cd7758e

File tree

9 files changed

+36
-144
lines changed

9 files changed

+36
-144
lines changed

Sources/SwiftRefactor/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ add_swift_syntax_library(SwiftRefactor
2323
RemoveSeparatorsFromIntegerLiteral.swift
2424
SyntaxUtils.swift
2525

26-
PackageManifest/AbsolutePath.swift
2726
PackageManifest/AddPackageDependency.swift
2827
PackageManifest/AddPackageTarget.swift
2928
PackageManifest/AddPluginUsage.swift
@@ -34,12 +33,9 @@ add_swift_syntax_library(SwiftRefactor
3433
PackageManifest/ManifestSyntaxRepresentable.swift
3534
PackageManifest/PackageDependency.swift
3635
PackageManifest/PackageEdit.swift
37-
PackageManifest/PackageIdentity.swift
3836
PackageManifest/PackageTarget.swift
3937
PackageManifest/ProductDescription.swift
40-
PackageManifest/RelativePath.swift
4138
PackageManifest/SemanticVersion.swift
42-
PackageManifest/SourceControlURL.swift
4339
PackageManifest/StringUtils.swift
4440
PackageManifest/SyntaxEditUtils.swift
4541
)

Sources/SwiftRefactor/PackageManifest/AbsolutePath.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/SwiftRefactor/PackageManifest/AddPackageTarget.swift

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
121121
)
122122
}
123123

124-
let outerPath = RelativePath(outerDirectory)
124+
let outerPath = outerDirectory
125125

126126
/// The set of auxiliary files this refactoring will create.
127127
var auxiliaryFiles: AuxiliaryFiles = []
@@ -186,14 +186,12 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
186186
/// Add the primary source file for a target to the list of auxiliary
187187
/// source files.
188188
fileprivate static func addPrimarySourceFile(
189-
outerPath: RelativePath,
189+
outerPath: String,
190190
target: PackageTarget,
191191
configuration: Configuration,
192192
to auxiliaryFiles: inout AuxiliaryFiles
193193
) {
194-
let sourceFilePath = outerPath.appending(
195-
components: [target.name, "\(target.name).swift"]
196-
)
194+
let sourceFilePath = "\(outerPath)/\(target.name)/\(target.name).swift"
197195

198196
// Introduce imports for each of the dependencies that were specified.
199197
var importModuleNames = target.dependencies.map {
@@ -299,14 +297,12 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
299297
/// Add a file that introduces the main entrypoint and provided macros
300298
/// for a macro target.
301299
fileprivate static func addProvidedMacrosSourceFile(
302-
outerPath: RelativePath,
300+
outerPath: String,
303301
target: PackageTarget,
304302
to auxiliaryFiles: inout AuxiliaryFiles
305303
) {
306304
auxiliaryFiles.addSourceFile(
307-
path: outerPath.appending(
308-
components: [target.name, "ProvidedMacros.swift"]
309-
),
305+
path: "\(outerPath)/\(target.name)/ProvidedMacros.swift",
310306
sourceCode: """
311307
import SwiftCompilerPlugin
312308
@@ -335,12 +331,12 @@ fileprivate extension PackageTarget.Dependency {
335331

336332
/// The array of auxiliary files that can be added by a package editing
337333
/// operation.
338-
fileprivate typealias AuxiliaryFiles = [(RelativePath, SourceFileSyntax)]
334+
fileprivate typealias AuxiliaryFiles = [(String, SourceFileSyntax)]
339335

340336
fileprivate extension AuxiliaryFiles {
341337
/// Add a source file to the list of auxiliary files.
342338
mutating func addSourceFile(
343-
path: RelativePath,
339+
path: String,
344340
sourceCode: SourceFileSyntax
345341
) {
346342
self.append((path, sourceCode))
@@ -357,8 +353,8 @@ fileprivate let macroTargetDependencies: [PackageTarget.Dependency] = [
357353
/// The package dependency for swift-syntax, for use in macros.
358354
fileprivate extension PackageDependency {
359355
/// Source control URL for the swift-syntax package.
360-
static var swiftSyntaxURL: SourceControlURL {
361-
.init("https://github.com/swiftlang/swift-syntax.git")
356+
static var swiftSyntaxURL: String {
357+
"https://github.com/swiftlang/swift-syntax.git"
362358
}
363359

364360
/// Package dependency on the swift-syntax package.
@@ -367,7 +363,7 @@ fileprivate extension PackageDependency {
367363
) -> PackageDependency {
368364
return .sourceControl(
369365
.init(
370-
identity: PackageIdentity("swift-syntax"),
366+
identity: "swift-syntax",
371367
location: .remote(swiftSyntaxURL),
372368
requirement: .rangeFrom(version)
373369
)

Sources/SwiftRefactor/PackageManifest/PackageDependency.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public enum PackageDependency: Sendable {
2222
case registry(Registry)
2323

2424
public struct FileSystem: Sendable {
25-
public let identity: PackageIdentity
25+
public let identity: String
2626
public let nameForTargetDependencyResolutionOnly: String?
27-
public let path: AbsolutePath
27+
public let path: String
2828
}
2929

3030
public struct SourceControl: Sendable {
31-
public let identity: PackageIdentity
31+
public let identity: String
3232
public let location: Location
3333
public let requirement: Requirement
3434

35-
public init(identity: PackageIdentity, location: Location, requirement: Requirement) {
35+
public init(identity: String, location: Location, requirement: Requirement) {
3636
self.identity = identity
3737
self.location = location
3838
self.requirement = requirement
@@ -47,13 +47,13 @@ public enum PackageDependency: Sendable {
4747
}
4848

4949
public enum Location: Sendable {
50-
case local(AbsolutePath)
51-
case remote(SourceControlURL)
50+
case local(String)
51+
case remote(String)
5252
}
5353
}
5454

5555
public struct Registry: Sendable {
56-
public let identity: PackageIdentity
56+
public let identity: String
5757
public let requirement: Requirement
5858

5959
/// The dependency requirement.

Sources/SwiftRefactor/PackageManifest/PackageEdit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public struct PackageEdit {
1919
public var manifestEdits: [SourceEdit] = []
2020

2121
/// Auxiliary files to write.
22-
public var auxiliaryFiles: [(RelativePath, SourceFileSyntax)] = []
22+
public var auxiliaryFiles: [(String, SourceFileSyntax)] = []
2323
}

Sources/SwiftRefactor/PackageManifest/PackageIdentity.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/SwiftRefactor/PackageManifest/RelativePath.swift

Lines changed: 0 additions & 35 deletions
This file was deleted.

Sources/SwiftRefactor/PackageManifest/SourceControlURL.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)