Skip to content

Commit 3f23be3

Browse files
authored
deprecate unused and outdated code (#246)
motivation: reduce API surface area when not needed changes: * deprecate ObjectIdentifierProtocol, since we have Identifiable now in the stdlib * deprecate PackageLocation which is a SwiftPM diagnostics concern and name-squats a too general of a name * deprecate AuthorizationProviding which is not in use and redundant * deprecate TSCUtility.URL which is redundant and name-squats / conflict with Foundation.URL * adjust call-sites / test
1 parent 769fea0 commit 3f23be3

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

Sources/TSCBasic/ObjectIdentifierProtocol.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
/// A protocol which implements Hashable protocol using ObjectIdentifier.
1212
///
1313
/// Classes can conform to this protocol to auto-conform to Hashable and Equatable.
14+
@available(*, deprecated, message: "user Identifiable instead")
1415
public protocol ObjectIdentifierProtocol: AnyObject, Hashable {}
1516

17+
@available(*, deprecated)
1618
extension ObjectIdentifierProtocol {
1719
public func hash(into hasher: inout Hasher) {
1820
hasher.combine(ObjectIdentifier(self))

Sources/TSCBasic/Process.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ public struct ProcessResult: CustomStringConvertible {
119119
/// Process allows spawning new subprocesses and working with them.
120120
///
121121
/// Note: This class is thread safe.
122-
public final class Process: ObjectIdentifierProtocol {
123-
122+
public final class Process {
124123
/// Errors when attempting to invoke a process
125124
public enum Error: Swift.Error {
126125
/// The program requested to be executed cannot be found on the existing search paths, or is not executable.
@@ -837,6 +836,16 @@ extension Process {
837836
}
838837
}
839838

839+
extension Process: Hashable {
840+
public func hash(into hasher: inout Hasher) {
841+
hasher.combine(ObjectIdentifier(self))
842+
}
843+
844+
public static func == (lhs: Process, rhs: Process) -> Bool {
845+
ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
846+
}
847+
}
848+
840849
// MARK: - Private helpers
841850

842851
#if !os(Windows)

Sources/TSCUtility/Diagnostics.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ extension Optional where Wrapped == DiagnosticsEngine {
186186
}
187187

188188
/// Namespace for representing diagnostic location of a package.
189+
// deprecated 9/2021
190+
@available(*, deprecated)
189191
public enum PackageLocation {
190192

191193
/// Represents location of a locally available package. This could be root

Sources/TSCUtility/Netrc.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import Foundation
22
import TSCBasic
33

44
/// Supplies `Authorization` header, typically to be appended to `URLRequest`
5+
6+
// deprecated 9/2021
7+
@available(*, deprecated)
58
public protocol AuthorizationProviding {
69
/// Optional `Authorization` header, likely added to `URLRequest`
710
func authorization(for url: Foundation.URL) -> String?
811
}
912

13+
// deprecated 9/2021
14+
@available(*, deprecated)
1015
extension AuthorizationProviding {
1116
public func authorization(for url: Foundation.URL) -> String? {
1217
return nil
@@ -17,9 +22,9 @@ extension AuthorizationProviding {
1722
Netrc feature depends upon `NSTextCheckingResult.range(withName name: String) -> NSRange`,
1823
which is only available in macOS 10.13+, iOS 11+, etc at this time.
1924
*/
20-
@available (macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)
2125
/// Container of parsed netrc connection settings
22-
public struct Netrc: AuthorizationProviding {
26+
@available (macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)
27+
public struct Netrc {
2328
/// Representation of `machine` connection settings & `default` connection settings.
2429
/// If `default` connection settings present, they will be last element.
2530
public let machines: [Machine]
@@ -62,7 +67,7 @@ public struct Netrc: AuthorizationProviding {
6267

6368
let machines: [Machine] = matches.compactMap {
6469
return Machine(for: $0, string: content, variant: "lp") ??
65-
Machine(for: $0, string: content, variant: "pl")
70+
Machine(for: $0, string: content, variant: "pl")
6671
}
6772

6873
if let defIndex = machines.firstIndex(where: { $0.isDefault }) {
@@ -88,6 +93,11 @@ public struct Netrc: AuthorizationProviding {
8893
}
8994
}
9095

96+
// deprecated 9/2021
97+
@available(*, deprecated)
98+
@available (macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)
99+
extension Netrc: AuthorizationProviding {}
100+
91101
@available (macOS 10.13, iOS 11, tvOS 11, watchOS 4, *)
92102
public extension Netrc {
93103
enum Error: Swift.Error {
@@ -117,10 +127,10 @@ public extension Netrc {
117127

118128
init?(for match: NSTextCheckingResult, string: String, variant: String = "") {
119129
guard let name = RegexUtil.Token.machine.capture(in: match, string: string) ?? RegexUtil.Token.default.capture(in: match, string: string),
120-
let login = RegexUtil.Token.login.capture(prefix: variant, in: match, string: string),
121-
let password = RegexUtil.Token.password.capture(prefix: variant, in: match, string: string) else {
122-
return nil
123-
}
130+
let login = RegexUtil.Token.login.capture(prefix: variant, in: match, string: string),
131+
let password = RegexUtil.Token.password.capture(prefix: variant, in: match, string: string) else {
132+
return nil
133+
}
124134
self = Machine(name: name, login: login, password: password)
125135
}
126136
}

Sources/TSCUtility/URL.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
// deprecated 9/2021
12+
@available(*, deprecated, message: "use Foundation APIs instead")
1113
public struct URL {
1214

1315
/// Parses the URL type of a git repository

Tests/TSCBasicTests/ObjectIdentifierProtocolTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ import XCTest
1212

1313
import TSCBasic
1414

15+
@available(*, deprecated)
1516
final class Person {
1617
let name: String
1718
init(_ name: String) {
1819
self.name = name
1920
}
2021
}
2122

23+
@available(*, deprecated)
2224
extension Person: ObjectIdentifierProtocol {}
2325

26+
@available(*, deprecated)
2427
class ObjectIdentifierProtocolTests: XCTestCase {
2528

2629
func testBasics() {

Tests/TSCUtilityTests/StringTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class StringTests: XCTestCase {
5757
}
5858

5959
class URLTests: XCTestCase {
60+
@available(*, deprecated)
6061
func testSchema() {
6162
XCTAssertEqual(TSCUtility.URL.scheme("http://github.com/foo/bar"), "http")
6263
XCTAssertEqual(TSCUtility.URL.scheme("https://github.com/foo/bar"), "https")

0 commit comments

Comments
 (0)