Skip to content

Commit 76ae479

Browse files
committed
Deprecate static method AbsolutePath.root
1 parent 49264e3 commit 76ae479

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

Sources/TSCBasic/FileSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -981,11 +981,11 @@ public class RerootedFileSystemView: FileSystem {
981981

982982
/// Adjust the input path for the underlying file system.
983983
private func formUnderlyingPath(_ path: AbsolutePath) -> AbsolutePath {
984-
if path == AbsolutePath.root {
984+
if path.isRoot {
985985
return root
986986
} else {
987987
// FIXME: Optimize?
988-
return root.appending(RelativePath(String(path.pathString.dropFirst(1))))
988+
return root.appending(RelativePath(path.filepath.removingRoot()))
989989
}
990990
}
991991

Sources/TSCBasic/Path.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,14 @@ public struct AbsolutePath: Path {
268268
/// Root directory (whose string representation is just a path separator).
269269
///
270270
/// FIXME: root is not a static value, we'd better remove this property.
271-
public static let root = AbsolutePath(FilePath._root)
271+
@available(*, deprecated, message: "root is not a static value, use the instance property instead")
272+
public static var root: AbsolutePath {
273+
if let rootPath = localFileSystem.currentWorkingDirectory?.root {
274+
return AbsolutePath(rootPath)
275+
} else {
276+
return AbsolutePath(FilePath._root)
277+
}
278+
}
272279
}
273280

274281
/// Represents a relative file system path. A relative path never starts with

Sources/TSCUtility/Platform.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public enum Platform: Equatable {
105105
defer { tmp.deallocate() }
106106
guard confstr(name, tmp.baseAddress, len) == len else { return nil }
107107
let value = String(cString: tmp.baseAddress!)
108-
guard value.hasSuffix(AbsolutePath.root.pathString) else { return nil }
109-
return resolveSymlinks(AbsolutePath(value))
108+
guard let path = try? AbsolutePath(validating: value) else { return nil }
109+
return resolveSymlinks(path)
110110
}
111111
#endif
112112
}

Tests/TSCBasicPerformanceTests/SynchronizedQueuePerfTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TSCBasic
1414
import TSCTestSupport
1515

1616
class SynchronizedQueuePerfTests: XCTestCasePerf {
17-
17+
1818
// Mock the UnitTest struct in SwiftPM/SwiftTestTool.swift
1919
struct Item {
2020
let productPath: AbsolutePath
@@ -28,7 +28,6 @@ class SynchronizedQueuePerfTests: XCTestCasePerf {
2828
}
2929
}
3030

31-
3231
func testEnqueueDequeue_10000() {
3332
let queue = SynchronizedQueue<Item>()
3433
let test = Item(productPath: AbsolutePath.root, name: "TestName", testCase: "TestCaseName")
@@ -42,7 +41,7 @@ class SynchronizedQueuePerfTests: XCTestCasePerf {
4241
}
4342
}
4443
}
45-
44+
4645
func testEnqueueDequeue_1000() {
4746
let queue = SynchronizedQueue<Item>()
4847
let test = Item(productPath: AbsolutePath.root, name: "TestName", testCase: "TestCaseName")
@@ -56,7 +55,7 @@ class SynchronizedQueuePerfTests: XCTestCasePerf {
5655
}
5756
}
5857
}
59-
58+
6059
func testEnqueueDequeue_100() {
6160
let queue = SynchronizedQueue<Item>()
6261
let test = Item(productPath: AbsolutePath.root, name: "TestName", testCase: "TestCaseName")

0 commit comments

Comments
 (0)