Skip to content

Commit 38c1d28

Browse files
committed
[xcodegen] Fix hasPrefix for paths
The intention here was to do a component-wise prefix check, not sure why I did a string prefix check. Switch to component prefix and rename to `starts(with:)` to match `FilePath`.
1 parent b3b538e commit 38c1d28

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/SwiftTargets.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ struct SwiftTargets {
285285

286286
func getTargets(below path: RelativePath) -> [SwiftTarget] {
287287
targets.filter { target in
288-
guard let parent = target.buildRule?.parentPath, parent.hasPrefix(path)
288+
guard let parent = target.buildRule?.parentPath, parent.starts(with: path)
289289
else {
290290
return false
291291
}

utils/swift-xcodegen/Sources/SwiftXcodeGen/Generator/ProjectGenerator.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ fileprivate final class ProjectGenerator {
154154
guard let path else { return true }
155155

156156
// Not very efficient, but excludedPaths should be small in practice.
157-
guard let excluded = spec.excludedPaths.first(where: { path.hasPrefix($0.path) })
158-
else {
157+
guard let excluded = spec.excludedPaths.first(
158+
where: { path.starts(with: $0.path) }
159+
) else {
159160
return true
160161
}
161162
if let description, let reason = excluded.reason {
@@ -238,7 +239,9 @@ fileprivate final class ProjectGenerator {
238239
group(for: repoRelativePath.appending(parentPath)) != nil else {
239240
// If this isn't a child of an explicitly added reference, something
240241
// has probably gone wrong.
241-
if !spec.referencesToAdd.contains(where: { parentPath.hasPrefix($0.path) }) {
242+
if !spec.referencesToAdd.contains(
243+
where: { parentPath.starts(with: $0.path) }
244+
) {
242245
log.warning("""
243246
Target '\(name)' at '\(repoRelativePath.appending(parentPath))' is \
244247
nested in a folder reference; skipping. This is likely an xcodegen bug.

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/PathProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public extension PathProtocol {
7878
return exts.contains(where: { ext == $0.rawValue })
7979
}
8080

81-
func hasPrefix(_ other: Self) -> Bool {
82-
rawPath.hasPrefix(other.rawPath)
81+
func starts(with other: Self) -> Bool {
82+
self.storage.starts(with: other.storage)
8383
}
8484

8585
var components: FilePath.ComponentView {

0 commit comments

Comments
 (0)