Skip to content

Commit

Permalink
Added command line build to allow testing multiple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
svermeulen committed May 27, 2018
1 parent 57743e8 commit 0f5bac6
Show file tree
Hide file tree
Showing 23 changed files with 692 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ project_root_marker
*.pyc

*.csproj.user
/SampleBuilds
5 changes: 5 additions & 0 deletions Build/CreateSampleBuilds.bat
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 %*

2 changes: 1 addition & 1 deletion Build/python/mtm/util/UnityHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _getBuildTargetArg(self, platform):
if platform == Platforms.Ios:
return 'ios'

assertThat(False)
assertThat(False, "Unhandled platform {0}".format(platform))

def runEditorFunctionRaw(self, projectPath, editorCommand, platform, extraArgs):

Expand Down
92 changes: 92 additions & 0 deletions Build/python/mtm/zen/CreateSampleBuilds.py
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)


2 changes: 2 additions & 0 deletions UnityProject/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/Builds
/obj

/.vs

#ignoring pidb, they are just code completion caching data according to:
# http://stackoverflow.com/questions/1022111/what-are-monodevelops-pidb-files
*.pidb
Expand Down
6 changes: 0 additions & 6 deletions UnityProject/Assembly-CSharp.csproj.user

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Zenject.Tests
public class SceneContextEventsTester : MonoBehaviour
{
[SerializeField]
SceneContext _sceneContext;
SceneContext _sceneContext = null;

bool _calledPreInstall;
bool _calledPostInstall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public class GuiHandler : MonoBehaviour, IDisposable, IInitializable
[SerializeField]
GUIStyle _instructionsStyle;

[SerializeField]
GUIStyle _gameOverStyle;

[SerializeField]
GUIStyle _timeStyle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ public class Explosion : MonoBehaviour
[SerializeField]
ParticleSystem _particleSystem;

[SerializeField]
AudioClip _sound;

[SerializeField]
float _soundVolume;

float _startTime;

[Inject]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Zenject
public class BindSignalToBinder<TSignal>
where TSignal : ISignal
{
BindInfo _bindInfo;
DiContainer _container;
BindFinalizerWrapper _finalizerWrapper;

Expand Down
8 changes: 8 additions & 0 deletions UnityProject/Assets/SampleBuilder.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions UnityProject/Assets/SampleBuilder/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions UnityProject/Assets/SampleBuilder/Editor/ProjectFileHook.cs
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 UnityProject/Assets/SampleBuilder/Editor/ProjectFileHook.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions UnityProject/Assets/SampleBuilder/Editor/SampleBuilder.cs
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 UnityProject/Assets/SampleBuilder/Editor/SampleBuilder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions UnityProject/Assets/SampleBuilder/SampleMenu.cs
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");
}
}
}
}
13 changes: 13 additions & 0 deletions UnityProject/Assets/SampleBuilder/SampleMenu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f5bac6

Please sign in to comment.