Skip to content

Commit 470575c

Browse files
authored
Merge pull request #542 from abertelrud/remove-implicit-path-creation-from-string-literals
Remove `ExpressibleByStringLiteral` conformance for AbsolutePath and RelativePath
2 parents a949809 + 7f0cc67 commit 470575c

39 files changed

+268
-294
lines changed

Sources/Basic/Path.swift

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,6 @@ public struct AbsolutePath {
206206
}
207207
}
208208

209-
/// Adoption of the ExpressibleByStringLiteral protocol allows literal strings
210-
/// to be implicitly converted to AbsolutePaths.
211-
extension AbsolutePath : ExpressibleByStringLiteral {
212-
public typealias UnicodeScalarLiteralType = StringLiteralType
213-
public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
214-
public init(stringLiteral value: String) {
215-
self.init(value)
216-
}
217-
public init(extendedGraphemeClusterLiteral value: String) {
218-
self.init(stringLiteral: value)
219-
}
220-
public init(unicodeScalarLiteral value: String) {
221-
self.init(stringLiteral: value)
222-
}
223-
}
224-
225-
226209
/// Represents a relative file system path. A relative path never starts with
227210
/// a `/` character, and holds a normalized string representation. As with
228211
/// AbsolutePath, the normalization is strictly syntactic, and does not access
@@ -299,22 +282,6 @@ public struct RelativePath {
299282
}
300283
}
301284

302-
/// Adoption of the ExpressibleByStringLiteral protocol allows literal strings
303-
/// to be implicitly converted to RelativePaths.
304-
extension RelativePath : ExpressibleByStringLiteral {
305-
public typealias UnicodeScalarLiteralType = StringLiteralType
306-
public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType
307-
public init(stringLiteral value: String) {
308-
self.init(value)
309-
}
310-
public init(extendedGraphemeClusterLiteral value: String) {
311-
self.init(stringLiteral: value)
312-
}
313-
public init(unicodeScalarLiteral value: String) {
314-
self.init(stringLiteral: value)
315-
}
316-
}
317-
318285
// Make absolute paths Hashable.
319286
extension AbsolutePath : Hashable {
320287
public var hashValue: Int {

Sources/Build/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protocol ClangModuleCachable {
145145

146146
extension ClangModuleCachable {
147147
func moduleCacheDir(prefix: AbsolutePath) -> AbsolutePath {
148-
return prefix.appending("ModuleCache")
148+
return prefix.appending(component: "ModuleCache")
149149
}
150150
}
151151

Sources/Commands/Options.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public class Options {
2020

2121
public class Path {
2222
public lazy var root = getroot()
23-
public var packages: AbsolutePath { return root.appending("Packages") }
23+
public var packages: AbsolutePath { return root.appending(component: "Packages") }
2424

2525
public var build: AbsolutePath {
26-
get { return _build != nil ? AbsolutePath(_build!) : getroot().appending(".build") }
26+
get { return _build != nil ? AbsolutePath(_build!) : getroot().appending(component: ".build") }
2727
set { _build = newValue.asString }
2828
}
2929
private var _build = getEnvBuildPath()?.asString
@@ -48,7 +48,7 @@ private func getroot() -> AbsolutePath {
4848
while !isFile(root.appending(component: Manifest.filename)) {
4949
root = root.parentDirectory
5050

51-
guard root != "/" else {
51+
guard !root.isRoot else {
5252
// abort because lazy properties cannot throw and we
5353
// want erroring on no manifest found to be “lazy” so
5454
// any path that requires this property errors, but we

Sources/Commands/SwiftPackageTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public struct SwiftPackageTool: SwiftTool {
182182
let item = opts.path.packages.appending(RelativePath(name))
183183

184184
// Only look at repositories.
185-
guard exists(item.appending(".git")) else { continue }
185+
guard exists(item.appending(component: ".git")) else { continue }
186186

187187
// If there is a staged or unstaged diff, don't remove the
188188
// tree. This won't detect new untracked files, but it is

Sources/Commands/SwiftTestTool.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ public struct SwiftTestTool: SwiftTool {
282282
let xctestHelperBin = "swiftpm-xctest-helper"
283283
let binDirectory = AbsolutePath(CommandLine.arguments.first!, relativeTo: currentWorkingDirectory).parentDirectory
284284
// XCTestHelper tool is installed in libexec.
285-
let maybePath = binDirectory.appending("../libexec/swift/pm/").appending(RelativePath(xctestHelperBin))
285+
let maybePath = binDirectory.parentDirectory.appending(components: "libexec", "swift", "pm", xctestHelperBin)
286286
if isFile(maybePath) {
287287
return maybePath
288288
}
289289
// This will be true during swiftpm developement.
290290
// FIXME: Factor all of the development-time resource location stuff into a common place.
291-
let path = binDirectory.appending(RelativePath(xctestHelperBin))
291+
let path = binDirectory.appending(component: xctestHelperBin)
292292
if isFile(path) {
293293
return path
294294
}

Sources/Commands/init.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ final class InitPackage {
9393
}
9494

9595
private func writeGitIgnore() throws {
96-
let gitignore = rootd.appending(".gitignore")
96+
let gitignore = rootd.appending(component: ".gitignore")
9797
guard exists(gitignore) == false else {
9898
return
9999
}
@@ -110,7 +110,7 @@ final class InitPackage {
110110
if mode == .systemModule {
111111
return
112112
}
113-
let sources = rootd.appending("Sources")
113+
let sources = rootd.appending(component: "Sources")
114114
guard exists(sources) == false else {
115115
return
116116
}
@@ -138,7 +138,7 @@ final class InitPackage {
138138
if mode != .systemModule {
139139
return
140140
}
141-
let modulemap = rootd.appending("module.modulemap")
141+
let modulemap = rootd.appending(component: "module.modulemap")
142142
guard exists(modulemap) == false else {
143143
return
144144
}
@@ -156,7 +156,7 @@ final class InitPackage {
156156
if mode == .systemModule {
157157
return
158158
}
159-
let tests = rootd.appending("Tests")
159+
let tests = rootd.appending(component: "Tests")
160160
guard exists(tests) == false else {
161161
return
162162
}
@@ -171,7 +171,7 @@ final class InitPackage {
171171
}
172172

173173
private func writeLinuxMain(testsPath: AbsolutePath) throws {
174-
try writePackageFile(testsPath.appending("LinuxMain.swift")) { stream in
174+
try writePackageFile(testsPath.appending(component: "LinuxMain.swift")) { stream in
175175
stream <<< "import XCTest\n"
176176
stream <<< "@testable import \(moduleName)TestSuite\n\n"
177177
stream <<< "XCTMain([\n"

Sources/Get/PackagesDirectory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class PackagesDirectory {
4343

4444
/// The path to the packages.
4545
var packagesPath: AbsolutePath {
46-
return rootPath.appending("Packages")
46+
return rootPath.appending(component: "Packages")
4747
}
4848

4949
/// The set of all repositories available within the `Packages` directory, by origin.

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public final class ManifestLoader {
110110
cmd += [manifestPath.asString]
111111

112112
//Create and open a temporary file to write toml to
113-
let filePath = manifestPath.parentDirectory.appending(".Package.toml")
113+
let filePath = manifestPath.parentDirectory.appending(component: ".Package.toml")
114114
let fp = try fopen(filePath, mode: .write)
115115
defer { fp.closeFile() }
116116

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public struct PackageBuilder {
191191
}
192192

193193
private var packagesDirectory: AbsolutePath {
194-
return packagePath.appending("Packages")
194+
return packagePath.appending(component: "Packages")
195195
}
196196

197197
private var excludedPaths: [AbsolutePath] {
@@ -232,7 +232,7 @@ public struct PackageBuilder {
232232

233233
/// Collects the modules which are defined by a package.
234234
private func constructModules() throws -> [Module] {
235-
let moduleMapPath = packagePath.appending("module.modulemap")
235+
let moduleMapPath = packagePath.appending(component: "module.modulemap")
236236
if fileSystem.isFile(moduleMapPath) {
237237
let sources = Sources(paths: [moduleMapPath], root: packagePath)
238238
return [try CModule(name: manifest.name, sources: sources, path: packagePath, pkgConfig: pkgConfigPath, providers: manifest.package.providers)]
@@ -408,7 +408,7 @@ public struct PackageBuilder {
408408
}
409409

410410
private func constructTestModules(modules: [Module]) throws -> [Module] {
411-
let testsPath = packagePath.appending("Tests")
411+
let testsPath = packagePath.appending(component: "Tests")
412412

413413
// Don't try to walk Tests if it is in excludes or doesn't exists.
414414
guard fileSystem.isDirectory(testsPath) && !excludedPaths.contains(testsPath) else {

Sources/PackageModel/Module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public class ClangModule: CModule {
131131
}
132132
let type: ModuleType = isLibrary ? .library : .executable
133133

134-
try super.init(name: name, type: type, sources: sources, path: sources.root.appending("include"), isTest: isTest)
134+
try super.init(name: name, type: type, sources: sources, path: sources.root.appending(component: "include"), isTest: isTest)
135135
}
136136
}
137137

Sources/SourceControl/CheckoutManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public class CheckoutManager {
182182

183183
/// The path at which we persist the manager state.
184184
private var statePath: AbsolutePath {
185-
return path.appending("manager-state.json")
185+
return path.appending(component: "manager-state.json")
186186
}
187187

188188
/// Restore the manager state from disk.

Sources/Utility/Platform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum Platform {
2727
case "darwin":
2828
return .darwin
2929
case "linux":
30-
if isFile("/etc/debian_version") {
30+
if isFile(AbsolutePath("/etc/debian_version")) {
3131
return .linux(.debian)
3232
}
3333
default:

Sources/Xcodeproj/generate().swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ public func generate(dstdir: AbsolutePath, projectName: String, graph: PackageGr
4040

4141
let xcodeprojName = "\(projectName).xcodeproj"
4242
let xcodeprojPath = dstdir.appending(RelativePath(xcodeprojName))
43-
let schemesDirectory = xcodeprojPath.appending("xcshareddata/xcschemes")
43+
let schemesDirectory = xcodeprojPath.appending(components: "xcshareddata", "xcschemes")
4444
try makeDirectories(xcodeprojPath)
4545
try makeDirectories(schemesDirectory)
4646
let schemeName = "\(projectName).xcscheme"
4747
let directoryReferences = try findDirectoryReferences(path: srcroot)
4848

4949
////// the pbxproj file describes the project and its targets
50-
try open(xcodeprojPath.appending("project.pbxproj")) { stream in
50+
try open(xcodeprojPath.appending(component: "project.pbxproj")) { stream in
5151
try pbxproj(srcroot: srcroot, projectRoot: dstdir, xcodeprojPath: xcodeprojPath, graph: graph, directoryReferences: directoryReferences, options: options, printer: stream)
5252
}
5353

@@ -59,7 +59,7 @@ public func generate(dstdir: AbsolutePath, projectName: String, graph: PackageGr
5959

6060
////// we generate this file to ensure our main scheme is listed
6161
/// before any inferred schemes Xcode may autocreate
62-
try open(schemesDirectory.appending("xcschememanagement.plist")) { print in
62+
try open(schemesDirectory.appending(component: "xcschememanagement.plist")) { print in
6363
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
6464
print("<plist version=\"1.0\">")
6565
print("<dict>")

Sources/Xcodeproj/pbxproj().swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public func pbxproj(srcroot: AbsolutePath, projectRoot: AbsolutePath, xcodeprojP
5353
print(" };")
5454

5555
////// Package.swift file
56-
let packageSwift = fileRef(inProjectRoot: "Package.swift", srcroot: srcroot)
56+
let packageSwift = fileRef(inProjectRoot: RelativePath("Package.swift"), srcroot: srcroot)
5757
print(" \(packageSwift.refId) = {")
5858
print(" isa = PBXFileReference;")
5959
print(" lastKnownFileType = sourcecode.swift;")

0 commit comments

Comments
 (0)