Skip to content

Commit 7a12c5e

Browse files
authored
fix warning from using deprecated TSC URL (#4110)
motivation: TSC URL is deprecated changes: * migrate the url scheme parsing code to the one call site that needs it
1 parent 6befd7f commit 7a12c5e

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

Sources/PackageLoading/ManifestJSONParser.swift

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import Foundation
1313
import PackageModel
1414
import TSCBasic
1515

16-
import struct TSCUtility.URL
17-
18-
fileprivate typealias URL = Foundation.URL
19-
2016
enum ManifestJSONParser {
2117
private static let filePrefix = "file://"
2218

@@ -250,7 +246,7 @@ enum ManifestJSONParser {
250246
)
251247
}
252248
return AbsolutePath(location).pathString
253-
} else if TSCUtility.URL.scheme(dependencyLocation) == nil {
249+
} else if parseScheme(dependencyLocation) == nil {
254250
// If the dependency URL is not remote, try to "fix" it.
255251
// If the URL has no scheme, we treat it as a path (either absolute or relative to the base URL).
256252
return AbsolutePath(dependencyLocation, relativeTo: packagePath).pathString
@@ -415,6 +411,33 @@ enum ManifestJSONParser {
415411
)
416412
}
417413

414+
/// Parses the URL type of a git repository
415+
/// e.g. https://github.com/apple/swift returns "https"
416+
/// e.g. [email protected]:apple/swift returns "git"
417+
///
418+
/// This is *not* a generic URI scheme parser!
419+
private static func parseScheme(_ location: String) -> String? {
420+
func prefixOfSplitBy(_ delimiter: String) -> String? {
421+
let (head, tail) = location.spm_split(around: delimiter)
422+
if tail == nil {
423+
//not found
424+
return nil
425+
} else {
426+
//found, return head
427+
//lowercase the "scheme", as specified by the URI RFC (just in case)
428+
return head.lowercased()
429+
}
430+
}
431+
432+
for delim in ["://", "@"] {
433+
if let found = prefixOfSplitBy(delim), !found.contains("/") {
434+
return found
435+
}
436+
}
437+
438+
return nil
439+
}
440+
418441
/// Looks for Xcode-style build setting macros "$()".
419442
private static let invalidValueRegex = try! RegEx(pattern: #"(\$\(.*?\))"#)
420443
}

0 commit comments

Comments
 (0)