Skip to content

Commit

Permalink
Add better error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Miller committed Oct 23, 2017
1 parent 83d7b5b commit 2210082
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ $ UnityBuildKit generate

4. Once generation is completed, open the Xcode project. Using the Build Scheme drop down menu, select Edit Scheme to edit your project's scheme (the scheme should be the same name as your project). Select the Run action then the Options tab. In the middle of the window, you will see `Metal API Validation` with a set of options in a drop down menu. Change the current option to `Disabled`, as seen below:
![](Assets/metal_validation_scheme.png)
_(Note: if you do not see the option for Metal API Validation, verify your run destination is a physical device of set to Generic iOS Device)_

#### Notes
- The generation script sets up the Unity project to build for the Device SDK. These means that, if building for a simulator, there is a high probability that you will encounter build errors in Xcode. Change the run destination to a physical device and the errors should go away.
- The generation script sets up the Unity project to build for the Device SDK. These means that, if building for a simulator, there is a high probability that you will encounter build and linker errors in Xcode. Change the run destination to a physical device and the errors should go away.

- If building for a physical device, do not forget to set up your code signing.

Expand Down Expand Up @@ -87,4 +88,4 @@ Inspiration for building `UnityBuildKit` came after running into several problem

## License

UnityBuildKit is licensed under the MIT license. See LICENSE for more info.
UnityBuildKit is licensed under the MIT license. See LICENSE for more info.
6 changes: 3 additions & 3 deletions Sources/UBKit/Models/UBKitError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum UBKitError: Error, CustomStringConvertible {
case error(Error)
case unableToCreateFile(String)
case invalidFolder(String)
case invalidXcodeProject
case invalidXcodeProject(String)
case missingGroup(String)
case invalidUnityProject
case unableToCreateXcodeProjectGroup(String)
Expand All @@ -50,8 +50,8 @@ public enum UBKitError: Error, CustomStringConvertible {
return "Unable to create \(str)"
case .invalidFolder(let str):
return "Invalid Folder: \(str)"
case .invalidXcodeProject:
return "Invalid Xcode Project"
case .invalidXcodeProject(let str):
return "Invalid Xcode Project: \(str)"
case .missingGroup(let str):
return "Could not find \(str)"
case .invalidUnityProject:
Expand Down
32 changes: 16 additions & 16 deletions Sources/UBKit/Workers/FileCopier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ private extension FileCopier {

func addUnityBridgingFiles() -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
}

let sourceBuildPhases = project.pbxproj.sourcesBuildPhases
guard sourceBuildPhases.count == 1, let sourceBuildPhase = sourceBuildPhases.first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing sources build phase"))
}

guard let targetGroup = project.pbxproj.groups.filter({ $0.path == config.projectName }).first else {
Expand Down Expand Up @@ -162,25 +162,25 @@ private extension FileCopier {

func deleteUnityFiles() -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject(""))
}

guard let ubkGroup = project.pbxproj.groups.filter({
$0.path == "UBK"
}).first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing Vendor/UBK/ folder"))
}

guard let frameworksBuildPhase = project.pbxproj.frameworksBuildPhases.first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing frameworks build phase"))
}

guard let sourcesBuildPhase = project.pbxproj.sourcesBuildPhases.first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing sources build phase"))
}

guard let resourcesBuildPhase = project.pbxproj.resourcesBuildPhases.first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing resources build phase"))
}

func removeFile(reference: String) {
Expand Down Expand Up @@ -244,11 +244,11 @@ private extension FileCopier {

func createUnityFileGroups() -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
}

guard let unityGroup = project.pbxproj.groups.filter({ $0.path == "UBK" }).first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing Vendor/UBK/ folder"))
}

if let classesGroup = generateGroup("Classes", sourceTree: .absolute) {
Expand Down Expand Up @@ -300,16 +300,16 @@ private extension FileCopier {
@discardableResult
func addFiles(workingPath: String, parentGroup: PBXGroup) -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
}

let sourceBuildPhases = project.pbxproj.sourcesBuildPhases
guard sourceBuildPhases.count == 1, let sourceBuildPhase = sourceBuildPhases.first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing sources build phase"))
}

guard let mainTarget = project.pbxproj.nativeTargets.filter({ $0.name == config.projectName }).first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing main target"))
}

let frameworksBuildPhase: PBXFrameworksBuildPhase
Expand Down Expand Up @@ -386,16 +386,16 @@ private extension FileCopier {

func copyUnityDataFolder() -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
}

guard let unityGroup = project.pbxproj.groups.filter({ $0.path == "UBK" }).first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing Vendor/UBK/ folder"))
}

let resourcesBuildPhases = project.pbxproj.resourcesBuildPhases
guard resourcesBuildPhases.count == 1, let resourcesBuildPhase = resourcesBuildPhases.first else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Missing resources build phase"))
}

let fileReference = PBXFileReference(reference: generateUUID(PBXFileReference.self, "data".appending(nameSalt)),
Expand All @@ -416,7 +416,7 @@ private extension FileCopier {

func saveProject() -> Result {
guard let project = project else {
return .failure(UBKitError.invalidXcodeProject)
return .failure(UBKitError.invalidXcodeProject("Failed to find project file"))
}

let projectPath = Path(xcodeProjectFilePath)
Expand Down
2 changes: 1 addition & 1 deletion Sources/UBKit/Workers/UnityProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private extension UnityProject {

// MARK: - Main
print("Building \(unitySceneName) for iOS...")
print("This will take some time to complete\n")
print("This may take some time to complete\n")
shell.perform(
unityAppPath,
Unity.Arguments.batchmode,
Expand Down

0 comments on commit 2210082

Please sign in to comment.