@@ -17,7 +17,7 @@ class FileCopier {
1717 let buildFile : PBXBuildFile
1818 }
1919
20- private let projectName : String
20+ private let config : Config
2121 private let workingPath : String
2222 private let xcodeProjectPath : String
2323 private let xcodeProjectFilePath : String
@@ -30,11 +30,11 @@ class FileCopier {
3030 private var classesGroup : PBXGroup ?
3131 private var libsGroup : PBXGroup ?
3232
33- init ( projectName : String , workingPath: String , xcodeProjectPath: String ) {
34- self . projectName = projectName
33+ init ( config : Config , workingPath: String , xcodeProjectPath: String ) {
34+ self . config = config
3535 self . workingPath = workingPath
3636 self . xcodeProjectPath = xcodeProjectPath
37- self . xcodeProjectFilePath = String ( format: " %@%@%@ " , xcodeProjectPath, projectName, " .xcodeproj " )
37+ self . xcodeProjectFilePath = String ( format: " %@%@%@ " , xcodeProjectPath, config . projectName, " .xcodeproj " )
3838 }
3939
4040 func copyFiles( ) -> Result {
@@ -54,7 +54,7 @@ class FileCopier {
5454 }
5555
5656 print ( " Adding Unity files to Xcode project " )
57- let classesPath = workingPath. appending ( projectName ) . appending ( " /ios_build/Classes/ " )
57+ let classesPath = workingPath. appending ( config . relativeUnityClassesPath )
5858 guard let classesGroup = classesGroup else {
5959 return . failure( UBKitError . invalidUnityProject)
6060 }
@@ -63,7 +63,7 @@ class FileCopier {
6363 return addClassesFilesResult
6464 }
6565
66- let librariesPath = workingPath. appending ( projectName ) . appending ( " /ios_build/Libraries/ " )
66+ let librariesPath = workingPath. appending ( config . relativeUnityLibrariesPath )
6767 guard let libsGroup = libsGroup else {
6868 return . failure( UBKitError . invalidUnityProject)
6969 }
@@ -90,8 +90,7 @@ private extension FileCopier {
9090 project = try XcodeProj ( path: projectPath)
9191 return . success
9292 } catch {
93- print ( " Failure: \( error. localizedDescription) " )
94- return . failure( UBKitError . invalidXcodeProject)
93+ return . failure( error)
9594 }
9695 }
9796
@@ -105,8 +104,8 @@ private extension FileCopier {
105104 return . failure( UBKitError . invalidXcodeProject)
106105 }
107106
108- guard let targetGroup = project. pbxproj. groups. filter ( { $0. path == projectName } ) . first else {
109- return . failure( UBKitError . missingGroup ( projectName) )
107+ guard let targetGroup = project. pbxproj. groups. filter ( { $0. path == config . projectName } ) . first else {
108+ return . failure( UBKitError . missingGroup ( config . projectName) )
110109 }
111110
112111 do {
@@ -142,14 +141,14 @@ private extension FileCopier {
142141 }
143142
144143 if let classesGroup = generateGroup ( " Classes " , sourceTree: . absolute) {
145- classesGroup. path = workingPath. appending ( projectName ) . appending ( " /ios_build/Classes " )
144+ classesGroup. path = workingPath. appending ( config . relativeUnityClassesPath )
146145 project. pbxproj. addObject ( classesGroup)
147146 self . classesGroup = classesGroup
148147 unityGroup. children. append ( classesGroup. reference)
149148 }
150149
151150 if let librariesGroup = generateGroup ( " Libraries " , sourceTree: . absolute) {
152- librariesGroup. path = workingPath. appending ( projectName ) . appending ( " /ios_build/Libraries " )
151+ librariesGroup. path = workingPath. appending ( config . relativeUnityLibrariesPath )
153152 project. pbxproj. addObject ( librariesGroup)
154153 self . libsGroup = librariesGroup
155154 unityGroup. children. append ( librariesGroup. reference)
@@ -177,10 +176,14 @@ private extension FileCopier {
177176 return . failure( UBKitError . invalidXcodeProject)
178177 }
179178
180- let frameworksBuildPhases = project. pbxproj. frameworksBuildPhases
181- guard frameworksBuildPhases. count == 1 , let frameworksBuildPhase = frameworksBuildPhases. first else {
182- return . failure( UBKitError . invalidXcodeProject)
179+ let frameworksBuildPhase = PBXFrameworksBuildPhase ( reference: generateUUID ( PBXFrameworksBuildPhase . self,
180+ " frameworks " . appending ( nameSalt) ) )
181+ if let mainTarget = project. pbxproj. nativeTargets. filter ( { $0. name == config. projectName } ) . first,
182+ parentGroup. name == " Libraries " {
183+ mainTarget. buildPhases. append ( frameworksBuildPhase. reference)
184+ print ( " Adding to main target " )
183185 }
186+ project. pbxproj. addObject ( frameworksBuildPhase)
184187
185188 @discardableResult
186189 func add( toPath: String , parentGroup: PBXGroup ) -> Result {
@@ -363,7 +366,7 @@ private extension FileCopier {
363366 }
364367
365368 func generateSourceFile( path: Path , in group: PBXGroup , name: String ) -> SourceFile ? {
366- let referencePath = Path ( xcodeProjectPath. appending ( projectName) . appending ( " / " ) . appending ( projectName) )
369+ let referencePath = Path ( xcodeProjectPath. appending ( config . projectName) . appending ( " / " ) . appending ( config . projectName) )
367370 guard let fileReference = getFileReference ( path: path, inPath: referencePath, name: name) else {
368371 return nil
369372 }
0 commit comments