diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index d89458d7..c6148d18 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -288,23 +288,21 @@ class SourceGenerator { let isTopLevelGroup = (isBaseGroup && !createIntermediateGroups) || isRootPath let groupName = name ?? path.lastComponent - let groupPath = isTopLevelGroup ? - ((try? path.relativePath(from: project.basePath)) ?? path).string : - path.lastComponent - - let relativePath: Path? - if let projectDestinationDirectory = projectDestinationDirectory { - relativePath = try? path.relativePath(from: projectDestinationDirectory) + let groupPath: String + if isTopLevelGroup { + if let relativePath = try? path.relativePath(from: projectDestinationDirectory ?? project.basePath).string { + groupPath = relativePath + } else { + groupPath = path.lastComponent + } } else { - relativePath = Path(groupName) + groupPath = path.lastComponent } - - let shouldSetGroupName = (groupName != groupPath) || (relativePath?.string != groupPath) let group = PBXGroup( children: children, sourceTree: .group, - name: shouldSetGroupName ? groupName : nil, - path: relativePath?.string + name: groupName != groupPath ? groupName : nil, + path: groupPath ) groupReference = addObject(group) groupsByPath[path] = groupReference diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index e635c48e..85ae81bc 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -1021,7 +1021,7 @@ class ProjectGeneratorTests: XCTestCase { let project = Project(name: "test", targets: [frameworkWithSources]) let generator = ProjectGenerator(project: project) let generatedProject = try generator.generateXcodeProject() - let group = generatedProject.pbxproj.groups.first(where: { $0.name == groupName }) + let group = generatedProject.pbxproj.groups.first(where: { $0.nameOrPath == groupName }) try expect(group?.path) == "App_iOS" } } @@ -1032,7 +1032,7 @@ class ProjectGeneratorTests: XCTestCase { let project = Project(name: "test", targets: [frameworkWithSources]) let generator = ProjectGenerator(project: project) let generatedProject = try generator.generateXcodeProject(to: destinationPath) - let group = generatedProject.pbxproj.groups.first(where: { $0.name == groupName }) + let group = generatedProject.pbxproj.groups.first(where: { $0.nameOrPath == groupName }) try expect(group?.path) == "TestProject/App_iOS" } }