From a63fcb36748963cb9c189a40e72899368d2d0ce9 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Mon, 30 Oct 2023 20:47:24 -0400 Subject: [PATCH] fix(hr): restrict XamlReader to mobile targets only --- .../ClientHotReloadProcessor.Agent.cs | 9 ++++---- .../ClientHotReloadProcessor.PartialReload.cs | 4 ++-- .../ClientHotReloadProcessor.Xaml.cs | 22 +++++++++++++++++++ .../HotReload/ClientHotReloadProcessor.cs | 5 +++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Agent.cs b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Agent.cs index 0c1c16ef626f..8e57e57e4915 100644 --- a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Agent.cs +++ b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Agent.cs @@ -23,12 +23,13 @@ partial class ClientHotReloadProcessor { private bool _linkerEnabled; private HotReloadAgent? _agent; - private bool _metadataUpdatesEnabled; + private bool _serverMetadataUpdatesEnabled; private static ClientHotReloadProcessor? _instance; private readonly TaskCompletionSource _hotReloadWorkloadSpaceLoaded = new(); private void WorkspaceLoadResult(HotReloadWorkspaceLoadResult hotReloadWorkspaceLoadResult) => _hotReloadWorkloadSpaceLoaded.SetResult(hotReloadWorkspaceLoadResult.WorkspaceInitialized); + /// /// Waits for the server's hot reload workspace to be loaded /// @@ -42,7 +43,7 @@ partial void InitializeMetadataUpdater() { _instance = this; - _metadataUpdatesEnabled = BuildMetadataUpdatesEnabled(); + _serverMetadataUpdatesEnabled = BuildServerMetadataUpdatesEnabled(); _linkerEnabled = string.Equals(Environment.GetEnvironmentVariable("UNO_BOOTSTRAP_LINKER_ENABLED"), "true", StringComparison.OrdinalIgnoreCase); @@ -63,7 +64,7 @@ partial void InitializeMetadataUpdater() }); } - private bool BuildMetadataUpdatesEnabled() + private bool BuildServerMetadataUpdatesEnabled() { var unoRuntimeIdentifier = GetMSBuildProperty("UnoRuntimeIdentifier"); //var targetFramework = GetMSBuildProperty("TargetFramework"); @@ -93,7 +94,7 @@ private bool BuildMetadataUpdatesEnabled() if (this.Log().IsEnabled(LogLevel.Trace)) { - this.Log().Trace($"MetadataUpdates Enabled:{enabled} DebuggerAttached:{Debugger.IsAttached} BuildingInsideVS: {buildingInsideVisualStudio} unorid: {unoRuntimeIdentifier}"); + this.Log().Trace($"ServerMetadataUpdates Enabled:{enabled} DebuggerAttached:{Debugger.IsAttached} BuildingInsideVS: {buildingInsideVisualStudio} unorid: {unoRuntimeIdentifier}"); } return enabled; diff --git a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.PartialReload.cs b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.PartialReload.cs index bb8dcb191492..2331f39afd29 100644 --- a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.PartialReload.cs +++ b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.PartialReload.cs @@ -52,8 +52,8 @@ private void InitializePartialReload() this.Log().Trace($"Partial Hot Reload Enabled:{_supportsLightweightHotReload} " + $"unoRuntimeIdentifier:{unoRuntimeIdentifier} " + $"targetFramework:{targetFramework} " + - $"buildingInsideVisualStudio:{targetFramework}" + - $"debuggerAttached: {Debugger.IsAttached}"); + $"buildingInsideVisualStudio:{targetFramework} " + + $"debuggerAttached:{Debugger.IsAttached}"); } _mappedTypes = _supportsLightweightHotReload diff --git a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Xaml.cs b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Xaml.cs index 2e5b3b352436..4e722877d14c 100644 --- a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Xaml.cs +++ b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.Xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; @@ -38,6 +39,27 @@ namespace Uno.UI.RemoteControl.HotReload partial class ClientHotReloadProcessor { private string? _lastUpdatedFilePath; + private bool _supportsXamlReader; + + private void InitializeXamlReader() + { + var targetFramework = GetMSBuildProperty("TargetFramework"); + var buildingInsideVisualStudio = GetMSBuildProperty("BuildingInsideVisualStudio").Equals("true", StringComparison.OrdinalIgnoreCase); + + // As of VS 17.8, the only target which supports + // + // Disabled until https://github.com/dotnet/runtime/issues/93860 is fixed + // + _supportsXamlReader = (targetFramework.Contains("-android", StringComparison.OrdinalIgnoreCase) + || targetFramework.Contains("-ios", StringComparison.OrdinalIgnoreCase) + || targetFramework.Contains("-maccatalyst", StringComparison.OrdinalIgnoreCase)); + + if (this.Log().IsEnabled(LogLevel.Trace)) + { + this.Log().Trace($"XamlReader Hot Reload Enabled:{_supportsXamlReader} " + + $"targetFramework:{targetFramework}"); + } + } private void ReloadFileWithXamlReader(FileReload fileReload) { diff --git a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.cs b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.cs index 8064dd77df2f..60a67b86c0af 100644 --- a/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.cs +++ b/src/Uno.UI.RemoteControl/HotReload/ClientHotReloadProcessor.cs @@ -65,7 +65,7 @@ public async Task ProcessFrame(Messages.Frame frame) private async Task ProcessFileReload(HotReload.Messages.FileReload fileReload) { - if ((!_supportsLightweightHotReload && !_metadataUpdatesEnabled) || _forcedHotReloadMode == HotReloadMode.XamlReader) + if ((!_supportsLightweightHotReload && !_serverMetadataUpdatesEnabled && _supportsXamlReader) || _forcedHotReloadMode == HotReloadMode.XamlReader) { ReloadFileWithXamlReader(fileReload); } @@ -104,8 +104,9 @@ private async Task ConfigureServer() ConfigureHotReloadMode(); InitializeMetadataUpdater(); InitializePartialReload(); + InitializeXamlReader(); - ConfigureServer message = new(_projectPath, _xamlPaths, GetMetadataUpdateCapabilities(), _metadataUpdatesEnabled, config.MSBuildProperties); + ConfigureServer message = new(_projectPath, _xamlPaths, GetMetadataUpdateCapabilities(), _serverMetadataUpdatesEnabled, config.MSBuildProperties); await _rcClient.SendMessage(message); }