Skip to content

Commit 8aa3540

Browse files
author
Richard Lyle
committed
* Added Build manager for making player builds with the AOT compiles.
1 parent 51953f4 commit 8aa3540

File tree

3 files changed

+215
-20
lines changed

3 files changed

+215
-20
lines changed

Editor/Build.cs

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/**
2+
* Copyright 2015 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#if UNITY_EDITOR
19+
20+
using UnityEngine;
21+
using UnityEditor;
22+
using System.Collections;
23+
using IBM.Watson.DeveloperCloud.Utilities;
24+
using System.Collections.Generic;
25+
using System.IO;
26+
using System;
27+
28+
public class Build
29+
{
30+
public static string BuildError { get; set; }
31+
32+
#region Build Options
33+
public static bool IsBuilding {
34+
get { return EditorPrefs.GetInt("IsBuilding") != 0; }
35+
set { EditorPrefs.SetInt( "IsBuilding", value ? 1 : 0 ); }
36+
}
37+
public static BuildTarget BuildTarget {
38+
get { return (BuildTarget)EditorPrefs.GetInt("BuildTarget"); }
39+
set { EditorPrefs.SetInt( "BuildTarget", (int)value ); }
40+
}
41+
public static BuildOptions BuildOptions {
42+
get { return (BuildOptions)EditorPrefs.GetInt("BuildOptions"); }
43+
set { EditorPrefs.SetInt( "BuildOptions", (int)value ); }
44+
}
45+
#endregion
46+
47+
[UnityEditor.Callbacks.DidReloadScripts]
48+
private static void OnScriptsReloaded()
49+
{
50+
// start back up our build co-routine on script reloads..
51+
if ( IsBuilding )
52+
{
53+
Runnable.EnableRunnableInEditor();
54+
Runnable.Run( ExecuteBuild() );
55+
}
56+
}
57+
58+
private static string[] GetBuildScenes()
59+
{
60+
List<string> scenes = new List<string>();
61+
foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
62+
{
63+
if (scene == null || !scene.enabled)
64+
continue;
65+
scenes.Add(scene.path);
66+
}
67+
68+
return scenes.ToArray();
69+
}
70+
71+
private static string GetBuildPath( BuildTarget target )
72+
{
73+
string projectName = Path.GetFileNameWithoutExtension( Application.productName );
74+
if ( target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64 )
75+
projectName += ".exe";
76+
else if ( target == BuildTarget.StandaloneOSXIntel || target == BuildTarget.StandaloneOSXIntel64 || target == BuildTarget.StandaloneOSXUniversal )
77+
projectName += ".app";
78+
else if ( target == BuildTarget.Android )
79+
projectName += ".apk";
80+
81+
string directory = Application.dataPath + "/../Clients/" + target.ToString();
82+
if ( Directory.Exists( directory ) )
83+
Directory.Delete( directory, true );
84+
85+
Directory.CreateDirectory( directory );
86+
return directory + "/" + projectName;
87+
}
88+
89+
private static void StartBuild( BuildTarget target )
90+
{
91+
if (! IsBuilding )
92+
{
93+
IsBuilding = true;
94+
BuildTarget = target;
95+
96+
Runnable.EnableRunnableInEditor();
97+
Runnable.Run( ExecuteBuild() );
98+
}
99+
}
100+
101+
private static IEnumerator ExecuteBuild()
102+
{
103+
yield return null;
104+
105+
/// generate the AOT code, wait for it to be compiled..
106+
FullSerializer.AotHelpers.BuildAOT();
107+
while( EditorApplication.isCompiling )
108+
yield return null;
109+
110+
string [] buildScenes = GetBuildScenes();
111+
string buildPath = GetBuildPath( BuildTarget );
112+
113+
BuildError = string.Empty;
114+
try {
115+
BuildError = BuildPipeline.BuildPlayer( buildScenes, buildPath, BuildTarget, BuildOptions );
116+
}
117+
catch( Exception e )
118+
{
119+
BuildError = e.ToString();
120+
}
121+
122+
FullSerializer.AotHelpers.CleanAOT();
123+
IsBuilding = false;
124+
125+
// TODO: Check if launch from the command line, if so then quit out..
126+
yield break;
127+
}
128+
129+
130+
#region Build Options
131+
[MenuItem( "Watson/Build/Options/Development Build/On", false, 200 ) ]
132+
public static void DevelopmentBuildOn()
133+
{
134+
BuildOptions |= BuildOptions.Development;
135+
}
136+
137+
[MenuItem( "Watson/Build/Options/Development Build/On", true, 200 ) ]
138+
public static bool CanDevelopmentBuildOn()
139+
{
140+
return (BuildOptions & BuildOptions.Development) == 0;
141+
}
142+
143+
[MenuItem( "Watson/Build/Options/Development Build/Off", false, 200 ) ]
144+
public static void DevelopmentBuildOff()
145+
{
146+
BuildOptions &= ~BuildOptions.Development;
147+
}
148+
149+
[MenuItem( "Watson/Build/Options/Development Build/Off", true, 200 ) ]
150+
public static bool CanDevelopmentBuildOff()
151+
{
152+
return (BuildOptions & BuildOptions.Development) != 0;
153+
}
154+
#endregion
155+
156+
#region Build Players
157+
[MenuItem( "Watson/Build/Player/Windows x86", false, 200 )]
158+
public static void BuildWindows()
159+
{
160+
StartBuild( BuildTarget.StandaloneWindows );
161+
}
162+
163+
[MenuItem( "Watson/Build/Player/Windows x64", false, 200 )]
164+
public static void BuildWindows64()
165+
{
166+
StartBuild( BuildTarget.StandaloneWindows64 );
167+
}
168+
169+
[MenuItem( "Watson/Build/Player/OSX x86", false, 200 )]
170+
public static void BuildOSX()
171+
{
172+
StartBuild( BuildTarget.StandaloneOSXIntel );
173+
}
174+
175+
[MenuItem( "Watson/Build/Player/OSX x64", false, 200 )]
176+
public static void BuildOSX64()
177+
{
178+
StartBuild( BuildTarget.StandaloneOSXIntel64 );
179+
}
180+
181+
[MenuItem( "Watson/Build/Player/OSX Universal", false, 200 )]
182+
public static void BuildOSXUniversal()
183+
{
184+
StartBuild( BuildTarget.StandaloneOSXUniversal );
185+
}
186+
187+
[MenuItem( "Watson/Build/Player/Android", false, 200 )]
188+
public static void BuildAndroid()
189+
{
190+
StartBuild( BuildTarget.Android );
191+
}
192+
193+
[MenuItem( "Watson/Build/Player/iOS", false, 200 )]
194+
public static void BuildIOS()
195+
{
196+
StartBuild( BuildTarget.iOS );
197+
}
198+
#endregion
199+
200+
}
201+
202+
#endif

Editor/Build.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ThirdParty/FullSerializer/Source/Editor/AotHelpers.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4-
using FullSerializer;
54
using UnityEngine;
65
using UnityEditor;
76

87
namespace FullSerializer
98
{
109
public static class AotHelpers
1110
{
12-
//[MenuItem("Watson/FullSerializer/Add Seen Aot Compilations", false, 5 )]
13-
public static void AddSeenAotCompilations()
14-
{
15-
var outputDirectory = EditorUtility.SaveFolderPanel( "Please select save path?", Application.dataPath, "fsAotCompilations" );
16-
if (!Directory.Exists(outputDirectory) == false)
17-
Directory.CreateDirectory(outputDirectory);
18-
19-
foreach (var aot in fsAotCompilationManager.AvailableAotCompilations)
20-
{
21-
Debug.Log("Performing AOT compilation for " + aot.Key.CSharpName(true));
22-
var path = Path.Combine(outputDirectory, "AotConverter_" + aot.Key.CSharpName(true, true) + ".cs");
23-
var compilation = aot.Value;
24-
File.WriteAllText(path, compilation);
25-
}
26-
27-
AssetDatabase.Refresh();
28-
}
29-
3011
[MenuItem("Watson/FullSerializer/Build AOT", false, 5 )]
31-
public static void AddAllDiscoverableAotCompilations()
12+
public static void BuildAOT()
3213
{
3314
var outputDirectory = Application.dataPath + "/fsAotCompilations";
3415
if (!Directory.Exists(outputDirectory))

0 commit comments

Comments
 (0)