Skip to content

Commit

Permalink
fix warning from using deprecated TSC URL (#4110)
Browse files Browse the repository at this point in the history
motivation: TSC URL is deprecated

changes:
* migrate the url scheme parsing code to the one call site that needs it
  • Loading branch information
tomerd authored Feb 10, 2022
1 parent 6befd7f commit 7a12c5e
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions Sources/PackageLoading/ManifestJSONParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import Foundation
import PackageModel
import TSCBasic

import struct TSCUtility.URL

fileprivate typealias URL = Foundation.URL

enum ManifestJSONParser {
private static let filePrefix = "file://"

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

/// Parses the URL type of a git repository
/// e.g. https://github.com/apple/swift returns "https"
/// e.g. git@github.com:apple/swift returns "git"
///
/// This is *not* a generic URI scheme parser!
private static func parseScheme(_ location: String) -> String? {
func prefixOfSplitBy(_ delimiter: String) -> String? {
let (head, tail) = location.spm_split(around: delimiter)
if tail == nil {
//not found
return nil
} else {
//found, return head
//lowercase the "scheme", as specified by the URI RFC (just in case)
return head.lowercased()
}
}

for delim in ["://", "@"] {
if let found = prefixOfSplitBy(delim), !found.contains("/") {
return found
}
}

return nil
}

/// Looks for Xcode-style build setting macros "$()".
private static let invalidValueRegex = try! RegEx(pattern: #"(\$\(.*?\))"#)
}
Expand Down

0 comments on commit 7a12c5e

Please sign in to comment.