forked from ssannandeji/Zenject-2019
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command line build to allow testing multiple platforms
- Loading branch information
1 parent
57743e8
commit 0f5bac6
Showing
23 changed files
with
692 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ project_root_marker | |
*.pyc | ||
|
||
*.csproj.user | ||
/SampleBuilds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
|
||
set PYTHONPATH=%~dp0/python;%PYTHONPATH% | ||
python -m mtm.zen.CreateSampleBuilds %* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
import sys | ||
import os | ||
import re | ||
|
||
import argparse | ||
|
||
from mtm.log.LogStreamFile import LogStreamFile | ||
from mtm.log.LogStreamConsole import LogStreamConsole | ||
|
||
from mtm.util.ZipHelper import ZipHelper | ||
|
||
from mtm.util.ScriptRunner import ScriptRunner | ||
|
||
from mtm.util.ProcessRunner import ProcessRunner | ||
from mtm.util.SystemHelper import SystemHelper | ||
from mtm.util.VarManager import VarManager | ||
from mtm.config.Config import Config | ||
from mtm.log.Logger import Logger | ||
from mtm.util.VisualStudioHelper import VisualStudioHelper | ||
from mtm.util.UnityHelper import UnityHelper, Platforms | ||
|
||
from mtm.util.Assert import * | ||
|
||
import mtm.ioc.Container as Container | ||
from mtm.ioc.Inject import Inject | ||
|
||
ScriptDir = os.path.dirname(os.path.realpath(__file__)) | ||
RootDir = os.path.realpath(os.path.join(ScriptDir, '../../../..')) | ||
|
||
class Runner: | ||
_scriptRunner = Inject('ScriptRunner') | ||
_unityHelper = Inject('UnityHelper') | ||
_log = Inject('Logger') | ||
|
||
def run(self, args): | ||
self._args = args | ||
success = self._scriptRunner.runWrapper(self._runInternal) | ||
|
||
if not success: | ||
sys.exit(1) | ||
|
||
def _runInternal(self): | ||
self._log.heading("Running Build") | ||
self._unityHelper.runEditorFunction('[UnityProjectPath]', 'Zenject.Internal.SampleBuilder.BuildRelease', self._args.platform) | ||
|
||
def installBindings(): | ||
|
||
config = { | ||
'PathVars': { | ||
'ScriptDir': ScriptDir, | ||
'RootDir': RootDir, | ||
'BuildDir': '[RootDir]/Build', | ||
'UnityExePath': 'D:/Utils/Unity/Unity2018.1.1f1/Editor/Unity.exe', | ||
'LogPath': '[BuildDir]/Log.txt', | ||
'UnityProjectPath': '[RootDir]/UnityProject', | ||
'MsBuildExePath': 'C:/Windows/Microsoft.NET/Framework/v4.0.30319/msbuild.exe' | ||
}, | ||
'Compilation': { | ||
'UseDevenv': False | ||
}, | ||
} | ||
Container.bind('Config').toSingle(Config, [config]) | ||
|
||
Container.bind('LogStream').toSingle(LogStreamFile) | ||
Container.bind('LogStream').toSingle(LogStreamConsole, True, False) | ||
|
||
Container.bind('ScriptRunner').toSingle(ScriptRunner) | ||
Container.bind('VarManager').toSingle(VarManager) | ||
Container.bind('SystemHelper').toSingle(SystemHelper) | ||
Container.bind('Logger').toSingle(Logger) | ||
Container.bind('ProcessRunner').toSingle(ProcessRunner) | ||
Container.bind('ZipHelper').toSingle(ZipHelper) | ||
Container.bind('VisualStudioHelper').toSingle(VisualStudioHelper) | ||
Container.bind('UnityHelper').toSingle(UnityHelper) | ||
|
||
if __name__ == '__main__': | ||
|
||
if (sys.version_info < (3, 0)): | ||
print('Wrong version of python! Install python 3 and try again') | ||
sys.exit(2) | ||
|
||
parser = argparse.ArgumentParser(description='Create Sample') | ||
parser.add_argument('-ncs', '--newCSharp', action='store_true', help='') | ||
parser.add_argument('-pl', '--platform', type=str, default='Windows', choices=[x for x in Platforms.All], help='The platform to use. If unspecified, windows is assumed.') | ||
args = parser.parse_args(sys.argv[1:]) | ||
|
||
installBindings() | ||
|
||
Runner().run(args) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
UnityProject/Assets/SampleBuilder/Editor/ProjectFileHook.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Xml.Linq; | ||
|
||
using UnityEditor; | ||
|
||
#if ENABLE_VSTU | ||
|
||
using SyntaxTree.VisualStudio.Unity.Bridge; | ||
|
||
[InitializeOnLoad] | ||
public class ProjectFileHook | ||
{ | ||
// necessary for XLinq to save the xml project file in utf8 | ||
class Utf8StringWriter : StringWriter | ||
{ | ||
public override Encoding Encoding | ||
{ | ||
get { return Encoding.UTF8; } | ||
} | ||
} | ||
|
||
static ProjectFileHook() | ||
{ | ||
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) => | ||
{ | ||
// parse the document and make some changes | ||
var document = XDocument.Parse(content); | ||
var ns = document.Root.Name.Namespace; | ||
|
||
document.Root | ||
.Descendants() | ||
.First(x => x.Name.LocalName == "PropertyGroup") | ||
.Add(new XElement(ns + "ImplicitlyExpandNETStandardFacades", "false"), | ||
new XElement(ns + "ImplicitlyExpandDesignTimeFacades", "false")); | ||
|
||
// save the changes using the Utf8StringWriter | ||
var str = new Utf8StringWriter(); | ||
document.Save(str); | ||
|
||
return str.ToString(); | ||
}; | ||
} | ||
} | ||
|
||
#endif |
11 changes: 11 additions & 0 deletions
11
UnityProject/Assets/SampleBuilder/Editor/ProjectFileHook.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using ModestTree; | ||
using UnityEditor; | ||
using UnityEditor.Build.Reporting; | ||
using UnityEngine; | ||
|
||
namespace Zenject.Internal | ||
{ | ||
public class SampleBuilder | ||
{ | ||
[MenuItem("ZenjectSamples/Build Debug")] | ||
public static void BuildDebug() | ||
{ | ||
BuildInternal(false); | ||
} | ||
|
||
[MenuItem("ZenjectSamples/Build Release")] | ||
public static void BuildRelease() | ||
{ | ||
BuildInternal(true); | ||
} | ||
|
||
static void BuildInternal(bool isRelease) | ||
{ | ||
var scenePaths = UnityEditor.EditorBuildSettings.scenes | ||
.Select(x => x.path).ToList(); | ||
|
||
switch (EditorUserBuildSettings.activeBuildTarget) | ||
{ | ||
case BuildTarget.StandaloneWindows64: | ||
case BuildTarget.StandaloneWindows: | ||
{ | ||
string path = Path.Combine( | ||
Application.dataPath, "../../SampleBuilds/Windows/ZenjectSamples.exe"); | ||
|
||
BuildGeneric(path, scenePaths, isRelease); | ||
break; | ||
} | ||
default: | ||
{ | ||
throw new Exception( | ||
"Cannot build on platform '{0}'".Fmt(EditorUserBuildSettings.activeBuildTarget)); | ||
} | ||
} | ||
} | ||
|
||
static bool BuildGeneric( | ||
string path, List<string> scenePaths, bool isRelease) | ||
{ | ||
var options = BuildOptions.None; | ||
|
||
// Create the directory if it doesn't exist | ||
// Otherwise the build fails | ||
Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
|
||
if (!isRelease) | ||
{ | ||
options |= BuildOptions.Development; | ||
} | ||
|
||
var report = BuildPipeline.BuildPlayer(scenePaths.ToArray(), path, EditorUserBuildSettings.activeBuildTarget, options); | ||
|
||
bool succeeded = (report.summary.result == BuildResult.Succeeded); | ||
|
||
if (succeeded) | ||
{ | ||
Log.Info("Build completed successfully"); | ||
} | ||
else | ||
{ | ||
Log.Error("Error occurred while building"); | ||
} | ||
|
||
if (UnityEditorInternal.InternalEditorUtility.inBatchMode) | ||
{ | ||
EditorApplication.Exit(succeeded ? 0 : 1); | ||
} | ||
|
||
return succeeded; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
UnityProject/Assets/SampleBuilder/Editor/SampleBuilder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
namespace ZenjectSamples | ||
{ | ||
public class SampleMenu : MonoBehaviour | ||
{ | ||
public void OnGUI() | ||
{ | ||
if (GUI.Button(new Rect(100, 100, 100, 50), "Asteroids")) | ||
{ | ||
SceneManager.LoadScene("Asteroids"); | ||
} | ||
else if (GUI.Button(new Rect(300, 100, 100, 50), "Space Fighter")) | ||
{ | ||
SceneManager.LoadScene("SpaceFighter"); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.