diff --git a/Editor/BuildProcessors/CheckSettings.cs b/Editor/BuildProcessors/CheckSettings.cs index a5840bc..994683b 100644 --- a/Editor/BuildProcessors/CheckSettings.cs +++ b/Editor/BuildProcessors/CheckSettings.cs @@ -1,8 +1,10 @@ using HybridCLR.Editor.Settings; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using UnityEditor; using UnityEditor.Build; @@ -16,6 +18,8 @@ namespace HybridCLR.Editor.BuildProcessors { public int callbackOrder => 0; + public static bool DisableMethodBridgeDevelopmentFlagChecking { get; set; } + public void OnPreprocessBuild(BuildReport report) { HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings; @@ -67,6 +71,24 @@ namespace HybridCLR.Editor.BuildProcessors Debug.LogWarning("[CheckSettings] No hot update modules configured in HybridCLRSettings"); } + if (!DisableMethodBridgeDevelopmentFlagChecking) + { + string methodBridgeFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.cpp"; + var match = Regex.Match(File.ReadAllText(methodBridgeFile), @"// DEVELOPMENT=(\d)"); + if (match.Success) + { + int developmentFlagInMethodBridge = int.Parse(match.Groups[1].Value); + int developmentFlagInEditorSettings = EditorUserBuildSettings.development ? 1 : 0; + if (developmentFlagInMethodBridge != developmentFlagInEditorSettings) + { + Debug.LogError($"[CheckSettings] MethodBridge.cpp DEVELOPMENT flag:{developmentFlagInMethodBridge} is inconsistent with EditorUserBuildSettings.development:{developmentFlagInEditorSettings}. Please run 'HybridCLR/Generate/All' before building."); + } + } + else + { + Debug.LogError("[CheckSettings] MethodBridge.cpp DEVELOPMENT flag not found. Please run 'HybridCLR/Generate/All' before building."); + } + } } } } diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index fde1084..ab8f365 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -38,6 +38,7 @@ namespace HybridCLR.Editor.Commands TemplateCode = templateCode, OutputFile = outputFile, GenericMethods = analyzer.GenericMethods, + Development = EditorUserBuildSettings.development, }); g.PrepareMethods(); diff --git a/Editor/Commands/StripAOTDllCommand.cs b/Editor/Commands/StripAOTDllCommand.cs index 31ab3cd..46672eb 100644 --- a/Editor/Commands/StripAOTDllCommand.cs +++ b/Editor/Commands/StripAOTDllCommand.cs @@ -1,4 +1,5 @@ -using HybridCLR.Editor.Installer; +using HybridCLR.Editor.BuildProcessors; +using HybridCLR.Editor.Installer; using System; using System.Collections.Generic; using System.IO; @@ -85,99 +86,109 @@ namespace HybridCLR.Editor.Commands bool oldOpenHarmonyProj = EditorUserBuildSettings.exportAsOpenHarmonyProject; #endif bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly; - EditorUserBuildSettings.buildScriptsOnly = true; - string location = GetLocationPathName(outputPath, target); string oldBuildLocation = EditorUserBuildSettings.GetBuildLocation(target); - EditorUserBuildSettings.SetBuildLocation(target, location); - - switch (target) + try { - case BuildTarget.StandaloneWindows: - case BuildTarget.StandaloneWindows64: + CheckSettings.DisableMethodBridgeDevelopmentFlagChecking = true; + EditorUserBuildSettings.buildScriptsOnly = true; + + string location = GetLocationPathName(outputPath, target); + EditorUserBuildSettings.SetBuildLocation(target, location); + + switch (target) { -#if UNITY_EDITOR_WIN - UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true; -#endif + case BuildTarget.StandaloneWindows: + case BuildTarget.StandaloneWindows64: + { + #if UNITY_EDITOR_WIN + UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true; + #endif + break; + } + case BuildTarget.StandaloneOSX: + { + #if UNITY_EDITOR_OSX + UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true; + #endif break; + } + #if TUANJIE_2022_3_OR_NEWER + case BuildTarget.HMIAndroid: + #endif + case BuildTarget.Android: + { + EditorUserBuildSettings.exportAsGoogleAndroidProject = true; + break; + } + #if TUANJIE_2022_3_OR_NEWER + case BuildTarget.OpenHarmony: + { + EditorUserBuildSettings.exportAsOpenHarmonyProject = true; + break; + } + #endif } - case BuildTarget.StandaloneOSX: + + Debug.Log($"GenerateStripedAOTDlls build option:{buildOptions}"); + + BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions() { -#if UNITY_EDITOR_OSX - UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true; -#endif - break; - } -#if TUANJIE_2022_3_OR_NEWER - case BuildTarget.HMIAndroid: -#endif - case BuildTarget.Android: + scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(), + locationPathName = location, + options = buildOptions, + target = target, + targetGroup = BuildPipeline.GetBuildTargetGroup(target), + }; + + var report = BuildPipeline.BuildPlayer(buildPlayerOptions); + + + + if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded) { - EditorUserBuildSettings.exportAsGoogleAndroidProject = true; - break; + throw new Exception("GenerateStripedAOTDlls failed"); } -#if TUANJIE_2022_3_OR_NEWER - case BuildTarget.OpenHarmony: - { - EditorUserBuildSettings.exportAsOpenHarmonyProject = true; - break; - } -#endif } - - Debug.Log($"GenerateStripedAOTDlls build option:{buildOptions}"); - - BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions() + finally { - scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(), - locationPathName = location, - options = buildOptions, - target = target, - targetGroup = BuildPipeline.GetBuildTargetGroup(target), - }; + CheckSettings.DisableMethodBridgeDevelopmentFlagChecking = false; + EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly; + EditorUserBuildSettings.SetBuildLocation(target, oldBuildLocation); - var report = BuildPipeline.BuildPlayer(buildPlayerOptions); - - EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly; - EditorUserBuildSettings.SetBuildLocation(target, oldBuildLocation); - - switch (target) - { - case BuildTarget.StandaloneWindows: - case BuildTarget.StandaloneWindows64: + switch (target) + { + case BuildTarget.StandaloneWindows: + case BuildTarget.StandaloneWindows64: { #if UNITY_EDITOR_WIN - UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution; + UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution; #endif break; } - case BuildTarget.StandaloneOSX: + case BuildTarget.StandaloneOSX: { #if UNITY_EDITOR_OSX - UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution; + UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution; #endif break; } #if TUANJIE_2022_3_OR_NEWER - case BuildTarget.HMIAndroid: + case BuildTarget.HMIAndroid: #endif - case BuildTarget.Android: - { - EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj; - break; - } + case BuildTarget.Android: + { + EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj; + break; + } #if TUANJIE_2022_3_OR_NEWER - case BuildTarget.OpenHarmony: - { - EditorUserBuildSettings.exportAsOpenHarmonyProject = oldOpenHarmonyProj; - break; - } + case BuildTarget.OpenHarmony: + { + EditorUserBuildSettings.exportAsOpenHarmonyProject = oldOpenHarmonyProj; + break; + } #endif - } - - if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded) - { - throw new Exception("GenerateStripedAOTDlls failed"); + } } Debug.Log($"GenerateStripedAOTDlls target:{target} path:{outputPath}"); } diff --git a/Editor/MethodBridge/Generator.cs b/Editor/MethodBridge/Generator.cs index 39451ad..a7f1954 100644 --- a/Editor/MethodBridge/Generator.cs +++ b/Editor/MethodBridge/Generator.cs @@ -25,6 +25,8 @@ namespace HybridCLR.Editor.MethodBridge public string OutputFile { get; set; } public IReadOnlyCollection GenericMethods { get; set; } + + public bool Development { get; set; } } private readonly List _genericMethods; @@ -33,6 +35,8 @@ namespace HybridCLR.Editor.MethodBridge private readonly string _outputFile; + private readonly bool _development; + private readonly TypeCreator _typeCreator; private readonly HashSet _managed2nativeMethodSet = new HashSet(); @@ -50,6 +54,7 @@ namespace HybridCLR.Editor.MethodBridge _templateCode = options.TemplateCode; _outputFile = options.OutputFile; _typeCreator = new TypeCreator(); + _development = options.Development; } private readonly Dictionary _sig2Types = new Dictionary(); @@ -391,6 +396,10 @@ namespace HybridCLR.Editor.MethodBridge List lines = new List(20_0000); + lines.Add("\n"); + lines.Add($"// DEVELOPMENT={(_development ? 1 : 0)}"); + lines.Add("\n"); + var classInfos = new List(); var classTypeSet = new HashSet(); foreach (var type in structTypes)