diff --git a/CHANGELOG.md b/CHANGELOG.md index d5181dbfb..dba87adcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ##### Bug Fixes -- None. +- Fix local Swift package support. ## 2.20.0 (2024-05-29) diff --git a/Sources/PeripheryKit/SPM/SPM.swift b/Sources/PeripheryKit/SPM/SPM.swift index 84518d0ad..cdd447d19 100644 --- a/Sources/PeripheryKit/SPM/SPM.swift +++ b/Sources/PeripheryKit/SPM/SPM.swift @@ -40,10 +40,6 @@ public struct SPM { targets.filter(\.isSwiftTarget) } - public var testTargets: [Target] { - targets.filter(\.isTestTarget) - } - func clean() throws { try Shell.shared.exec(["swift", "package", "clean"]) } @@ -56,7 +52,6 @@ public struct SPM { let path: String let moduleType: String let type: String - let targetDependencies: Set? public var sourcePaths: [FilePath] { let root = FilePath(path) @@ -75,10 +70,6 @@ public struct SPM { public var isTestTarget: Bool { type == "test" } - - public func depends(on target: Target) -> Bool { - (targetDependencies ?? []).contains(target.name) - } } } diff --git a/Sources/XcodeSupport/XcodeProject.swift b/Sources/XcodeSupport/XcodeProject.swift index 4e49d7c7e..c2b430cc1 100644 --- a/Sources/XcodeSupport/XcodeProject.swift +++ b/Sources/XcodeSupport/XcodeProject.swift @@ -72,19 +72,10 @@ final class XcodeProject: XcodeProjectlike { if !packageTargetNames.isEmpty { var packages: [SPM.Package] = [] - // The project file does not provide a clear way to identify file references for local SPM packages. - // We need to iterate over all references and check for folders containing a Package.swift file. - for fileRef in xcodeProject.pbxproj.fileReferences { - // To avoid checking every single file reference, narrow our search down to the known file types Xcode uses - // for package references. - guard ["wrapper", "folder", "text"].contains(fileRef.lastKnownFileType), - let fullPath = try fileRef.fullPath(sourceRoot: sourceRoot.string) - else { continue } - - let packagePath = FilePath(fullPath) - - if packagePath.appending("Package.swift").exists { - try packagePath.chdir { + for localPackage in xcodeProject.pbxproj.rootObject?.localPackages ?? [] { + let path = sourceRoot.appending(localPackage.relativePath) + if path.appending("Package.swift").exists { + try path.chdir { let package = try SPM.Package.load() packages.append(package) } @@ -95,10 +86,6 @@ final class XcodeProject: XcodeProjectlike { for package in packages { if let target = package.targets.first(where: { $0.name == targetName }) { result[package, default: []].insert(target) - - // Also include any test targets that depend upon this target, as they may be built by a scheme. - let testTargets = package.testTargets.filter { $0.depends(on: target) } - result[package, default: []].formUnion(testTargets) } } })