From d8bf945ca22cfcc7b026e2a06919b7ec72a38740 Mon Sep 17 00:00:00 2001 From: freddi Date: Thu, 5 Mar 2020 09:50:45 +0900 Subject: [PATCH] Fixed issue on localPackage when specified as absolute path and when using -p --- Sources/XcodeGenKit/PBXProjGenerator.swift | 3 +-- Sources/XcodeGenKit/SourceGenerator.swift | 10 ++++++++-- Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 2244eb63..d88fdf1d 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -57,8 +57,7 @@ public class PBXProjGenerator { } for (_, package) in project.localPackages { - let path = project.basePath + Path(package.path).normalize() - try sourceGenerator.createLocalPackage(path: path) + try sourceGenerator.createLocalPackage(path: Path(package.path)) } let buildConfigs: [XCBuildConfiguration] = project.configs.map { config in diff --git a/Sources/XcodeGenKit/SourceGenerator.swift b/Sources/XcodeGenKit/SourceGenerator.swift index b0e94360..edc53a47 100644 --- a/Sources/XcodeGenKit/SourceGenerator.swift +++ b/Sources/XcodeGenKit/SourceGenerator.swift @@ -60,12 +60,18 @@ class SourceGenerator { localPackageGroup = addObject(PBXGroup(sourceTree: .sourceRoot, name: groupName)) rootGroups.insert(localPackageGroup!) } + + let absolutePath = path.isAbsolute ? path : project.basePath + path.normalize() + + // Get local pakcage's relative path from generating project's root + let fileReferencePath = try? absolutePath.relativePath(from: projectDirectory ?? project.basePath).string + let fileReference = addObject( PBXFileReference( - sourceTree: .sourceRoot, + sourceTree: .group, name: path.lastComponent, lastKnownFileType: "folder", - path: try path.relativePath(from: project.basePath).string + path: fileReferencePath ) ) localPackageGroup!.children.append(fileReference) diff --git a/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj b/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj index a5886840..d9ea20df 100644 --- a/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj +++ b/Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj @@ -49,7 +49,7 @@ 4E22B8BCC18A29EFE1DE3BE4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 61C17B77601A9D1B7895AB42 /* StaticLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaticLibrary.swift; sourceTree = ""; }; A9601593D0AD02931266A4E5 /* App.xctestplan */ = {isa = PBXFileReference; path = App.xctestplan; sourceTree = ""; }; - C1DE9A872F470EAA65B9B0B0 /* XcodeGen */ = {isa = PBXFileReference; lastKnownFileType = folder; name = XcodeGen; path = ../../..; sourceTree = SOURCE_ROOT; }; + B71D3227C09EFC935723F45B /* .. */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ..; path = ../../..; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -107,7 +107,7 @@ AD0F3623091EEA8D1EA3DFF8 /* Packages */ = { isa = PBXGroup; children = ( - C1DE9A872F470EAA65B9B0B0 /* XcodeGen */, + B71D3227C09EFC935723F45B /* .. */, ); name = Packages; sourceTree = SOURCE_ROOT;