-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathNamedBuildTarget.cs
More file actions
172 lines (153 loc) · 7.03 KB
/
NamedBuildTarget.cs
File metadata and controls
172 lines (153 loc) · 7.03 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Linq;
namespace UnityEditor.Build
{
public readonly struct NamedBuildTarget : IEquatable<NamedBuildTarget>, IComparable<NamedBuildTarget>
{
private static readonly string[] k_ValidNames =
{
"",
"Standalone",
"Server",
"iPhone",
"Android",
"WebGL",
"Windows Store Apps",
"PS4",
"XboxOne",
"tvOS",
"Nintendo Switch",
"Stadia",
"CloudRendering",
"LinuxHeadlessSimulation",
"Lumin",
"GameCoreScarlett",
"GameCoreXboxOne",
"PS5",
"EmbeddedLinux",
"QNX",
};
public static readonly NamedBuildTarget Unknown = new NamedBuildTarget("");
public static readonly NamedBuildTarget Standalone = new NamedBuildTarget("Standalone");
public static readonly NamedBuildTarget Server = new NamedBuildTarget("Server");
public static readonly NamedBuildTarget iOS = new NamedBuildTarget("iPhone");
public static readonly NamedBuildTarget Android = new NamedBuildTarget("Android");
public static readonly NamedBuildTarget WebGL = new NamedBuildTarget("WebGL");
public static readonly NamedBuildTarget WindowsStoreApps = new NamedBuildTarget("Windows Store Apps");
public static readonly NamedBuildTarget PS4 = new NamedBuildTarget("PS4");
public static readonly NamedBuildTarget PS5 = new NamedBuildTarget("PS5");
public static readonly NamedBuildTarget XboxOne = new NamedBuildTarget("XboxOne");
public static readonly NamedBuildTarget tvOS = new NamedBuildTarget("tvOS");
public static readonly NamedBuildTarget NintendoSwitch = new NamedBuildTarget("Nintendo Switch");
[System.Obsolete("Stadia has been removed in 2023.1")]
public static readonly NamedBuildTarget Stadia = new NamedBuildTarget("Stadia");
public static readonly NamedBuildTarget LinuxHeadlessSimulation = new NamedBuildTarget("LinuxHeadlessSimulation");
[System.Obsolete("CloudRendering is deprecated, please use LinuxHeadlessSimulation (UnityUpgradable) -> LinuxHeadlessSimulation", false)]
public static readonly NamedBuildTarget CloudRendering = LinuxHeadlessSimulation;
public static readonly NamedBuildTarget EmbeddedLinux = new NamedBuildTarget("EmbeddedLinux");
public static readonly NamedBuildTarget QNX = new NamedBuildTarget("QNX");
public string TargetName { get; }
internal NamedBuildTarget(string targetName)
{
if (!k_ValidNames.Contains(targetName))
{
throw new ArgumentException($"'{targetName}' is not a valid build target name");
}
TargetName = targetName;
}
public BuildTargetGroup ToBuildTargetGroup()
{
switch (TargetName)
{
case "Server":
return BuildTargetGroup.Standalone;
default:
return BuildPipeline.GetBuildTargetGroupByName(TargetName);
}
}
public static NamedBuildTarget FromBuildTargetGroup(BuildTargetGroup buildTargetGroup)
{
switch (buildTargetGroup)
{
case BuildTargetGroup.Unknown:
return NamedBuildTarget.Unknown;
case BuildTargetGroup.Standalone:
return NamedBuildTarget.Standalone;
case BuildTargetGroup.iOS:
return NamedBuildTarget.iOS;
case BuildTargetGroup.Android:
return NamedBuildTarget.Android;
case BuildTargetGroup.WebGL:
return NamedBuildTarget.WebGL;
case BuildTargetGroup.WSA:
return NamedBuildTarget.WindowsStoreApps;
case BuildTargetGroup.PS4:
return NamedBuildTarget.PS4;
case BuildTargetGroup.XboxOne:
return NamedBuildTarget.XboxOne;
case BuildTargetGroup.tvOS:
return NamedBuildTarget.tvOS;
case BuildTargetGroup.Switch:
return NamedBuildTarget.NintendoSwitch;
case BuildTargetGroup.LinuxHeadlessSimulation:
return NamedBuildTarget.LinuxHeadlessSimulation;
case BuildTargetGroup.EmbeddedLinux:
return NamedBuildTarget.EmbeddedLinux;
case BuildTargetGroup.QNX:
return NamedBuildTarget.QNX;
// Build targets that are not explicitly listed
case BuildTargetGroup.GameCoreXboxSeries:
return new NamedBuildTarget("GameCoreScarlett");
case BuildTargetGroup.GameCoreXboxOne:
return new NamedBuildTarget("GameCoreXboxOne");
case BuildTargetGroup.PS5:
return new NamedBuildTarget("PS5");
}
throw new ArgumentException($"There is no a valid NamedBuildTarget for BuildTargetGroup '{buildTargetGroup}'");
}
// TODO: We shouldn't be assuming that the namedBuildTarget can be extracted from the
// active settings. This should be passed through the callstack instead when building.
// We will need to use BuildTargetSelection (BuildTarget + Subtarget) that is in the cpp side.
// For now this fixes an issue where Dedicated Server compiles with the Standalone settings.
internal static NamedBuildTarget FromActiveSettings(BuildTarget target)
{
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
if (buildTargetGroup == BuildTargetGroup.Standalone && (StandaloneBuildSubtarget)EditorUserBuildSettings.GetActiveSubtargetFor(target) == StandaloneBuildSubtarget.Server)
{
return NamedBuildTarget.Server;
}
return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
}
public static bool operator==(NamedBuildTarget lhs, NamedBuildTarget rhs)
{
return lhs.Equals(rhs);
}
public static bool operator!=(NamedBuildTarget lhs, NamedBuildTarget rhs)
{
return !lhs.Equals(rhs);
}
public override int GetHashCode()
{
return TargetName.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
return Equals((NamedBuildTarget)obj);
}
public bool Equals(NamedBuildTarget other)
{
return TargetName == other.TargetName;
}
public int CompareTo(NamedBuildTarget other)
{
return TargetName.CompareTo(other.TargetName);
}
}
}