From 5f9186b0f26001810cd7b96e6ba1279ccabfd093 Mon Sep 17 00:00:00 2001 From: fortmarek Date: Thu, 6 Feb 2025 19:16:03 +0100 Subject: [PATCH] fix: missing framework target dependency --- .../PBXFrameworksBuildPhaseMapper.swift | 12 +++++++ .../PBXFrameworksBuildPhaseMapperTests.swift | 35 ++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Sources/XcodeGraphMapper/Mappers/Phases/PBXFrameworksBuildPhaseMapper.swift b/Sources/XcodeGraphMapper/Mappers/Phases/PBXFrameworksBuildPhaseMapper.swift index 6bd5b64b..e87851ab 100644 --- a/Sources/XcodeGraphMapper/Mappers/Phases/PBXFrameworksBuildPhaseMapper.swift +++ b/Sources/XcodeGraphMapper/Mappers/Phases/PBXFrameworksBuildPhaseMapper.swift @@ -42,6 +42,18 @@ struct PBXFrameworksBuildPhaseMapper: PBXFrameworksBuildPhaseMapping { xcodeProj: XcodeProj ) throws -> TargetDependency { let fileRef = try buildFile.file.throwing(PBXFrameworksBuildPhaseMappingError.missingFileReference) + switch fileRef.sourceTree { + case .buildProductsDir: + guard let path = fileRef.path else { break } + let name = path.replacingOccurrences(of: ".framework", with: "") + return .target( + name: name, + status: .required, + condition: nil + ) + default: + break + } let filePathString = try fileRef.fullPath(sourceRoot: xcodeProj.srcPathString) .throwing(PBXFrameworksBuildPhaseMappingError.missingFilePath(name: fileRef.name)) diff --git a/Tests/XcodeGraphMapperTests/MapperTests/Phases/PBXFrameworksBuildPhaseMapperTests.swift b/Tests/XcodeGraphMapperTests/MapperTests/Phases/PBXFrameworksBuildPhaseMapperTests.swift index 37d2dac4..1df5df19 100644 --- a/Tests/XcodeGraphMapperTests/MapperTests/Phases/PBXFrameworksBuildPhaseMapperTests.swift +++ b/Tests/XcodeGraphMapperTests/MapperTests/Phases/PBXFrameworksBuildPhaseMapperTests.swift @@ -1,6 +1,8 @@ +import Path import Testing import XcodeGraph import XcodeProj + @testable import XcodeGraphMapper @Suite @@ -18,9 +20,20 @@ struct PBXFrameworksBuildPhaseMapperTests { ) .add(to: pbxProj) .addToMainGroup(in: pbxProj) - let frameworkBuildFile = PBXBuildFile(file: frameworkRef).add(to: pbxProj) - let frameworksPhase = PBXFrameworksBuildPhase(files: [frameworkBuildFile]).add(to: pbxProj) + + let targetFrameworkRef = PBXFileReference( + sourceTree: .buildProductsDir, + path: "Target.framework" + ) + let targetFrameworkBuildFile = PBXBuildFile(file: targetFrameworkRef).add(to: pbxProj) + + let frameworksPhase = PBXFrameworksBuildPhase( + files: [ + frameworkBuildFile, + targetFrameworkBuildFile, + ] + ).add(to: pbxProj) try PBXNativeTarget( name: "App", @@ -36,8 +49,20 @@ struct PBXFrameworksBuildPhaseMapperTests { let frameworks = try mapper.map(frameworksPhase, xcodeProj: xcodeProj) // Then - #expect(frameworks.count == 1) - let dependency = try #require(frameworks.first) - #expect(dependency.name == "MyFramework") + let frameworkPath = try AbsolutePath(validating: "/tmp/TestProject/Frameworks/MyFramework.framework") + #expect( + frameworks.sorted(by: { $0.name < $1.name }) == [ + .framework( + path: frameworkPath, + status: .required, + condition: nil + ), + .target( + name: "Target", + status: .required, + condition: nil + ), + ] + ) } }