@@ -13,10 +13,6 @@ import Foundation
13
13
import PackageModel
14
14
import TSCBasic
15
15
16
- import struct TSCUtility. URL
17
-
18
- fileprivate typealias URL = Foundation . URL
19
-
20
16
enum ManifestJSONParser {
21
17
private static let filePrefix = " file:// "
22
18
@@ -250,7 +246,7 @@ enum ManifestJSONParser {
250
246
)
251
247
}
252
248
return AbsolutePath ( location) . pathString
253
- } else if TSCUtility . URL . scheme ( dependencyLocation) == nil {
249
+ } else if parseScheme ( dependencyLocation) == nil {
254
250
// If the dependency URL is not remote, try to "fix" it.
255
251
// If the URL has no scheme, we treat it as a path (either absolute or relative to the base URL).
256
252
return AbsolutePath ( dependencyLocation, relativeTo: packagePath) . pathString
@@ -415,6 +411,33 @@ enum ManifestJSONParser {
415
411
)
416
412
}
417
413
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
+
418
441
/// Looks for Xcode-style build setting macros "$()".
419
442
private static let invalidValueRegex = try ! RegEx ( pattern: #"(\$\(.*?\))"# )
420
443
}
0 commit comments