Skip to content

Commit aa3410f

Browse files
authored
Support PBXGroup build file elements eg localized variants (#35)
* Add localized file to ExampleProject and associated test * Refactor PBXBuildFile.path(projectFolder:) to leverage guard statements * Refactor PBXBuildFile.path(projectFolder:) to return an array of paths * Support PBXGroup build file elements eg localized variants
1 parent da2add4 commit aa3410f

5 files changed

Lines changed: 79 additions & 17 deletions

File tree

Sources/DependencyCalculator/DependencyGraph.swift

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,41 @@ import Workspace
1010
import XcodeProj
1111

1212
extension PBXBuildFile {
13-
func path(projectFolder: Path) -> Path? {
14-
if let path = file?.path {
15-
var intermediatePath = Path()
13+
func paths(projectFolder: Path) -> [Path] {
14+
guard let file else {
15+
Logger.warning("PBXBuildFile without file: self=\(self), \n self.product=\(String(describing: product))")
16+
return []
17+
}
18+
19+
let paths: [String] = switch file {
20+
case let group as PBXGroup:
21+
group.children.compactMap { $0.path }
22+
default:
23+
if let path = file.path {
24+
[path]
25+
} else {
26+
[]
27+
}
28+
}
29+
30+
guard paths.count > 0 else {
31+
Logger.warning("File without paths: self=\(self), \n self.file=\(String(describing: file)), \n self.product=\(String(describing: product))")
32+
return []
33+
}
34+
35+
var intermediatePath = Path()
1636

17-
var parent = file?.parent
37+
var parent = file.parent
1838

19-
while parent?.path != nil {
20-
if let parentPath = parent?.path {
21-
intermediatePath = Path(parentPath) + intermediatePath
22-
}
23-
parent = parent?.parent
39+
while parent?.path != nil {
40+
if let parentPath = parent?.path {
41+
intermediatePath = Path(parentPath) + intermediatePath
2442
}
43+
parent = parent?.parent
44+
}
2545

26-
return projectFolder + intermediatePath + path
27-
} else {
28-
Logger.warning("File without path: self=\(self), \n self.file=\(String(describing: file)), \n self.product=\(String(describing: product))")
29-
return nil
46+
return paths.map {
47+
projectFolder + intermediatePath + $0
3048
}
3149
}
3250
}
@@ -284,13 +302,13 @@ extension WorkspaceInfo {
284302
}
285303

286304
// Source Files
287-
var filesPaths = try Set(target.sourcesBuildPhase()?.files?.compactMap { file in
288-
file.path(projectFolder: path.parent())
305+
var filesPaths = try Set(target.sourcesBuildPhase()?.files?.flatMap { file in
306+
file.paths(projectFolder: path.parent())
289307
} ?? [])
290308

291309
// Resources
292-
filesPaths = try filesPaths.union(Set(target.resourcesBuildPhase()?.files?.compactMap { file in
293-
file.path(projectFolder: path.parent())
310+
filesPaths = try filesPaths.union(Set(target.resourcesBuildPhase()?.files?.flatMap { file in
311+
file.paths(projectFolder: path.parent())
294312
} ?? []))
295313

296314
// Establish dependencies based on linked frameworks build phase

Tests/SelectiveTestingTests/ExampleProject/ExampleProject.xcodeproj/project.pbxproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
27F4680529B145A700A93E94 /* ExampleLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27F4680429B145A700A93E94 /* ExampleLibrary.framework */; };
2323
27F4680929B145F900A93E94 /* ExampleTargetLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27F4680829B145F900A93E94 /* ExampleTargetLibrary.swift */; };
2424
27F4680C29B1482E00A93E94 /* ExamplePackage in Frameworks */ = {isa = PBXBuildFile; productRef = 27F4680B29B1482E00A93E94 /* ExamplePackage */; };
25+
B24BBDBD2CAD7228005E6DAC /* Example.xib in Resources */ = {isa = PBXBuildFile; fileRef = B24BBDBC2CAD7228005E6DAC /* Example.xib */; };
2526
FDE924012A5C5AC300D61FD3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE924002A5C5AC300D61FD3 /* ContentView.swift */; };
2627
/* End PBXBuildFile section */
2728

@@ -88,6 +89,8 @@
8889
27F4680429B145A700A93E94 /* ExampleLibrary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ExampleLibrary.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8990
27F4680829B145F900A93E94 /* ExampleTargetLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleTargetLibrary.swift; sourceTree = "<group>"; };
9091
27F4680A29B1469D00A93E94 /* ExamplePackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = ExamplePackage; sourceTree = "<group>"; };
92+
B24BBDBB2CAD7228005E6DAC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Example.xib; sourceTree = "<group>"; };
93+
B24BBDBF2CAD7244005E6DAC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Example.strings; sourceTree = "<group>"; };
9194
FDE924002A5C5AC300D61FD3 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
9295
/* End PBXFileReference section */
9396

@@ -167,6 +170,7 @@
167170
FDE923FE2A5C5AC300D61FD3 /* Deep */,
168171
276DB5C229B144C900E5C615 /* Assets.xcassets */,
169172
276DB5C429B144C900E5C615 /* Preview Content */,
173+
B24BBDBC2CAD7228005E6DAC /* Example.xib */,
170174
);
171175
path = ExampleProject;
172176
sourceTree = "<group>";
@@ -405,6 +409,7 @@
405409
isa = PBXResourcesBuildPhase;
406410
buildActionMask = 2147483647;
407411
files = (
412+
B24BBDBD2CAD7228005E6DAC /* Example.xib in Resources */,
408413
276DB5C629B144C900E5C615 /* Preview Assets.xcassets in Resources */,
409414
276DB5C329B144C900E5C615 /* Assets.xcassets in Resources */,
410415
);
@@ -509,6 +514,18 @@
509514
};
510515
/* End PBXTargetDependency section */
511516

517+
/* Begin PBXVariantGroup section */
518+
B24BBDBC2CAD7228005E6DAC /* Example.xib */ = {
519+
isa = PBXVariantGroup;
520+
children = (
521+
B24BBDBB2CAD7228005E6DAC /* Base */,
522+
B24BBDBF2CAD7244005E6DAC /* en */,
523+
);
524+
name = Example.xib;
525+
sourceTree = "<group>";
526+
};
527+
/* End PBXVariantGroup section */
528+
512529
/* Begin XCBuildConfiguration section */
513530
276DB5DD29B144CA00E5C615 /* Debug */ = {
514531
isa = XCBuildConfiguration;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
5+
</dependencies>
6+
<objects>
7+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
8+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
9+
</objects>
10+
</document>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Tests/SelectiveTestingTests/SelectiveTestingProjectTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,20 @@ final class SelectiveTestingProjectTests: XCTestCase {
7171
testTool.mainProjectUITests,
7272
]))
7373
}
74+
75+
func testProjectLocalizedPathChange() async throws {
76+
// given
77+
let tool = try testTool.createSUT(config: nil,
78+
basePath: "ExampleProject.xcodeproj")
79+
// when
80+
try testTool.changeFile(at: testTool.projectPath + "ExampleProject/Base.lproj/Example.xib")
81+
82+
// then
83+
let result = try await tool.run()
84+
XCTAssertEqual(result, Set([
85+
testTool.mainProjectMainTarget,
86+
testTool.mainProjectTests,
87+
testTool.mainProjectUITests,
88+
]))
89+
}
7490
}

0 commit comments

Comments
 (0)