-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCommandLineBuild.cs
116 lines (94 loc) · 3.66 KB
/
CommandLineBuild.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using Nordeus.Build.Reporters;
using UnityEditor;
namespace Nordeus.Build
{
public static class CommandLineBuild
{
#region Constants
private const string PublishPathCommand = "-out";
private const string BuildNumberCommand = "-buildNumber";
private const string BuildVersionCommand = "-buildVersion";
private const string BuildReporterCommand = "-reporter";
private const string BuildTargetCommand = "-target";
private const string AndroidTextureCompressionCommand = "-textureCompression";
private const char CommandStartCharacter = '-';
#endregion
#region Methods
/// <summary>
/// Performs the command line build by using the passed command line arguments.
/// </summary>
private static void Build()
{
string publishPath, buildNumber, buildVersion, buildReporter, buildTarget, androidTextureCompression;
Dictionary<string, string> commandToValueDictionary = GetCommandLineArguments();
// Extract our arguments from dictionary
commandToValueDictionary.TryGetValue(PublishPathCommand, out publishPath);
commandToValueDictionary.TryGetValue(BuildNumberCommand, out buildNumber);
commandToValueDictionary.TryGetValue(BuildVersionCommand, out buildVersion);
commandToValueDictionary.TryGetValue(BuildReporterCommand, out buildReporter);
commandToValueDictionary.TryGetValue(BuildTargetCommand, out buildTarget);
commandToValueDictionary.TryGetValue(AndroidTextureCompressionCommand, out androidTextureCompression);
if (!string.IsNullOrEmpty(buildReporter)) BuildReporter.Current = BuildReporter.CreateReporterByName(buildReporter);
try
{
if (!string.IsNullOrEmpty(buildNumber))
{
BundleVersionResolver.BuildNumber = int.Parse(buildNumber);
}
if (!string.IsNullOrEmpty(buildVersion))
{
BundleVersionResolver.PrettyVersion = buildVersion;
}
if (string.IsNullOrEmpty(buildTarget))
{
BuildReporter.Current.Log("No target was specified for this build.", BuildReporter.MessageSeverity.Error);
}
else
{
BuildTarget parsedBuildTarget = (BuildTarget)Enum.Parse(typeof(BuildTarget), buildTarget);
MobileTextureSubtarget? parsedTextureSubtarget = null;
if (!string.IsNullOrEmpty(androidTextureCompression)) parsedTextureSubtarget = (MobileTextureSubtarget)Enum.Parse(typeof(MobileTextureSubtarget), androidTextureCompression);
BundleVersionResolver.Setup(parsedBuildTarget);
Builder.Build(parsedBuildTarget, publishPath, parsedTextureSubtarget);
}
}
catch (Exception e)
{
BuildReporter.Current.Log(e.Message, BuildReporter.MessageSeverity.Error);
}
}
/// <summary>
/// Gets all the command line arguments relevant to the build process. All commands that don't have a value after them have their value at string.Empty.
/// </summary>
private static Dictionary<string, string> GetCommandLineArguments()
{
Dictionary<string, string> commandToValueDictionary = new Dictionary<string, string>();
string[] args = System.Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
{
if (args[i].StartsWith(CommandStartCharacter.ToString()))
{
string command = args[i];
string value = string.Empty;
if (i < args.Length - 1 && !args[i + 1].StartsWith(CommandStartCharacter.ToString()))
{
value = args[i + 1];
i++;
}
if (!commandToValueDictionary.ContainsKey(command))
{
commandToValueDictionary.Add(command, value);
}
else
{
BuildReporter.Current.Log("Duplicate command line argument " + command, BuildReporter.MessageSeverity.Warning);
}
}
}
return commandToValueDictionary;
}
#endregion
}
}