Skip to content

Commit 717fd0a

Browse files
committedFeb 3, 2021
Reduce hardcoded target name strings
Replace hardcoded target names like `Unity-iPhone` and `UnityFrameworks` with properties. Change-Id: Ieac0078aed70c66f6246971a0b7bdb6bd2ab50d9
1 parent 25e13ef commit 717fd0a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed
 

‎source/IOSResolver/src/IOSResolver.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,29 @@ internal static bool MultipleXcodeTargetsSupported {
808808
}
809809
}
810810

811+
/// <summary>
812+
/// Name of the Xcode main target generated by Unity.
813+
/// </summary>
814+
public static string XcodeMainTargetName {
815+
get {
816+
// NOTE: Unity-iPhone is hard coded in UnityEditor.iOS.Xcode.PBXProject and will no
817+
// longer be exposed via GetUnityTargetName(). It hasn't changed in many years though
818+
// so we'll use this constant as a relatively safe default.
819+
return MultipleXcodeTargetsSupported ? "Unity-iPhone" :
820+
(string)VersionHandler.InvokeStaticMethod(typeof(UnityEditor.iOS.Xcode.PBXProject),
821+
"GetUnityTargetName", null);
822+
}
823+
}
824+
825+
/// <summary>
826+
/// Name of the Xcode UnityFramework target generated by Unity 2019.3+
827+
/// </summary>
828+
public static string XcodeUnityFrameworkTargetName {
829+
get {
830+
return "UnityFramework";
831+
}
832+
}
833+
811834
/// <summary>
812835
/// Initialize the TARGET_NAME property.
813836
/// This will be "Unity-iPhone" in versions of Unity (2019.3+) that added support for using
@@ -818,9 +841,7 @@ private static string InitializeTargetName() {
818841
// NOTE: Unity-iPhone is hard coded in UnityEditor.iOS.Xcode.PBXProject and will soon longer
819842
// be exposed via GetUnityTargetName(). It hasn't changed in many years though so we'll use
820843
// this constant as a relatively safe default for users of the TARGET_NAME variable.
821-
TARGET_NAME = MultipleXcodeTargetsSupported ? "Unity-iPhone" :
822-
(string)VersionHandler.InvokeStaticMethod(typeof(UnityEditor.iOS.Xcode.PBXProject),
823-
"GetUnityTargetName", null);
844+
TARGET_NAME = XcodeMainTargetName;
824845
return TARGET_NAME;
825846
}
826847

@@ -1802,7 +1823,7 @@ public static IEnumerable<string> XcodeTargetNames {
18021823
get {
18031824
// Return hard coded names in the UnityEditor.iOS.Xcode.PBXProject DLL.
18041825
return MultipleXcodeTargetsSupported ?
1805-
new List<string>() { "UnityFramework" } :
1826+
new List<string>() { XcodeUnityFrameworkTargetName } :
18061827
new List<string>() { InitializeTargetName() };
18071828
}
18081829
}
@@ -1954,7 +1975,7 @@ private static void ParseUnityDeps(string unityPodfilePath) {
19541975
continue;
19551976
}
19561977
// TODO: Properly support multiple targets.
1957-
if (line.StartsWith("target 'Unity-iPhone' do")) {
1978+
if (line.StartsWith(String.Format("target '{0}' do", XcodeMainTargetName))) {
19581979
capturingPodsDepth++;
19591980
continue;
19601981
}
@@ -2074,7 +2095,7 @@ public static void GenPodfile(BuildTarget buildTarget,
20742095
}
20752096

20762097
if (MultipleXcodeTargetsSupported && PodfileAlwaysAddMainTarget) {
2077-
file.WriteLine(String.Format("target '{0}' do", "Unity-iPhone"));
2098+
file.WriteLine(String.Format("target '{0}' do", XcodeMainTargetName));
20782099
bool allowPodsInMultipleTargets = PodfileAllowPodsInMultipleTargets;
20792100
int podAdded = 0;
20802101
foreach(var pod in pods.Values) {

‎source/IOSResolver/src/IOSResolverSettingsDialog.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public void OnGUI() {
222222
GUILayout.EndHorizontal();
223223

224224
GUILayout.Label("Add the following lines to Podfile.");
225-
GUILayout.Label(" target 'Unity-iPhone' do\n" +
226-
" end");
225+
GUILayout.Label(String.Format(" target '{0}' do\n" +
226+
" end", IOSResolver.XcodeMainTargetName));
227227

228228
if (settings.podfileAlwaysAddMainTarget) {
229229
GUILayout.BeginHorizontal();

0 commit comments

Comments
 (0)
Please sign in to comment.