Skip to content

Commit

Permalink
fix issue with absolute path linking
Browse files Browse the repository at this point in the history
  • Loading branch information
Nik committed Nov 26, 2020
1 parent b45e712 commit da8fad4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/General/ProjectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import PathKit
import XcodeProj
import Foundation

final class ProjectService {

Expand Down Expand Up @@ -32,15 +33,26 @@ 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)
guard let group = try addGroupsIfNeeded(for: project, path: groupPath) else {
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?
Expand Down

0 comments on commit da8fad4

Please sign in to comment.