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

Fix returning full path for file in group without folder. #246

Merged
merged 2 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Writes showEnvVarsInLog only when false https://github.com/xcodeswift/xcproj/pull/240 by @briantkelley
- Writes `PBXProject.projectReferences` to the plist https://github.com/xcodeswift/xcproj/pull/242 by @briantkelley
- Comment generation for `PBXProject`, `PBXTarget`, and `PBXVariantGroup` https://github.com/xcodeswift/xcproj/pull/243 by @briantkelley
- `fullPath` now returns the path for a file inside a group without a folder https://github.com/xcodeswift/xcproj/pull/246 by @ileitch

## 4.1.0

Expand Down
25 changes: 20 additions & 5 deletions Fixtures/iOS/Project.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
0403345F1F8F57CB0079CCF5 /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 0403345D1F8F57CB0079CCF5 /* Model.xcdatamodeld */; };
04D5C09F1F153824008A2F98 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04D5C09E1F153824008A2F98 /* CoreData.framework */; };
04D5C0A31F153924008A2F98 /* Public.h in Headers */ = {isa = PBXBuildFile; fileRef = 04D5C0A01F153915008A2F98 /* Public.h */; };
04D5C0A41F153924008A2F98 /* Protected.h in Headers */ = {isa = PBXBuildFile; fileRef = 04D5C0A11F15391B008A2F98 /* Protected.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -18,6 +17,7 @@
23766C1D1EAA3484007A9026 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 23766C1C1EAA3484007A9026 /* Assets.xcassets */; };
23766C201EAA3484007A9026 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 23766C1E1EAA3484007A9026 /* LaunchScreen.storyboard */; };
23766C2B1EAA3484007A9026 /* iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23766C2A1EAA3484007A9026 /* iOSTests.swift */; };
3CD1EADD205763E400DAEECB /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 3CD1EADB205763E400DAEECB /* Model.xcdatamodeld */; };
/* End PBXBuildFile section */

/* Begin PBXBuildRule section */
Expand Down Expand Up @@ -54,7 +54,6 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0403345E1F8F57CB0079CCF5 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
04D5C09E1F153824008A2F98 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
04D5C0A01F153915008A2F98 /* Public.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Public.h; sourceTree = "<group>"; };
04D5C0A11F15391B008A2F98 /* Protected.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Protected.h; sourceTree = "<group>"; };
Expand All @@ -69,6 +68,7 @@
23766C261EAA3484007A9026 /* iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
23766C2A1EAA3484007A9026 /* iOSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSTests.swift; sourceTree = "<group>"; };
23766C2C1EAA3484007A9026 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3CD1EADC205763E400DAEECB /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -120,6 +120,8 @@
23766C141EAA3484007A9026 /* iOS */ = {
isa = PBXGroup;
children = (
3CD1EADB205763E400DAEECB /* Model.xcdatamodeld */,
3CD1EAD92057638200DAEECB /* GroupWithoutFolder */,
23766C151EAA3484007A9026 /* AppDelegate.swift */,
23766C171EAA3484007A9026 /* ViewController.swift */,
23766C191EAA3484007A9026 /* Main.storyboard */,
Expand All @@ -129,7 +131,6 @@
04D5C0A01F153915008A2F98 /* Public.h */,
04D5C0A11F15391B008A2F98 /* Protected.h */,
04D5C0A21F153921008A2F98 /* Private.h */,
0403345D1F8F57CB0079CCF5 /* Model.xcdatamodeld */,
);
path = iOS;
sourceTree = "<group>";
Expand All @@ -143,6 +144,13 @@
path = iOSTests;
sourceTree = "<group>";
};
3CD1EAD92057638200DAEECB /* GroupWithoutFolder */ = {
isa = PBXGroup;
children = (
);
name = GroupWithoutFolder;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -283,7 +291,7 @@
files = (
23766C181EAA3484007A9026 /* ViewController.swift in Sources */,
23766C161EAA3484007A9026 /* AppDelegate.swift in Sources */,
0403345F1F8F57CB0079CCF5 /* Model.xcdatamodeld in Sources */,
3CD1EADD205763E400DAEECB /* Model.xcdatamodeld in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -503,8 +511,15 @@
/* End XCConfigurationList section */

/* Begin XCVersionGroup section */
0403345D1F8F57CB0079CCF5 /* Model.xcdatamodeld */ = {
3CD1EADB205763E400DAEECB /* Model.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
3CD1EADC205763E400DAEECB /* Model.xcdatamodel */,
);
currentVersion = 3CD1EADC205763E400DAEECB /* Model.xcdatamodel */;
path = Model.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
};
/* End XCVersionGroup section */
};
Expand Down
3 changes: 2 additions & 1 deletion Sources/xcproj/PBXProjObjects+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ public extension PBXProj.Objects {
case .group?:
guard let group = groups.first(where: { $0.value.children.contains(reference) }) else { return sourceRoot }
guard let groupPath = fullPath(fileElement: group.value, reference: group.key, sourceRoot: sourceRoot) else { return nil }
return fileElement.path.flatMap({ Path($0, relativeTo: groupPath) })
guard let fileElementPath = fileElement.path else { return groupPath }
return Path(fileElementPath, relativeTo: groupPath)
default:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/xcprojTests/PBXProjSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class PBXProjIntegrationSpec: XCTestCase {
XCTAssertEqual(proj.objects.aggregateTargets.count, 0)
XCTAssertEqual(proj.objects.containerItemProxies.count, 1)
XCTAssertEqual(proj.objects.copyFilesBuildPhases.count, 1)
XCTAssertEqual(proj.objects.groups.count, 5)
XCTAssertEqual(proj.objects.groups.count, 6)
XCTAssertEqual(proj.objects.configurationLists.count, 3)
XCTAssertEqual(proj.objects.buildConfigurations.count, 6)
XCTAssertEqual(proj.objects.variantGroups.count, 2)
Expand Down
7 changes: 7 additions & 0 deletions Tests/xcprojTests/XcodeProjIntegrationSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ final class XcodeProjIntegrationSpec: XCTestCase {
XCTAssertEqual(file.object.path, "../../newfile.swift")
XCTAssertEqual(fullFilePath, filePath)

let groupWithoutFolder = proj.objects.group(named: "GroupWithoutFolder", inGroup: iOSGroup)!.object
file = try proj.objects.addFile(at: filePath, toGroup: groupWithoutFolder, sourceTree: .group, sourceRoot: sourceRoot)
fullFilePath = proj.objects.fullPath(fileElement: file.object, reference: file.reference, sourceRoot: sourceRoot)

XCTAssertEqual(file.object.path, "../../newfile.swift")
XCTAssertEqual(fullFilePath, filePath)

proj = projectiOS()!.pbxproj
iOSGroup = proj.objects.group(named: "iOS", inGroup: proj.rootGroup)!.object
file = try proj.objects.addFile(at: filePath, toGroup: iOSGroup, sourceTree: .sourceRoot, sourceRoot: sourceRoot)
Expand Down