Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions swift/runfiles/Runfiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,21 @@ public final class Runfiles {
}
}

// https://github.com/bazel-contrib/rules_go/blob/6505cf2e4f0a768497b123a74363f47b711e1d02/go/runfiles/global.go#L53-L54
private let legacyExternalGeneratedFile = /bazel-out\/[^\/]+\/bin\/external\/([^\/]+)/
private let legacyExternalFile = /external\/([^\/]+)/

// Extracts the canonical name of the repository containing the file
// located at `path`.
private func repository(from path: String) -> String {
if let match = path.prefixMatch(of: legacyExternalGeneratedFile) {
return String(match.1)
}
if let match = path.prefixMatch(of: legacyExternalFile) {
return String(match.1)
}
// If a file is not in an external repository, return an empty string
return ""
}
// https://github.com/bazel-contrib/rules_go/blob/6505cf2e4f0a768497b123a74363f47b711e1d02/go/runfiles/global.go#L53-L54
#if swift(>=5.10)
nonisolated(unsafe) private let legacyExternalGeneratedFile = /bazel-out\/[^\/]+\/bin\/external\/([^\/]+)/
nonisolated(unsafe) private let legacyExternalFile = /external\/([^\/]+)/
#else
private let legacyExternalGeneratedFile = /bazel-out\/[^\/]+\/bin\/external\/([^\/]+)/
private let legacyExternalFile = /external\/([^\/]+)/
#endif

// Extracts the canonical name of the repository containing the file
// located at `path`.
private func repository(from path: String) -> String {
let match = path.prefixMatch(of: legacyExternalGeneratedFile) ?? path.prefixMatch(of: legacyExternalFile)
return match.map { String($0.1) } ?? ""
}

// MARK: Runfiles Paths Computation

Expand Down