From 57de61cdf4ef4acf2627eacc8642da60e09f03ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Laban?= Date: Sun, 2 Mar 2025 22:30:22 -0500 Subject: [PATCH] Revert "Implemented a new generator to embedded XAML sources into application for Hot Reload (backport #19610)" --- .../Given_HotReloadEnabledInBuild.cs | 12 +- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 121 ------------- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 154 ---------------- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 128 -------------- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 128 -------------- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 122 ------------- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 119 ------------- .../XamlCodeGenerator_EmbeddedXamlSources.cs | 113 ------------ .../Content/Uno.UI.SourceGenerators.props | 1 - .../XamlCodeGeneration.XamlSources.cs | 164 ------------------ .../XamlGenerator/XamlCodeGeneration.cs | 12 +- .../XamlGenerator/XamlFileDefinition.cs | 15 +- .../XamlGenerator/XamlFileParser.cs | 9 +- 13 files changed, 15 insertions(+), 1083 deletions(-) delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SBUIIOFFE/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFEDT/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLS/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFRT/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFTLRD/XamlCodeGenerator_EmbeddedXamlSources.cs delete mode 100644 src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeGeneration.XamlSources.cs diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_HotReloadEnabledInBuild.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_HotReloadEnabledInBuild.cs index 9f76bf41f5e1..a8519c1b422c 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_HotReloadEnabledInBuild.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_HotReloadEnabledInBuild.cs @@ -312,10 +312,16 @@ public async Task SetOriginalSourceLocationIncludedInOutputForDependencyObjectsT """ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; - namespace TestRepro; - public sealed partial class MainPage : Page + + namespace TestRepro { - public MainPage() => InitializeComponent(); + public sealed partial class MainPage : Page + { + public MainPage() + { + this.InitializeComponent(); + } + } } """ } diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SBUIIOFFE/XamlCodeGenerator_EmbeddedXamlSources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SBUIIOFFE/XamlCodeGenerator_EmbeddedXamlSources.cs deleted file mode 100644 index f8827ab398cd..000000000000 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SBUIIOFFE/XamlCodeGenerator_EmbeddedXamlSources.cs +++ /dev/null @@ -1,121 +0,0 @@ -#nullable enable -// -using System; -using System.Collections.Generic; -using System.Threading; - -#pragma warning disable // Disable all warnings for this generated file - -// Register an embedded sources provider for Hot Reload -[assembly: global::System.Reflection.AssemblyMetadata("Uno.HotDesign.HotReloadEmbeddedXamlSourceFilesProvider", "MyProject.__Sources__.EmbeddedXamlSourcesProvider")] - -namespace MyProject.__Sources__; - -/// -/// Provides access to the embedded XAML sources -/// -/// -/// This class is used to provide the embedded XAML sources to the Hot Reload engine. -/// This is not intended to be used directly by application code. -/// WON'T BE GENERATED ON RELEASE BUILDS -/// -internal static class EmbeddedXamlSourcesProvider -{ - // key=absolute file path - private static IDictionary Getter)>? _XamlSources; - - // hash of all the paths - private static volatile string? _filesListHash; - - // get the current value of the update counter - private static volatile uint _updateCounter; - - // The content of this method only changes when the file list changes - private static IDictionary Getter)> EnsureInitialize() - { - const string currentListHash = "d6cd66944958ced0c513e0a04797b51d"; // that's the hash of all the paths, used to detect changes in the file list following a HR operation - - // Determine if the sources have been updated or not initialized yet - var previousHashList = _XamlSources; - var needsUpdate = previousHashList is null || _filesListHash != currentListHash; - - if (needsUpdate) - { - var xamlSources = new Dictionary Getter)>(1, StringComparer.OrdinalIgnoreCase); - - // Use method groups to avoid closure allocation and ensure no lambda is created, to allow proper HR support - xamlSources[NormalizePath(@"C:/Project/0/MainPage.xaml")] = (NormalizePath(@"C:/Project/0/MainPage.xaml"), GetSources_MainPage_d6cd66944958ced0c513e0a04797b51d); - - if (Interlocked.CompareExchange(ref _XamlSources, xamlSources, previousHashList) == previousHashList) - { - // The sources were updated successfully (no other thread modified them concurrently) - _filesListHash = currentListHash; - _updateCounter++; - } - } - - return _XamlSources; - } - - /// - /// Gets the current update counter, used to detect changes in the sources. - /// - /// - /// This counter is incremented each time a Hot Reload sources update is detected. - /// - public static uint UpdateCounter - { - get - { - EnsureInitialize(); - return _updateCounter; - } - } - - public static IReadOnlyList GetXamlFilesList() => [.. EnsureInitialize().Keys]; - - public static string? GetNormalizedFileName(string path) - { - // Will return the normalized path if the file exists, or null if it doesn't. - // (the returned value will be constant for the file and can be used in a dictionary using an ordinal comparer) - var normalizedPath = NormalizePath(path); - return EnsureInitialize().TryGetValue(normalizedPath, out var entry) ? entry.ActualPath : null; - } - - public static (string ActualPath, string Hash, string Payload)? GetXamlFile(string path) - { - var normalizedPath = NormalizePath(path); - if (EnsureInitialize().TryGetValue(normalizedPath, out var entry)) - { - var sources = entry.Getter(); - return (entry.ActualPath, sources.Hash, sources.Payload); - } - return null; - } - - private static string NormalizePath(string path) => path.Replace('\\', '/'); - - #region Sources for C:/Project/0/MainPage.xaml - private static (string hash, string payload) GetSources_MainPage_d6cd66944958ced0c513e0a04797b51d() - { - return ( - "b9972598331e683fbb77aea763a897b0b45bc3d6", // hash - """ - - - - - - - - """); - } - #endregion -} diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_EmbeddedXamlSources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_EmbeddedXamlSources.cs deleted file mode 100644 index f15ad32593a6..000000000000 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIIOFDOTAFE/XamlCodeGenerator_EmbeddedXamlSources.cs +++ /dev/null @@ -1,154 +0,0 @@ -#nullable enable -// -using System; -using System.Collections.Generic; -using System.Threading; - -#pragma warning disable // Disable all warnings for this generated file - -// Register an embedded sources provider for Hot Reload -[assembly: global::System.Reflection.AssemblyMetadata("Uno.HotDesign.HotReloadEmbeddedXamlSourceFilesProvider", "MyProject.__Sources__.EmbeddedXamlSourcesProvider")] - -namespace MyProject.__Sources__; - -/// -/// Provides access to the embedded XAML sources -/// -/// -/// This class is used to provide the embedded XAML sources to the Hot Reload engine. -/// This is not intended to be used directly by application code. -/// WON'T BE GENERATED ON RELEASE BUILDS -/// -internal static class EmbeddedXamlSourcesProvider -{ - // key=absolute file path - private static IDictionary Getter)>? _XamlSources; - - // hash of all the paths - private static volatile string? _filesListHash; - - // get the current value of the update counter - private static volatile uint _updateCounter; - - // The content of this method only changes when the file list changes - private static IDictionary Getter)> EnsureInitialize() - { - const string currentListHash = "d6cd66944958ced0c513e0a04797b51d"; // that's the hash of all the paths, used to detect changes in the file list following a HR operation - - // Determine if the sources have been updated or not initialized yet - var previousHashList = _XamlSources; - var needsUpdate = previousHashList is null || _filesListHash != currentListHash; - - if (needsUpdate) - { - var xamlSources = new Dictionary Getter)>(1, StringComparer.OrdinalIgnoreCase); - - // Use method groups to avoid closure allocation and ensure no lambda is created, to allow proper HR support - xamlSources[NormalizePath(@"C:/Project/0/MainPage.xaml")] = (NormalizePath(@"C:/Project/0/MainPage.xaml"), GetSources_MainPage_d6cd66944958ced0c513e0a04797b51d); - - if (Interlocked.CompareExchange(ref _XamlSources, xamlSources, previousHashList) == previousHashList) - { - // The sources were updated successfully (no other thread modified them concurrently) - _filesListHash = currentListHash; - _updateCounter++; - } - } - - return _XamlSources; - } - - /// - /// Gets the current update counter, used to detect changes in the sources. - /// - /// - /// This counter is incremented each time a Hot Reload sources update is detected. - /// - public static uint UpdateCounter - { - get - { - EnsureInitialize(); - return _updateCounter; - } - } - - public static IReadOnlyList GetXamlFilesList() => [.. EnsureInitialize().Keys]; - - public static string? GetNormalizedFileName(string path) - { - // Will return the normalized path if the file exists, or null if it doesn't. - // (the returned value will be constant for the file and can be used in a dictionary using an ordinal comparer) - var normalizedPath = NormalizePath(path); - return EnsureInitialize().TryGetValue(normalizedPath, out var entry) ? entry.ActualPath : null; - } - - public static (string ActualPath, string Hash, string Payload)? GetXamlFile(string path) - { - var normalizedPath = NormalizePath(path); - if (EnsureInitialize().TryGetValue(normalizedPath, out var entry)) - { - var sources = entry.Getter(); - return (entry.ActualPath, sources.Hash, sources.Payload); - } - return null; - } - - private static string NormalizePath(string path) => path.Replace('\\', '/'); - - #region Sources for C:/Project/0/MainPage.xaml - private static (string hash, string payload) GetSources_MainPage_d6cd66944958ced0c513e0a04797b51d() - { - return ( - "346ee2c4a3294fdba50b4b5daaa042583c405e7a", // hash - """ - - - - - - - - - - - """); - } - #endregion -} diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_EmbeddedXamlSources.cs b/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_EmbeddedXamlSources.cs deleted file mode 100644 index 5de5cbfefd94..000000000000 --- a/src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/SOSLIOFPLR/XamlCodeGenerator_EmbeddedXamlSources.cs +++ /dev/null @@ -1,128 +0,0 @@ -#nullable enable -// -using System; -using System.Collections.Generic; -using System.Threading; - -#pragma warning disable // Disable all warnings for this generated file - -// Register an embedded sources provider for Hot Reload -[assembly: global::System.Reflection.AssemblyMetadata("Uno.HotDesign.HotReloadEmbeddedXamlSourceFilesProvider", "MyProject.__Sources__.EmbeddedXamlSourcesProvider")] - -namespace MyProject.__Sources__; - -/// -/// Provides access to the embedded XAML sources -/// -/// -/// This class is used to provide the embedded XAML sources to the Hot Reload engine. -/// This is not intended to be used directly by application code. -/// WON'T BE GENERATED ON RELEASE BUILDS -/// -internal static class EmbeddedXamlSourcesProvider -{ - // key=absolute file path - private static IDictionary Getter)>? _XamlSources; - - // hash of all the paths - private static volatile string? _filesListHash; - - // get the current value of the update counter - private static volatile uint _updateCounter; - - // The content of this method only changes when the file list changes - private static IDictionary Getter)> EnsureInitialize() - { - const string currentListHash = "d6cd66944958ced0c513e0a04797b51d"; // that's the hash of all the paths, used to detect changes in the file list following a HR operation - - // Determine if the sources have been updated or not initialized yet - var previousHashList = _XamlSources; - var needsUpdate = previousHashList is null || _filesListHash != currentListHash; - - if (needsUpdate) - { - var xamlSources = new Dictionary Getter)>(1, StringComparer.OrdinalIgnoreCase); - - // Use method groups to avoid closure allocation and ensure no lambda is created, to allow proper HR support - xamlSources[NormalizePath(@"C:/Project/0/MainPage.xaml")] = (NormalizePath(@"C:/Project/0/MainPage.xaml"), GetSources_MainPage_d6cd66944958ced0c513e0a04797b51d); - - if (Interlocked.CompareExchange(ref _XamlSources, xamlSources, previousHashList) == previousHashList) - { - // The sources were updated successfully (no other thread modified them concurrently) - _filesListHash = currentListHash; - _updateCounter++; - } - } - - return _XamlSources; - } - - /// - /// Gets the current update counter, used to detect changes in the sources. - /// - /// - /// This counter is incremented each time a Hot Reload sources update is detected. - /// - public static uint UpdateCounter - { - get - { - EnsureInitialize(); - return _updateCounter; - } - } - - public static IReadOnlyList GetXamlFilesList() => [.. EnsureInitialize().Keys]; - - public static string? GetNormalizedFileName(string path) - { - // Will return the normalized path if the file exists, or null if it doesn't. - // (the returned value will be constant for the file and can be used in a dictionary using an ordinal comparer) - var normalizedPath = NormalizePath(path); - return EnsureInitialize().TryGetValue(normalizedPath, out var entry) ? entry.ActualPath : null; - } - - public static (string ActualPath, string Hash, string Payload)? GetXamlFile(string path) - { - var normalizedPath = NormalizePath(path); - if (EnsureInitialize().TryGetValue(normalizedPath, out var entry)) - { - var sources = entry.Getter(); - return (entry.ActualPath, sources.Hash, sources.Payload); - } - return null; - } - - private static string NormalizePath(string path) => path.Replace('\\', '/'); - - #region Sources for C:/Project/0/MainPage.xaml - private static (string hash, string payload) GetSources_MainPage_d6cd66944958ced0c513e0a04797b51d() - { - return ( - "d65e560961295873ce5fb238ed21e219474df252", // hash - """ - - - - - - - -