Skip to content

Commit 7f92f6f

Browse files
SpeakusMaxim Kholyavkinpepicrft
authored
fix: Inconsistent behaviour with Xcode 16 when PBXProject.TargetAttributes is empty (#865)
* remove empty TargetAttributes from result pbxproj as Xcode 16 do each run * Add tests * Fix the tests on Linux * Some fixes * Lint fixes * Use Swift 5.10.0 * Don't virtualize on CI * Fix tests on Linux * Not select Xcode * Fix linting issue * Fix tests on linux --------- Co-authored-by: Maxim Kholyavkin <[email protected]> Co-authored-by: Pedro <[email protected]>
1 parent 10c918e commit 7f92f6f

28 files changed

+257
-241
lines changed

.all-contributorsrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@
383383
"code"
384384
]
385385
},
386+
{
386387
"login": "georgenavarro",
387388
"name": "George Navarro",
388389
"avatar_url": "https://avatars.githubusercontent.com/u/2748028?v=4",

.github/workflows/xcodeproj.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ jobs:
2020
runs-on: macos-latest
2121
steps:
2222
- uses: actions/checkout@v3
23-
- name: Select Xcode 16
24-
run: sudo xcode-select -switch /Applications/Xcode_16.app/Contents/Developer
2523
- uses: jdx/mise-action@v2
2624
- name: Build
2725
run: mise run build
@@ -31,15 +29,14 @@ jobs:
3129
steps:
3230
- uses: actions/checkout@v3
3331
- uses: jdx/mise-action@v2
32+
- uses: swift-actions/setup-swift@v2
3433
- name: Build
35-
run: mise run build-linux
34+
run: swift build --configuration release
3635
test:
3736
name: Test (macOS / Xcode)
3837
runs-on: macos-latest
3938
steps:
4039
- uses: actions/checkout@v3
41-
- name: Select Xcode 16
42-
run: sudo xcode-select -switch /Applications/Xcode_16.app/Contents/Developer
4340
- uses: jdx/mise-action@v2
4441
- name: Run tests
4542
run: mise run test
@@ -50,15 +47,18 @@ jobs:
5047
steps:
5148
- uses: actions/checkout@v3
5249
- uses: jdx/mise-action@v2
50+
- uses: swift-actions/setup-swift@v2
51+
- run: |
52+
git config --global user.email '[email protected]'
53+
git config --global user.name 'xcodeproj'
54+
git config --global init.defaultBranch main
5355
- name: Test
54-
run: mise run test-linux
56+
run: swift test
5557

5658
lint:
5759
name: Lint
5860
runs-on: macos-latest
5961
steps:
6062
- uses: actions/checkout@v3
61-
- name: Select Xcode 16
62-
run: sudo xcode-select -switch /Applications/Xcode_16.app/Contents/Developer
6363
- uses: jdx/mise-action@v2
6464
- run: mise run lint

.mise/tasks/test-linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# mise description="Run tests on Linux"
33

4-
CONTAINER_RUNTIME=$(command -v podman || command -v docker)
4+
CONTAINER_RUNTIME=docker
55

66
if [ -z "$CONTAINER_RUNTIME" ]; then
77
echo "Neither podman nor docker is available. Please install one to proceed."

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.7.1
1+
5.10

Package.resolved

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.10.0
22

33
import PackageDescription
44

@@ -10,7 +10,6 @@ let package = Package(
1010
dependencies: [
1111
.package(url: "https://github.com/tadija/AEXML.git", .upToNextMinor(from: "4.6.1")),
1212
.package(url: "https://github.com/kylef/PathKit.git", .upToNextMinor(from: "1.0.1")),
13-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.4.3"),
1413
],
1514
targets: [
1615
.target(name: "XcodeProj",

Sources/XcodeProj/Errors/Errors.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public enum XCodeProjError: Error, CustomStringConvertible, Sendable {
1616
public var description: String {
1717
switch self {
1818
case let .notFound(path):
19-
return "The project cannot be found at \(path.string)"
19+
"The project cannot be found at \(path.string)"
2020
case let .pbxprojNotFound(path):
21-
return "The project doesn't contain a .pbxproj file at path: \(path.string)"
21+
"The project doesn't contain a .pbxproj file at path: \(path.string)"
2222
case let .xcworkspaceNotFound(path):
23-
return "The project doesn't contain a .xcworkspace at path: \(path.string)"
23+
"The project doesn't contain a .xcworkspace at path: \(path.string)"
2424
}
2525
}
2626
}
@@ -36,7 +36,7 @@ public enum XCSharedDataError: Error, CustomStringConvertible {
3636
public var description: String {
3737
switch self {
3838
case let .notFound(path):
39-
return "xcshareddata not found at path \(path.string)"
39+
"xcshareddata not found at path \(path.string)"
4040
}
4141
}
4242
}
@@ -52,7 +52,7 @@ public enum XCUserDataError: Error, CustomStringConvertible {
5252
public var description: String {
5353
switch self {
5454
case let .notFound(path):
55-
return "xcuserdata not found at path \(path.string)"
55+
"xcuserdata not found at path \(path.string)"
5656
}
5757
}
5858
}
@@ -68,7 +68,7 @@ public enum XCWorkspaceError: Error, CustomStringConvertible {
6868
public var description: String {
6969
switch self {
7070
case let .notFound(path):
71-
return "The project cannot be found at \(path.string)"
71+
"The project cannot be found at \(path.string)"
7272
}
7373
}
7474
}
@@ -84,7 +84,7 @@ public enum XCWorkspaceDataError: Error, CustomStringConvertible {
8484
public var description: String {
8585
switch self {
8686
case let .notFound(path):
87-
return "Workspace not found at \(path.string)"
87+
"Workspace not found at \(path.string)"
8888
}
8989
}
9090
}
@@ -100,7 +100,7 @@ public enum XcodeprojEditingError: Error, CustomStringConvertible {
100100
public var description: String {
101101
switch self {
102102
case let .unexistingFile(path):
103-
return "The file at path \(path.string) doesn't exist"
103+
"The file at path \(path.string) doesn't exist"
104104
}
105105
}
106106
}
@@ -116,7 +116,7 @@ public enum XcodeprojWritingError: Error, CustomStringConvertible {
116116
public var description: String {
117117
switch self {
118118
case let .invalidType(classType, expected):
119-
return "Invalid type for object \(classType) that expects a \(expected)"
119+
"Invalid type for object \(classType) that expects a \(expected)"
120120
}
121121
}
122122
}
@@ -140,15 +140,15 @@ public enum PBXObjectError: Error, CustomStringConvertible {
140140
public var description: String {
141141
switch self {
142142
case .missingIsa:
143-
return "Isa property is missing."
143+
"Isa property is missing."
144144
case let .unknownElement(element):
145-
return "The element \(element) is not supported."
145+
"The element \(element) is not supported."
146146
case .objectsReleased:
147-
return "The PBXObjects instance has been released before saving."
147+
"The PBXObjects instance has been released before saving."
148148
case let .objectNotFound(reference):
149-
return "PBXObject with reference \"\(reference)\" not found."
149+
"PBXObject with reference \"\(reference)\" not found."
150150
case let .orphaned(type, reference):
151-
return "Trying to use object \(type) with reference '\(reference)' before being added to any project"
151+
"Trying to use object \(type) with reference '\(reference)' before being added to any project"
152152
}
153153
}
154154
}
@@ -164,7 +164,7 @@ enum PBXProjEncoderError: Error, CustomStringConvertible {
164164
var description: String {
165165
switch self {
166166
case .emptyProjectReference:
167-
return "PBXProj should contain a reference to the XcodeProj object that represents the project"
167+
"PBXProj should contain a reference to the XcodeProj object that represents the project"
168168
}
169169
}
170170
}
@@ -187,23 +187,23 @@ enum PBXProjError: Error, CustomStringConvertible, Equatable {
187187
var description: String {
188188
switch self {
189189
case let .notFound(path):
190-
return ".pbxproj not found at path \(path.string)"
190+
".pbxproj not found at path \(path.string)"
191191
case let .invalidGroupPath(sourceRoot, elementPath):
192-
return "Cannot calculate full path for file element \"\(elementPath ?? "")\" in source root: \"\(sourceRoot)\""
192+
"Cannot calculate full path for file element \"\(elementPath ?? "")\" in source root: \"\(sourceRoot)\""
193193
case let .targetNotFound(targetName):
194-
return "Could not find target with \(targetName)"
194+
"Could not find target with \(targetName)"
195195
case let .frameworksBuildPhaseNotFound(targetName):
196-
return "Could not find frameworks build phase for target \(targetName)"
196+
"Could not find frameworks build phase for target \(targetName)"
197197
case let .sourcesBuildPhaseNotFound(targetName):
198-
return "Could not find sources build phase for target \(targetName)"
198+
"Could not find sources build phase for target \(targetName)"
199199
case let .pathIsAbsolute(path):
200-
return "Path must be relative, but path \(path.string) is absolute"
200+
"Path must be relative, but path \(path.string) is absolute"
201201
case let .multipleLocalPackages(productName: productName):
202-
return "Found multiple top-level packages named \(productName)"
202+
"Found multiple top-level packages named \(productName)"
203203
case let .multipleRemotePackages(productName: productName):
204-
return "Can not resolve dependency \(productName) - conflicting version requirements"
204+
"Can not resolve dependency \(productName) - conflicting version requirements"
205205
case .malformed:
206-
return "The .pbxproj is malformed."
206+
"The .pbxproj is malformed."
207207
}
208208
}
209209
}
@@ -221,9 +221,9 @@ public enum XCBreakpointListError: Error, CustomStringConvertible {
221221
public var description: String {
222222
switch self {
223223
case let .notFound(path):
224-
return "Breakpoints_v2.xcbkptlist couldn't be found at path \(path.string)"
224+
"Breakpoints_v2.xcbkptlist couldn't be found at path \(path.string)"
225225
case let .missing(property):
226-
return "Property \(property) missing"
226+
"Property \(property) missing"
227227
}
228228
}
229229
}
@@ -238,7 +238,7 @@ public enum XCConfigError: Error, CustomStringConvertible {
238238
public var description: String {
239239
switch self {
240240
case let .notFound(path):
241-
return ".xcconfig file not found at \(path.string)"
241+
".xcconfig file not found at \(path.string)"
242242
}
243243
}
244244
}

Sources/XcodeProj/Extensions/KeyedDecodingContainer+Additions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ extension KeyedDecodingContainer {
1111

1212
func decodeIntIfPresent(_ key: KeyedDecodingContainer.Key) throws -> UInt? {
1313
if let string: String = try? decodeIfPresent(key) {
14-
return UInt(string)
14+
UInt(string)
1515
} else if let bool: Bool = try? decodeIfPresent(key) {
16-
return bool ? 0 : 1
16+
bool ? 0 : 1
1717
} else if let int: UInt = try decodeIfPresent(key) {
1818
// don't `try?` here in case key _does_ exist but isn't an expected type
1919
// ie. not a string/bool/int
20-
return int
20+
int
2121
} else {
22-
return nil
22+
nil
2323
}
2424
}
2525

Sources/XcodeProj/Objects/Files/PBXContainerItemProxy.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ public final class PBXContainerItemProxy: PBXObject {
2020

2121
var uuid: String {
2222
switch self {
23-
case let .reference(reference): return reference.value
24-
case let .string(string): return string
23+
case let .reference(reference): reference.value
24+
case let .string(string): string
2525
}
2626
}
2727

2828
var id: RemoteGlobalID {
2929
switch self {
3030
case let .reference(reference):
3131
if let object = reference.getObject() {
32-
return .object(object)
32+
.object(object)
3333
} else {
34-
return .string(reference.value)
34+
.string(reference.value)
3535
}
36-
case let .string(string): return .string(string)
36+
case let .string(string): .string(string)
3737
}
3838
}
3939
}
@@ -44,15 +44,15 @@ public final class PBXContainerItemProxy: PBXObject {
4444

4545
var uuid: String {
4646
switch self {
47-
case let .object(object): return object.uuid
48-
case let .string(string): return string
47+
case let .object(object): object.uuid
48+
case let .string(string): string
4949
}
5050
}
5151

5252
var reference: RemoteGlobalIDReference {
5353
switch self {
54-
case let .object(object): return .reference(object.reference)
55-
case let .string(string): return .string(string)
54+
case let .object(object): .reference(object.reference)
55+
case let .string(string): .string(string)
5656
}
5757
}
5858
}
@@ -185,11 +185,11 @@ private extension PBXContainerItemProxy.ContainerPortal {
185185
var reference: PBXObjectReference? {
186186
switch self {
187187
case let .project(project):
188-
return project.reference
188+
project.reference
189189
case let .fileReference(fileReference):
190-
return fileReference.reference
190+
fileReference.reference
191191
case .unknownObject:
192-
return nil
192+
nil
193193
}
194194
}
195195

Sources/XcodeProj/Objects/Files/PBXGroup.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,17 @@ public extension PBXGroup {
215215
return existingFileReference.value
216216
}
217217

218-
let path: String?
219-
switch sourceTree {
218+
let path: String? = switch sourceTree {
220219
case .group:
221-
path = groupPath.map { filePath.relative(to: $0) }?.string
220+
groupPath.map { filePath.relative(to: $0) }?.string
222221
case .sourceRoot:
223-
path = filePath.relative(to: sourceRoot).string
222+
filePath.relative(to: sourceRoot).string
224223
case .absolute,
225224
.sdkRoot,
226225
.developerDir:
227-
path = filePath.string
226+
filePath.string
228227
default:
229-
path = nil
228+
nil
230229
}
231230
let fileReference = PBXFileReference(
232231
sourceTree: sourceTree,

0 commit comments

Comments
 (0)