From da8fad42d74ab89ff45aadef2d2f8acd6eb8f9bf Mon Sep 17 00:00:00 2001 From: Nik Date: Thu, 26 Nov 2020 14:09:39 +0600 Subject: [PATCH] fix issue with absolute path linking --- Sources/General/ProjectService.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/General/ProjectService.swift b/Sources/General/ProjectService.swift index f927ab4..89c0418 100644 --- a/Sources/General/ProjectService.swift +++ b/Sources/General/ProjectService.swift @@ -4,6 +4,7 @@ import PathKit import XcodeProj +import Foundation final class ProjectService { @@ -32,6 +33,18 @@ final class ProjectService { throw Error.noProject(path: path.string) } + // Folowing code fixes issue with absolute path linkinking. + // Creating of relative urls based on project url becomes useless + // due to XcodeProj internal issues. + var filePath = filePath + if filePath.string.contains(path.string) { + var string = filePath.string.replacingOccurrences(of: path.string, with: "") + if string.starts(with: "/") { + string.removeFirst() + } + filePath = Path(string) + } + var components = filePath.components components.removeLast() let groupPath = Path(components: components) @@ -39,8 +52,7 @@ final class ProjectService { throw Error.noGroup } - let fullPath = path + filePath - let file = try group.addFile(at: fullPath, sourceTree: .sourceRoot, sourceRoot: path) + let file = try group.addFile(at: filePath, sourceTree: .sourceRoot, sourceRoot: path) xcodeproj?.pbxproj.add(object: file) let targets = xcodeproj?.pbxproj.nativeTargets let target: PBXNativeTarget?