Skip to content

Commit

Permalink
Merge pull request #14 from handsomecode/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
enmiller authored Feb 7, 2018
2 parents aa00ee5 + d5845fd commit 4cf989d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TOOL_NAME = UnityBuildKit
VERSION = 1.1.2
VERSION = 1.1.3

PREFIX = /usr/local
INSTALL_PATH = $(PREFIX)/bin/$(TOOL_NAME)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img src="Assets/ubk_logo.png">
</p>
<p align="center">
<img src="https://img.shields.io/badge/version-1.1.2-blue.svg?style=flat-square" />
<img src="https://img.shields.io/badge/version-1.1.3-blue.svg?style=flat-square" />
<a href="https://github.com/handsomecode/UnityBuildKit/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square"/>
</a>
Expand Down
4 changes: 2 additions & 2 deletions Sources/UBKit/Files/Unity/UnityFrameworksScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Foundation

extension File {

class func unityFrameworksScriptFile(projectName: String, iOSProjectPath: String) -> Data? {
class func unityFrameworksScriptFile(iOSProjectName: String, iOSProjectPath: String) -> Data? {
let file = """
using System.Collections;
using System.IO;
Expand All @@ -39,7 +39,7 @@ extension File {
public class XcodeFrameworks: MonoBehaviour {
private const string iOSProjectRoot = \"\(iOSProjectPath)\";
private const string iOSProjectName = \"\(projectName)\";
private const string iOSProjectName = \"\(iOSProjectName)\";
private const string PbxFilePath = iOSProjectName + ".xcodeproj/project.pbxproj";
public static void Perform () {
Expand Down
4 changes: 2 additions & 2 deletions Sources/UBKit/Files/Unity/UnityProjectScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Foundation

extension File {

class func unityProjectScriptFile(projectName: String, iOSProjectPath: String) -> Data? {
class func unityProjectScriptFile(iOSProjectName: String, iOSProjectPath: String) -> Data? {
let file = """
using System.Linq;
using System.Collections.Generic;
Expand All @@ -40,7 +40,7 @@ extension File {
public class XcodeRefresher {
private const string iOSProjectRoot = \"\(iOSProjectPath)\";
private const string iOSProjectName = \"\(projectName)\";
private const string iOSProjectName = \"\(iOSProjectName)\";
private const string ClassesProjectPath = "Vendor/UBK/Classes";
private const string LibrariesProjectPath = "Vendor/UBK/Libraries";
private const string PbxFilePath = iOSProjectName + ".xcodeproj/project.pbxproj";
Expand Down
16 changes: 6 additions & 10 deletions Sources/UBKit/Workers/FileCopier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class FileCopier {
}

private let config: Config
private let workingPath: String
private let xcodeProjectPath: String
private let xcodeProjectFilePath: String

private lazy var fileManager = FileManager.default
Expand All @@ -49,9 +47,7 @@ class FileCopier {

init(config: Config) {
self.config = config
self.workingPath = config.unity.projectPath
self.xcodeProjectPath = config.iOS.projectPath
self.xcodeProjectFilePath = String(format: "%@%@%@", xcodeProjectPath, config.iOS.projectName, ".xcodeproj")
self.xcodeProjectFilePath = String(format: "%@%@%@", config.iOS.projectPath, config.iOS.projectName, ".xcodeproj")
}

func copyFiles() -> Result {
Expand Down Expand Up @@ -119,7 +115,7 @@ private extension FileCopier {
}

func changeUnityFiles() -> Result {
let mainFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/main.mm")
let mainFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build/Classes/main.mm")
guard fileManager.fileExists(atPath: mainFilePath) else {
return .failure(UBKitError.missingUnityFile("main.mm"))
}
Expand All @@ -128,7 +124,7 @@ private extension FileCopier {
return changeInitResult
}

let appControllerFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/UnityAppController.h")
let appControllerFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build/Classes/UnityAppController.h")
guard fileManager.fileExists(atPath: appControllerFilePath) else {
return .failure(UBKitError.missingUnityFile("UnityAppController.h"))
}
Expand All @@ -137,7 +133,7 @@ private extension FileCopier {
return changeAppControllerResult
}

let metalHelperFilePath = workingPath.appending(config.unity.projectName).appending("/ios_build/Classes/Unity/MetalHelper.mm")
let metalHelperFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build/Classes/Unity/MetalHelper.mm")
guard fileManager.fileExists(atPath: metalHelperFilePath) else {
return .failure(UBKitError.missingUnityFile("MetalHelper.mm"))
}
Expand All @@ -151,7 +147,7 @@ private extension FileCopier {
func addUnityFiles() -> Result {
let semaphore = DispatchSemaphore(value: 0)
var statusCode: Int32 = 999
let projectPath = workingPath.appending(config.unity.projectName).appending("/ios_build")
let projectPath = config.unity.projectPath.appending(config.unity.projectName).appending("/ios_build")

shell.perform(
config.unity.applicationPath,
Expand Down Expand Up @@ -182,7 +178,7 @@ private extension FileCopier {
func addXcodeFrameworks() -> Result {
let semaphore = DispatchSemaphore(value: 0)
var statusCode: Int32 = 999
let projectPath = workingPath.appending(config.unity.projectName)
let projectPath = config.unity.projectPath.appending(config.unity.projectName)

shell.perform(
config.unity.applicationPath,
Expand Down
37 changes: 14 additions & 23 deletions Sources/UBKit/Workers/UnityProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,19 @@ import Foundation
class UnityProject {

private let config: Config
private let workingPath: String
private let projectName: String
private let unitySceneNames: [String]

private let fileManager = FileManager()
private lazy var shell = Shell()
private let unityAppPath: String

init(config: Config) {
self.config = config
self.projectName = config.iOS.projectName
self.workingPath = config.unity.projectPath
self.unityAppPath = config.unity.applicationPath
self.unitySceneNames = config.unity.sceneNames
}

func create() -> Result {
guard UBKit.validatePath(unityAppPath, isDirectory: false) else {
return .failure(UBKitError.invalidFolder(unityAppPath))
guard UBKit.validatePath(config.unity.applicationPath, isDirectory: false) else {
return .failure(UBKitError.invalidFolder(config.unity.applicationPath))
}

print("Unity Project Path: \(workingPath)\n")
print("Unity Project Path: \(config.unity.projectPath)\n")
let unityFolderResult = createUnityFolder()
guard unityFolderResult == .success else {
return unityFolderResult
Expand Down Expand Up @@ -83,7 +74,7 @@ private extension UnityProject {
func createUnityFolder() -> Result {
do {
try fileManager.createDirectory(
atPath: workingPath,
atPath: config.unity.projectPath,
withIntermediateDirectories: false,
attributes: nil)
} catch {
Expand All @@ -95,11 +86,11 @@ private extension UnityProject {

func generateUnityProject() -> Result {
let semaphore = DispatchSemaphore(value: 0)
let unityProjectPath = workingPath.appending(projectName)
let unityProjectPath = config.unity.projectPath.appending(config.unity.projectName)
var statusCode: Int32 = 0

shell.perform(
unityAppPath,
config.unity.applicationPath,
UnityCommandLine.Arguments.batchmode,
UnityCommandLine.Arguments.createProject,
unityProjectPath,
Expand All @@ -123,7 +114,7 @@ private extension UnityProject {
}

func createUnityEditorScripts() -> Result {
let assetsFilePath = workingPath.appending(projectName).appending("/Assets/")
let assetsFilePath = config.unity.projectPath.appending(config.unity.projectName).appending("/Assets/")
guard UBKit.validatePath(assetsFilePath, isDirectory: true) else {
return .failure(UBKitError.invalidFolder(assetsFilePath))
}
Expand All @@ -139,21 +130,21 @@ private extension UnityProject {

guard fileManager.createFile(
atPath: editorFilePath.appending("iOSBuildScript.cs"),
contents: File.unityBuildScriptFile(iOSProjectFolderPath: config.iOS.projectPath, iOSProjectName: projectName),
contents: File.unityBuildScriptFile(iOSProjectFolderPath: config.iOS.projectPath, iOSProjectName: config.iOS.projectName),
attributes: nil) else {
return .failure(UBKitError.unableToCreateFile("Unity iOS Build Script"))
}

guard fileManager.createFile(
atPath: editorFilePath.appending("XcodeProjectRefresher.cs"),
contents: File.unityProjectScriptFile(projectName: projectName, iOSProjectPath: config.iOS.projectPath),
contents: File.unityProjectScriptFile(iOSProjectName: config.iOS.projectName, iOSProjectPath: config.iOS.projectPath),
attributes: nil) else {
return .failure(UBKitError.unableToCreateFile("Unity Project Script"))
}

guard fileManager.createFile(
atPath: editorFilePath.appending("XcodeFrameworks.cs"),
contents: File.unityFrameworksScriptFile(projectName: projectName, iOSProjectPath: config.iOS.projectPath),
contents: File.unityFrameworksScriptFile(iOSProjectName: config.iOS.projectName, iOSProjectPath: config.iOS.projectPath),
attributes: nil) else {
return .failure(UBKitError.unableToCreateFile("Xcode Frameworks Script"))
}
Expand All @@ -164,21 +155,21 @@ private extension UnityProject {
func runInitialProjectBuild() -> Result {
let semaphore = DispatchSemaphore(value: 0)
var statusCode: Int32 = 999
let projectPath = workingPath.appending(projectName)
let projectPath = config.unity.projectPath.appending(config.unity.projectName)
let outputLocation = projectPath.appending("/").appending("ios_build")

// MARK: - Main
print("Initializing Unity scene \(unitySceneNames[0]) for iOS...")
print("Initializing Unity scene \(config.unity.sceneNames[0]) for iOS...")
print("This will take some time to complete\n")
shell.perform(
unityAppPath,
config.unity.applicationPath,
UnityCommandLine.Arguments.batchmode,
UnityCommandLine.Arguments.projectPath,
projectPath,
UnityCommandLine.Arguments.outputLocation,
outputLocation,
UnityCommandLine.Arguments.sceneName,
unitySceneNames[0],
config.unity.sceneNames[0],
UnityCommandLine.Arguments.executeMethod,
UnityCommandLine.buildAction,
UnityCommandLine.Arguments.quit,
Expand Down
32 changes: 13 additions & 19 deletions Sources/UBKit/Workers/XcodeProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import Foundation

class XcodeProject {

private let projectName: String
private let bundleIdentifier: String
private let workingPath: String
private let unityVersion: String
private let config: Config
private let projectPath: String
private let vendorFolderPath: String
private let vendorClassesFolderPath: String
Expand All @@ -40,21 +37,18 @@ class XcodeProject {
private var error: Error?

init(config: Config) {
self.projectName = config.iOS.projectName
self.bundleIdentifier = config.iOS.bundleId
self.workingPath = config.iOS.projectPath
self.unityVersion = config.unity.version
self.config = config

self.projectPath = workingPath.appending(projectName).appending("/")
self.vendorFolderPath = workingPath.appending("Vendor/UBK/")
self.projectPath = config.iOS.projectPath.appending(config.iOS.projectName).appending("/")
self.vendorFolderPath = config.iOS.projectPath.appending("Vendor/UBK/")
self.vendorClassesFolderPath = vendorFolderPath.appending("Classes")
self.vendorLibrariesFolderPath = vendorFolderPath.appending("Libraries")
self.specFileName = "project.yml"
self.bridgingFilesPath = projectPath.appending("UnityBridge/")
}

func create() -> Result {
print("iOS Project Path: \(workingPath)")
print("iOS Project Path: \(config.iOS.projectPath)")
let iOSFolderResult = createiOSFolder()
guard iOSFolderResult == .success else {
return iOSFolderResult
Expand Down Expand Up @@ -104,7 +98,7 @@ private extension XcodeProject {
func createiOSFolder() -> Result {
do {
try fileManager.createDirectory(
atPath: workingPath,
atPath: config.iOS.projectPath,
withIntermediateDirectories: false,
attributes: nil)

Expand All @@ -115,18 +109,18 @@ private extension XcodeProject {
}

func createSpecFile() -> Result {
guard UBKit.validatePath(workingPath, isDirectory: true) else {
return .failure(UBKitError.invalidFolder(workingPath))
guard UBKit.validatePath(config.iOS.projectPath, isDirectory: true) else {
return .failure(UBKitError.invalidFolder(config.iOS.projectPath))
}

let contents = File.specFile(
projectName: projectName,
bundleIdentifier: bundleIdentifier,
unityVersion: unityVersion
projectName: config.iOS.projectName,
bundleIdentifier: config.iOS.bundleId,
unityVersion: config.unity.version
)

guard fileManager.createFile(
atPath: workingPath.appending(specFileName),
atPath: config.iOS.projectPath.appending(specFileName),
contents: contents,
attributes: nil) else {
return .failure(UBKitError.unableToCreateFile("Spec file"))
Expand Down Expand Up @@ -270,7 +264,7 @@ private extension XcodeProject {
}

func generateXcodeProject() -> Result {
let generator = XcodeGenerator(path: workingPath, fileName: specFileName)
let generator = XcodeGenerator(path: config.iOS.projectPath, fileName: specFileName)
return generator.generateProject()
}
}

0 comments on commit 4cf989d

Please sign in to comment.