Skip to content

Commit

Permalink
Fix local Swift package support. Closes #626
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Jun 15, 2024
1 parent e676e1a commit c0846a6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

##### Bug Fixes

- None.
- Fix local Swift package support.

## 2.20.0 (2024-05-29)

Expand Down
9 changes: 0 additions & 9 deletions Sources/PeripheryKit/SPM/SPM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
Expand All @@ -56,7 +52,6 @@ public struct SPM {
let path: String
let moduleType: String
let type: String
let targetDependencies: Set<String>?

public var sourcePaths: [FilePath] {
let root = FilePath(path)
Expand All @@ -75,10 +70,6 @@ public struct SPM {
public var isTestTarget: Bool {
type == "test"
}

public func depends(on target: Target) -> Bool {
(targetDependencies ?? []).contains(target.name)
}
}
}

Expand Down
21 changes: 4 additions & 17 deletions Sources/XcodeSupport/XcodeProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
}
})
Expand Down

0 comments on commit c0846a6

Please sign in to comment.