Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for local Swift packages in Xcode 15 #1465

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next Version

### Added

- Added support for local Swift packages in Xcode 15 #1465 @kinnarr

## 2.40.1

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/XcodeProj.git",
"state" : {
"revision" : "6e60fb55271c80f83a186c9b1b4982fd991cfc0a",
"version" : "8.13.0"
"revision" : "447c159b0c5fb047a024fd8d942d4a76cf47dde0",
"version" : "8.16.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
.package(url: "https://github.com/yonaskolb/JSONUtilities.git", from: "4.2.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.2"),
.package(url: "https://github.com/onevcat/Rainbow.git", from: "4.0.0"),
.package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.13.0"),
.package(url: "https://github.com/tuist/XcodeProj.git", exact: "8.16.0"),
.package(url: "https://github.com/jakeheis/SwiftCLI.git", from: "6.0.3"),
.package(url: "https://github.com/mxcl/Version", from: "2.0.0"),
.package(url: "https://github.com/SwiftDocOrg/GraphViz.git", exact: "0.2.0"),
Expand Down
13 changes: 9 additions & 4 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PBXProjGenerator {
var targetFileReferences: [String: PBXFileReference] = [:]
var sdkFileReferences: [String: PBXFileReference] = [:]
var packageReferences: [String: XCRemoteSwiftPackageReference] = [:]
var localPackageReferences: [String: XCLocalSwiftPackageReference] = [:]

var carthageFrameworksByPlatform: [String: Set<PBXFileElement>] = [:]
var frameworkFiles: [PBXFileElement] = []
Expand All @@ -30,7 +31,6 @@ public class PBXProjGenerator {
var generated = false

private var projects: [ProjectReference: PBXProj] = [:]
lazy private var localPackageReferences: [String] = project.packages.compactMap { $0.value.isLocal ? $0.key : nil }

public init(project: Project, projectDirectory: Path? = nil) {
self.project = project
Expand Down Expand Up @@ -170,6 +170,10 @@ public class PBXProjGenerator {
packageReferences[name] = packageReference
addObject(packageReference)
case let .local(path, group):
let packageReference = XCLocalSwiftPackageReference(relativePath: path)
localPackageReferences[name] = packageReference
addObject(packageReference)

try sourceGenerator.createLocalPackage(path: Path(path), group: group.map { Path($0) })
}
}
Expand Down Expand Up @@ -310,7 +314,8 @@ public class PBXProjGenerator {
}
pbxProject.knownRegions = knownRegions.sorted()

pbxProject.packages = packageReferences.sorted { $0.key < $1.key }.map { $1 }
pbxProject.remotePackages = packageReferences.sorted { $0.key < $1.key }.map { $1 }
pbxProject.localPackages = localPackageReferences.sorted { $0.key < $1.key }.map { $1 }

let allTargets: [PBXTarget] = targetObjects.valueArray + targetAggregateObjects.valueArray
pbxProject.targets = allTargets
Expand Down Expand Up @@ -945,7 +950,7 @@ public class PBXProjGenerator {

// If package's reference is none and there is no specified package in localPackages,
// then ignore the package specified as dependency.
if packageReference == nil, !localPackageReferences.contains(dependency.reference) {
if packageReference == nil, localPackageReferences[dependency.reference] == nil {
continue
}

Expand Down Expand Up @@ -1469,7 +1474,7 @@ public class PBXProjGenerator {
func makePackagePluginDependency(for target: ProjectTarget) -> [PBXTargetDependency] {
target.buildToolPlugins.compactMap { buildToolPlugin in
let packageReference = packageReferences[buildToolPlugin.package]
if packageReference == nil, !localPackageReferences.contains(buildToolPlugin.package) {
if packageReference == nil, localPackageReferences[buildToolPlugin.package] == nil {
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
5BA91390AE78D2EE15C60091 /* XCRemoteSwiftPackageReference "Codability" */,
348C81C327DB1710B742C370 /* XCRemoteSwiftPackageReference "Prefire" */,
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */,
630A8CE9F2BE39704ED9D461 /* XCLocalSwiftPackageReference "FooFeature" */,
C6539B364583AE96C18CE377 /* XCLocalSwiftPackageReference "../../.." */,
);
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -662,6 +664,17 @@
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCLocalSwiftPackageReference section */
630A8CE9F2BE39704ED9D461 /* XCLocalSwiftPackageReference "FooFeature" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = FooFeature;
};
C6539B364583AE96C18CE377 /* XCLocalSwiftPackageReference "../../.." */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../..;
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
15DB49096E2978F6BCA8D604 /* FooUI */ = {
isa = XCSwiftPackageProductDependency;
Expand Down