Skip to content

Commit 3b3b779

Browse files
committed
Deprecate AbsolutePath.withPOSIX(path:)
1 parent f3bac65 commit 3b3b779

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ extension Path {
175175

176176
/// Represents an absolute file system path, independently of what (or whether
177177
/// anything at all) exists at that path in the file system at any given time.
178-
/// An absolute path always starts with a `/` character, and holds a normalized
179-
/// string representation. This normalization is strictly syntactic, and does
180-
/// not access the file system in any way.
178+
/// An absolute path always holds a normalized string representation. This
179+
/// normalization is strictly syntactic, and does not access the file system
180+
/// in any way.
181181
///
182182
/// The absolute path string is normalized by:
183183
/// - Collapsing `..` path components
@@ -197,7 +197,7 @@ public struct AbsolutePath: Path {
197197
/// Underlying type, based on SwiftSystem.
198198
public let filepath: FilePath
199199

200-
/// Public initializer with FilePath.
200+
/// Public initializer with `FilePath``.
201201
public init(_ filepath: FilePath) {
202202
#if os(Windows)
203203
if filepath.isAbsolute {
@@ -220,6 +220,11 @@ public struct AbsolutePath: Path {
220220
/// not interpret leading `~` characters as home directory specifiers).
221221
/// The input string will be normalized if needed, as described in the
222222
/// documentation for AbsolutePath.
223+
///
224+
/// On Unix-like systems, an absolute path always starts with a `/`
225+
/// character. Windows normally regards `/` as a relative root, but for
226+
/// compatibility, system drive letter will be appended. Use
227+
/// `try AbsolutePath(validating:)` to avoid such convention.
223228
public init(_ absStr: String) {
224229
self.init(FilePath(absStr))
225230
}
@@ -299,20 +304,6 @@ public struct AbsolutePath: Path {
299304
#endif
300305
}
301306
}
302-
303-
@available(*, deprecated, message: "use AbsolutePath(_:) directly")
304-
public static func withPOSIX(path: String) -> AbsolutePath {
305-
#if os(Windows)
306-
var filepath = FilePath(path)
307-
precondition(filepath.root != nil)
308-
if !filepath.isAbsolute {
309-
filepath.root = root.filepath.root
310-
}
311-
return AbsolutePath(filepath)
312-
#else
313-
return AbsolutePath(path)
314-
#endif
315-
}
316307
}
317308

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

Sources/TSCBasic/PathShims.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
2929
}
3030

3131
return resolved.standardized.withUnsafeFileSystemRepresentation {
32-
try! AbsolutePath(validating: String(cString: $0!))
32+
AbsolutePath(String(cString: $0!))
3333
}
3434
#else
3535
let pathStr = path.pathString

Sources/TSCTestSupport/FileSystemExtensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension InMemoryFileSystem {
2525
self.init()
2626

2727
for (path, contents) in files {
28-
let path = AbsolutePath.withPOSIX(path: path)
28+
let path = AbsolutePath(path)
2929
try! createDirectory(path.parentDirectory, recursive: true)
3030
try! writeFileContents(path, bytes: contents)
3131
}
@@ -52,7 +52,7 @@ extension FileSystem {
5252
do {
5353
try createDirectory(root, recursive: true)
5454
for path in files {
55-
let components = AbsolutePath.withPOSIX(path: path).components
55+
let components = AbsolutePath(path).components
5656
let path = root.appending(components: components)
5757
try createDirectory(path.parentDirectory, recursive: true)
5858
try writeFileContents(path, bytes: "")

Tests/TSCBasicTests/PathShimTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class WalkTests : XCTestCase {
3737
#if os(Android)
3838
let root = "/system"
3939
var expected = [
40-
AbsolutePath.withPOSIX(path: "\(root)/usr"),
41-
AbsolutePath.withPOSIX(path: "\(root)/bin"),
42-
AbsolutePath.withPOSIX(path: "\(root)/xbin")
40+
AbsolutePath("\(root)/usr"),
41+
AbsolutePath("\(root)/bin"),
42+
AbsolutePath("\(root)/xbin")
4343
]
4444
#else
4545
let root = ""
@@ -49,7 +49,7 @@ class WalkTests : XCTestCase {
4949
AbsolutePath("/sbin")
5050
]
5151
#endif
52-
for x in try! walk(AbsolutePath.withPOSIX(path: "\(root)/"), recursively: false) {
52+
for x in try! walk(AbsolutePath("\(root)/"), recursively: false) {
5353
if let i = expected.firstIndex(of: x) {
5454
expected.remove(at: i)
5555
}

0 commit comments

Comments
 (0)