Skip to content

Commit

Permalink
fix(hr): restrict XamlReader to mobile targets only
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Oct 31, 2023
1 parent ec5cadc commit a63fcb3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> _hotReloadWorkloadSpaceLoaded = new();

private void WorkspaceLoadResult(HotReloadWorkspaceLoadResult hotReloadWorkspaceLoadResult)
=> _hotReloadWorkloadSpaceLoaded.SetResult(hotReloadWorkspaceLoadResult.WorkspaceInitialized);

/// <summary>
/// Waits for the server's hot reload workspace to be loaded
/// </summary>
Expand All @@ -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);

Expand All @@ -63,7 +64,7 @@ partial void InitializeMetadataUpdater()
});
}

private bool BuildMetadataUpdatesEnabled()
private bool BuildServerMetadataUpdatesEnabled()
{
var unoRuntimeIdentifier = GetMSBuildProperty("UnoRuntimeIdentifier");
//var targetFramework = GetMSBuildProperty("TargetFramework");
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a63fcb3

Please sign in to comment.