Skip to content

Commit 921b53e

Browse files
Make the Runfiles compatible with Swift 6 language mode (#1617)
Additionally fixed indentation. Changing `func repository(from path: String)` was not necessary, but decided to swiftify. [Should Regex be Sendable?](https://forums.swift.org/t/should-regex-be-sendable/69529) on swift forums. --------- Co-authored-by: Aaron Sky <aaronsky@skyaaron.com>
1 parent edcaa68 commit 921b53e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

swift/runfiles/Runfiles.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,21 @@ public final class Runfiles {
214214
}
215215
}
216216

217-
// https://github.com/bazel-contrib/rules_go/blob/6505cf2e4f0a768497b123a74363f47b711e1d02/go/runfiles/global.go#L53-L54
218-
private let legacyExternalGeneratedFile = /bazel-out\/[^\/]+\/bin\/external\/([^\/]+)/
219-
private let legacyExternalFile = /external\/([^\/]+)/
220-
221-
// Extracts the canonical name of the repository containing the file
222-
// located at `path`.
223-
private func repository(from path: String) -> String {
224-
if let match = path.prefixMatch(of: legacyExternalGeneratedFile) {
225-
return String(match.1)
226-
}
227-
if let match = path.prefixMatch(of: legacyExternalFile) {
228-
return String(match.1)
229-
}
230-
// If a file is not in an external repository, return an empty string
231-
return ""
232-
}
217+
// https://github.com/bazel-contrib/rules_go/blob/6505cf2e4f0a768497b123a74363f47b711e1d02/go/runfiles/global.go#L53-L54
218+
#if swift(>=5.10)
219+
nonisolated(unsafe) private let legacyExternalGeneratedFile = /bazel-out\/[^\/]+\/bin\/external\/([^\/]+)/
220+
nonisolated(unsafe) private let legacyExternalFile = /external\/([^\/]+)/
221+
#else
222+
private let legacyExternalGeneratedFile = /bazel-out\/[^\/]+\/bin\/external\/([^\/]+)/
223+
private let legacyExternalFile = /external\/([^\/]+)/
224+
#endif
225+
226+
// Extracts the canonical name of the repository containing the file
227+
// located at `path`.
228+
private func repository(from path: String) -> String {
229+
let match = path.prefixMatch(of: legacyExternalGeneratedFile) ?? path.prefixMatch(of: legacyExternalFile)
230+
return match.map { String($0.1) } ?? ""
231+
}
233232

234233
// MARK: Runfiles Paths Computation
235234

0 commit comments

Comments
 (0)