From 7a6eb33bbde99e18c559e071bf06106f407e79ce Mon Sep 17 00:00:00 2001 From: Stanislav Ryzhov Date: Wed, 19 Oct 2022 12:56:51 +0300 Subject: [PATCH] Automatically update link.xml by LinkerProcessor --- .../Editor/LinkerProcessor.cs | 31 ++++++++++ .../Editor/LinkerProcessor.cs.meta | 3 + .../Editor/SetupSteps/LinkXMLStep.cs | 61 ------------------- .../Editor/SetupSteps/LinkXMLStep.cs.meta | 11 ---- 4 files changed, 34 insertions(+), 72 deletions(-) create mode 100644 com.onesignal.unity.core/Editor/LinkerProcessor.cs create mode 100644 com.onesignal.unity.core/Editor/LinkerProcessor.cs.meta delete mode 100644 com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs delete mode 100644 com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs.meta diff --git a/com.onesignal.unity.core/Editor/LinkerProcessor.cs b/com.onesignal.unity.core/Editor/LinkerProcessor.cs new file mode 100644 index 000000000..88d6c40b3 --- /dev/null +++ b/com.onesignal.unity.core/Editor/LinkerProcessor.cs @@ -0,0 +1,31 @@ +using System.IO; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; +using UnityEditor.UnityLinker; + +namespace OneSignalSDK +{ + public class LinkerProcessor : IUnityLinkerProcessor + { + private const string XmlGuid = "b7ef312023e648bebcd07161e965b0d6"; + + public int callbackOrder => 0; + + public string GenerateAdditionalLinkXmlFile(BuildReport report, UnityLinkerBuildPipelineData data) + { + var assetPath = AssetDatabase.GUIDToAssetPath(XmlGuid); + return Path.GetFullPath(assetPath); + } + +#if !UNITY_2021_1_OR_NEWER + public void OnBeforeRun(BuildReport report, UnityLinkerBuildPipelineData data) + { + } + + public void OnAfterRun(BuildReport report, UnityLinkerBuildPipelineData data) + { + } +#endif + } +} diff --git a/com.onesignal.unity.core/Editor/LinkerProcessor.cs.meta b/com.onesignal.unity.core/Editor/LinkerProcessor.cs.meta new file mode 100644 index 000000000..6f48a3ef1 --- /dev/null +++ b/com.onesignal.unity.core/Editor/LinkerProcessor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4fe5d4d2faee441ba4565ff6f9c1e10f +timeCreated: 1666172587 \ No newline at end of file diff --git a/com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs b/com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs deleted file mode 100644 index 2f2b495f1..000000000 --- a/com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Modified MIT License - * - * Copyright 2022 OneSignal - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * 1. The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * 2. All copies of substantial portions of the Software may only be used in connection - * with services provided by OneSignal. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using System.IO; - -namespace OneSignalSDK { -/// -/// Makes sure that the link.xml file for the OneSignal SDK exists -/// -public class LinkXMLStep : OneSignalSetupStep { - public override string Summary - => "Generate link.xml"; - - public override string Details - => $"Generates the link.xml file at {_destinationPath} which is needed to prevent OneSignal classes from being " + - $"removed by Unity's code stripping."; - - public override bool IsRequired - => true; - - protected override bool _getIsStepCompleted() - => File.Exists(_destinationPath); - - protected override void _runStep() { - if (!Directory.Exists(_destinationDir)) - Directory.CreateDirectory(_destinationDir); - - if (!File.Exists(_destinationPath)) - File.Copy(_sourcePath, _destinationPath); - } - - private static readonly string _destinationDir = Path.Combine("Assets", "OneSignal"); - - private static readonly string _sourcePath = Path.Combine("Packages", "com.onesignal.unity.core", "Editor", "link.xml"); - private static readonly string _destinationPath = Path.Combine(_destinationDir, "link.xml"); - } -} \ No newline at end of file diff --git a/com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs.meta b/com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs.meta deleted file mode 100644 index eb0846354..000000000 --- a/com.onesignal.unity.core/Editor/SetupSteps/LinkXMLStep.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c3594193b5f2443239ebf6cd22682b81 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: