Skip to content

Commit 12db148

Browse files
author
Eric Miller
committed
Fine tuning the Unity build and update process
1 parent 63b5f55 commit 12db148

File tree

5 files changed

+40
-73
lines changed

5 files changed

+40
-73
lines changed

Sources/UBKit/Files/Xcode/SpecFile.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ extension File {
4343
sources:
4444
- \(projectName)
4545
- Vendor
46-
prebuildScripts:
47-
- script: rsync -rc --exclude-from=rsync_unity_exclusion --delete $UNITY_IOS_EXPORT_PATH/Classes/ Vendor/UBK/Classes/\\nrsync -rc --exclude-from=rsync_unity_exclusion --delete $UNITY_IOS_EXPORT_PATH/Libraries/ Vendor/UBK/Libraries/
48-
name: UnityBuildKit Prebuild
4946
postbuildScripts:
5047
- script: rm -rf "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data"\\ncp -Rf "$UNITY_IOS_EXPORT_PATH/Data" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data"
5148
name: UnityBuildKit Postbuild

Sources/UBKit/Files/Xcode/UnityExclusionFile.swift

Lines changed: 0 additions & 38 deletions
This file was deleted.

Sources/UBKit/Workers/FileCopier.swift

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,28 @@ private extension FileCopier {
122122
guard fileManager.fileExists(atPath: mainFilePath) else {
123123
return .failure(UBKitError.missingUnityFile("main.mm"))
124124
}
125+
let changeInitResult = changeUnityInitMethod(pathString: mainFilePath)
126+
guard changeInitResult == .success else {
127+
return changeInitResult
128+
}
125129

126130
let appControllerFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/UnityAppController.h")
127131
guard fileManager.fileExists(atPath: appControllerFilePath) else {
128132
return .failure(UBKitError.missingUnityFile("UnityAppController.h"))
129133
}
134+
let changeAppControllerResult = changeUnityAppControllerMethod(pathString: appControllerFilePath)
135+
guard changeAppControllerResult == .success else {
136+
return changeAppControllerResult
137+
}
130138

131-
changeUnityInitMethod(pathString: mainFilePath)
132-
changeUnityAppControllerMethod(pathString: appControllerFilePath)
139+
let metalHelperFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/Unity/MetalHelper.mm")
140+
guard fileManager.fileExists(atPath: metalHelperFilePath) else {
141+
return .failure(UBKitError.missingUnityFile("MetalHelper.mm"))
142+
}
143+
let changeMetalResult = changeUnityMetalHelper(pathString: metalHelperFilePath)
144+
guard changeMetalResult == .success else {
145+
return changeMetalResult
146+
}
133147
return .success
134148
}
135149

@@ -177,7 +191,7 @@ private extension FileCopier {
177191
}
178192
}
179193

180-
func changeUnityInitMethod(pathString: String) {
194+
func changeUnityInitMethod(pathString: String) -> Result {
181195
do {
182196
let fileString = try String(contentsOfFile: pathString)
183197
let unityString = "int main(int argc, char* argv[])"
@@ -186,11 +200,13 @@ private extension FileCopier {
186200

187201
try newFileString.data(using: .utf8)?.write(to: URL(fileURLWithPath: pathString))
188202
} catch {
189-
print("FAILED TO READ FILE")
203+
return .failure(UBKitError.missingUnityFile("main.mm"))
190204
}
205+
206+
return .success
191207
}
192208

193-
func changeUnityAppControllerMethod(pathString: String) {
209+
func changeUnityAppControllerMethod(pathString: String) -> Result {
194210
do {
195211
let fileString = try String(contentsOfFile: pathString)
196212
let unityString = """
@@ -210,8 +226,24 @@ private extension FileCopier {
210226
let newFileString = fileString.replacingOccurrences(of: unityString, with: replacementString)
211227
try newFileString.data(using: .utf8)?.write(to: URL(fileURLWithPath: pathString))
212228
} catch {
213-
print("FAILED TO READ FILE")
229+
return .failure(UBKitError.missingUnityFile("UnityAppController.h"))
230+
}
231+
232+
return .success
233+
}
234+
235+
func changeUnityMetalHelper(pathString: String) -> Result {
236+
do {
237+
let fileString = try String(contentsOfFile: pathString)
238+
let unityString = "surface->stencilRB = [surface->device newTextureWithDescriptor: stencilTexDesc];"
239+
let replacementString = "stencilTexDesc.usage |= MTLTextureUsageRenderTarget;\n surface->stencilRB = [surface->device newTextureWithDescriptor: stencilTexDesc];"
240+
let newFileString = fileString.replacingOccurrences(of: unityString, with: replacementString)
241+
try newFileString.data(using: .utf8)?.write(to: URL(fileURLWithPath: pathString))
242+
} catch {
243+
return .failure(UBKitError.missingUnityFile("MetalHelper.mm"))
214244
}
245+
246+
return .success
215247
}
216248
}
217249

@@ -225,8 +257,8 @@ private extension FileCopier {
225257
var uuid: String = ""
226258
var counter: UInt = 0
227259
let className: String = String(describing: T.self).replacingOccurrences(of: "PBX", with: "")
228-
let classAcronym = String(className.characters.filter { String($0).lowercased() != String($0) })
229-
let stringID = String(abs(id.hashValue).description.characters.prefix(10 - classAcronym.characters.count))
260+
let classAcronym = className.filter({ String($0).lowercased() != String($0) })
261+
let stringID = String(abs(id.hashValue).description.prefix(10 - classAcronym.utf8.count))
230262
repeat {
231263
counter += 1
232264
uuid = "\(classAcronym)\(stringID)\(String(format: "%02d", counter))"

Sources/UBKit/Workers/XcodeProject.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ class XcodeProject {
6161
return specFileResult
6262
}
6363

64-
let unityExclusionFileResult = createUnityExclusionFile()
65-
guard unityExclusionFileResult == .success else {
66-
return unityExclusionFileResult
67-
}
68-
6964
let projectFolderResult = createProjectFolder()
7065
guard projectFolderResult == .success else {
7166
return projectFolderResult
@@ -139,21 +134,6 @@ private extension XcodeProject {
139134
return .success
140135
}
141136

142-
func createUnityExclusionFile() -> Result {
143-
guard UBKit.validatePath(workingPath, isDirectory: true) else {
144-
return .failure(UBKitError.invalidFolder(workingPath))
145-
}
146-
147-
guard fileManager.createFile(
148-
atPath: workingPath.appending("rsync_unity_exclusion"),
149-
contents: File.unityExclusionFile(),
150-
attributes: nil) else {
151-
return .failure(UBKitError.unableToCreateFile("Unity exclusion file"))
152-
}
153-
154-
return .success
155-
}
156-
157137
func createProjectFolder() -> Result {
158138
do {
159139
try fileManager.createDirectory(

UnityBuildKit.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/* Begin PBXBuildFile section */
1010
D43456441FA3AD5B00CE9717 /* config.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43456431FA3AD5B00CE9717 /* config.swift */; };
1111
D48370ED1FA9137E00A05A8B /* UnityProjectScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48370EB1FA912B200A05A8B /* UnityProjectScript.swift */; };
12-
D48371001FA9F5A500A05A8B /* UnityExclusionFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48370FF1FA9F5A500A05A8B /* UnityExclusionFile.swift */; };
1312
OBJ_197 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_6 /* Package.swift */; };
1413
OBJ_203 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_67 /* Package.swift */; };
1514
OBJ_209 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_116 /* Package.swift */; };
@@ -472,7 +471,6 @@
472471
"AEXML::AEXML::Product" /* AEXML.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AEXML.framework; sourceTree = BUILT_PRODUCTS_DIR; };
473472
D43456431FA3AD5B00CE9717 /* config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = config.swift; sourceTree = "<group>"; };
474473
D48370EB1FA912B200A05A8B /* UnityProjectScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnityProjectScript.swift; sourceTree = "<group>"; };
475-
D48370FF1FA9F5A500A05A8B /* UnityExclusionFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnityExclusionFile.swift; sourceTree = "<group>"; };
476474
"JSONUtilities::JSONUtilities::Product" /* JSONUtilities.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = JSONUtilities.framework; sourceTree = BUILT_PRODUCTS_DIR; };
477475
OBJ_10 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
478476
OBJ_100 /* PBXSourcesBuildPhase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PBXSourcesBuildPhase.swift; sourceTree = "<group>"; };
@@ -903,7 +901,6 @@
903901
OBJ_22 /* MainStoryboardFile.swift */,
904902
OBJ_23 /* SpecFile.swift */,
905903
OBJ_24 /* ViewControllerFile.swift */,
906-
D48370FF1FA9F5A500A05A8B /* UnityExclusionFile.swift */,
907904
);
908905
path = Xcode;
909906
sourceTree = "<group>";
@@ -1623,7 +1620,6 @@
16231620
files = (
16241621
OBJ_281 /* File.swift in Sources */,
16251622
OBJ_282 /* UnityEditorBuildScript.swift in Sources */,
1626-
D48371001FA9F5A500A05A8B /* UnityExclusionFile.swift in Sources */,
16271623
OBJ_283 /* BridgeHeaderFile.swift in Sources */,
16281624
OBJ_284 /* MessageBridge.swift in Sources */,
16291625
OBJ_285 /* UnityUtilsFile.swift in Sources */,

0 commit comments

Comments
 (0)