release: 1.4.17

This commit is contained in:
2026-07-01 18:09:08 +08:00
parent 0958e1569a
commit 784bc7c0ee
6 changed files with 298 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Topon_Adapter.Editor
@@ -13,11 +15,15 @@ namespace Topon_Adapter.Editor
public bool forceVerbtoUtilVersion = true;
public string verbtoUtilDependency = ToponBuildSettingsStore.DefaultVerbtoUtilDependency;
public bool stripResolvedDebuggerArtifacts = true;
public bool enableIOSDebuggerUI = false;
public string iosDebuggerPodVersion = ToponBuildSettingsStore.DefaultIOSDebuggerPodVersion;
}
internal static class ToponBuildSettingsStore
{
public const string DefaultVerbtoUtilDependency = "com.verbto.tools:util:1.1.3";
public const string IOSDebuggerPodName = "AnyThinkDebugUISDK";
public const string DefaultIOSDebuggerPodVersion = "1.0.7";
private const string ActiveBuildSessionKey = "Commercialization.Topon.ActiveBuildSettings";
private const string SettingsFileSuffix = "_topon_build_settings.json";
@@ -47,6 +53,16 @@ namespace Topon_Adapter.Editor
return settings.verbtoUtilDependency.Trim();
}
public static string GetIOSDebuggerPodVersion(ToponBuildSettings settings)
{
if (settings == null || string.IsNullOrWhiteSpace(settings.iosDebuggerPodVersion))
{
return DefaultIOSDebuggerPodVersion;
}
return settings.iosDebuggerPodVersion.Trim();
}
public static ToponBuildSettings LoadForProfileName(string profileName, string repositoryRoot)
{
var settings = CreateDefault();
@@ -298,7 +314,9 @@ namespace Topon_Adapter.Editor
enableDebuggerUI = settings.enableDebuggerUI,
forceVerbtoUtilVersion = settings.forceVerbtoUtilVersion,
verbtoUtilDependency = GetVerbtoUtilDependency(settings),
stripResolvedDebuggerArtifacts = settings.stripResolvedDebuggerArtifacts
stripResolvedDebuggerArtifacts = settings.stripResolvedDebuggerArtifacts,
enableIOSDebuggerUI = settings.enableIOSDebuggerUI,
iosDebuggerPodVersion = GetIOSDebuggerPodVersion(settings)
};
}
@@ -310,6 +328,7 @@ namespace Topon_Adapter.Editor
}
settings.verbtoUtilDependency = NormalizeDependency(settings.verbtoUtilDependency);
settings.iosDebuggerPodVersion = NormalizeIOSDebuggerPodVersion(settings.iosDebuggerPodVersion);
}
private static string NormalizeDependency(string dependency)
@@ -322,6 +341,16 @@ namespace Topon_Adapter.Editor
return dependency.Trim();
}
private static string NormalizeIOSDebuggerPodVersion(string version)
{
if (string.IsNullOrWhiteSpace(version))
{
return DefaultIOSDebuggerPodVersion;
}
return version.Trim();
}
private static string GetVersionFromDependency(string dependency)
{
dependency = NormalizeDependency(dependency);
@@ -386,4 +415,196 @@ namespace Topon_Adapter.Editor
return new string(chars);
}
}
#if UNITY_IOS || UNITY_IPHONE
internal static class ToponIOSDebuggerDependencyPostProcessor
{
private const string Tag = "[TopOn Build]";
[PostProcessBuild(int.MaxValue)]
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
{
if (buildTarget != BuildTarget.iOS)
{
return;
}
var settings = ToponBuildSettingsStore.GetActiveForCurrentBuild();
try
{
ProcessExportedProject(buildPath, settings);
}
finally
{
ToponBuildSettingsStore.ClearActiveBuildSettings();
}
}
public static void ProcessExportedProject(string buildPath, ToponBuildSettings settings)
{
if (settings == null)
{
settings = ToponBuildSettingsStore.CreateDefault();
}
var podfilePath = Path.Combine(buildPath, "Podfile");
if (!File.Exists(podfilePath))
{
if (settings.enableIOSDebuggerUI)
{
Debug.LogWarning($"{Tag} Podfile not found, cannot add {ToponBuildSettingsStore.IOSDebuggerPodName}: {podfilePath}");
}
return;
}
var content = File.ReadAllText(podfilePath);
var updated = RewritePodfile(content, settings);
if (!string.Equals(content, updated, StringComparison.Ordinal))
{
File.WriteAllText(podfilePath, updated);
}
if (settings.enableIOSDebuggerUI)
{
Debug.Log($"{Tag} iOS DebugUI pod enabled: {ToponBuildSettingsStore.IOSDebuggerPodName} {ToponBuildSettingsStore.GetIOSDebuggerPodVersion(settings)}.");
}
else
{
Debug.Log($"{Tag} iOS DebugUI pod disabled for this build.");
}
}
private static string RewritePodfile(string content, ToponBuildSettings settings)
{
var newline = content.Contains("\r\n") ? "\r\n" : "\n";
var lines = new List<string>(content.Replace("\r\n", "\n").Replace('\r', '\n').Split('\n'));
for (var i = lines.Count - 1; i >= 0; i--)
{
if (IsDebuggerPodLine(lines[i]))
{
lines.RemoveAt(i);
}
}
if (settings.enableIOSDebuggerUI)
{
InsertDebuggerPod(lines, ToponBuildSettingsStore.GetIOSDebuggerPodVersion(settings));
}
return string.Join(newline, lines);
}
private static bool IsDebuggerPodLine(string line)
{
return Regex.IsMatch(line ?? string.Empty,
@"^\s*pod\s+['""]" + ToponBuildSettingsStore.IOSDebuggerPodName + @"['""]",
RegexOptions.CultureInvariant);
}
private static void InsertDebuggerPod(List<string> lines, string version)
{
var targetRange = FindTargetRange(lines, "UnityFramework");
if (targetRange.start < 0)
{
targetRange = FindTargetRange(lines, "Unity-iPhone");
}
if (targetRange.start >= 0)
{
var indent = ResolvePodIndent(lines, targetRange);
var podLine = $"{indent}pod '{ToponBuildSettingsStore.IOSDebuggerPodName}', '{version}'";
lines.Insert(ResolvePodInsertIndex(lines, targetRange), podLine);
return;
}
if (lines.Count > 0 && !string.IsNullOrWhiteSpace(lines[lines.Count - 1]))
{
lines.Add(string.Empty);
}
lines.Add("target 'UnityFramework' do");
lines.Add($" pod '{ToponBuildSettingsStore.IOSDebuggerPodName}', '{version}'");
lines.Add("end");
}
private static (int start, int end) FindTargetRange(List<string> lines, string targetName)
{
var targetPattern = new Regex(@"^\s*target\s+['""]" + Regex.Escape(targetName) + @"['""]\s+do\b",
RegexOptions.CultureInvariant);
for (var i = 0; i < lines.Count; i++)
{
if (!targetPattern.IsMatch(lines[i] ?? string.Empty))
{
continue;
}
var depth = 0;
for (var j = i; j < lines.Count; j++)
{
var line = StripComment(lines[j]);
if (Regex.IsMatch(line, @"\bdo\b", RegexOptions.CultureInvariant))
{
depth++;
}
if (Regex.IsMatch(line, @"^\s*end\s*$", RegexOptions.CultureInvariant))
{
depth--;
if (depth <= 0)
{
return (i, j);
}
}
}
return (i, lines.Count);
}
return (-1, -1);
}
private static int ResolvePodInsertIndex(List<string> lines, (int start, int end) targetRange)
{
var insertIndex = targetRange.start + 1;
for (var i = targetRange.start + 1; i < targetRange.end && i < lines.Count; i++)
{
if (Regex.IsMatch(lines[i] ?? string.Empty, @"^\s*pod\s+", RegexOptions.CultureInvariant))
{
insertIndex = i + 1;
}
}
return insertIndex;
}
private static string ResolvePodIndent(List<string> lines, (int start, int end) targetRange)
{
for (var i = targetRange.start + 1; i < targetRange.end && i < lines.Count; i++)
{
var match = Regex.Match(lines[i] ?? string.Empty, @"^(\s*)pod\s+", RegexOptions.CultureInvariant);
if (match.Success)
{
return match.Groups[1].Value;
}
}
var targetIndent = Regex.Match(lines[targetRange.start] ?? string.Empty, @"^(\s*)", RegexOptions.CultureInvariant).Value;
return targetIndent + " ";
}
private static string StripComment(string line)
{
if (string.IsNullOrEmpty(line))
{
return string.Empty;
}
var commentIndex = line.IndexOf('#');
return commentIndex >= 0 ? line.Substring(0, commentIndex) : line;
}
}
#endif
}