Skip to content

Commit 1c8cc58

Browse files
authored
Merge pull request #8951 from unoplatform/dev/jela/4-3-misc-backports
Misc backports
2 parents 9443a7b + 8a086e3 commit 1c8cc58

File tree

12 files changed

+92
-17
lines changed

12 files changed

+92
-17
lines changed

doc/articles/uno-development/troubleshooting-source-generation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ It is possible to step into the XAML generator by adding the following property:
2929
```
3030
Setting this property will popup a Debugger window allowing the selection of a visual studio instance, giving the ability to set breakpoints and trace the generator.
3131

32+
## Historical dumping of generated XAML files
33+
In the context of hot reload, troubleshooting the generator's state may be useful. In this case, the generator maintains a state in order to work around the current edition limitations (e.g. editing lambdas is not possible in .NET 6).
34+
35+
In order to see all the generated files historically, set the following property in the project:
36+
```xml
37+
<PropertyGroup>
38+
<UnoXamlHistoricalOutputGenerationPath>$(MSBuildThisFileDirectory)obj\generation-history</UnoXamlHistoricalOutputGenerationPath>
39+
</PropertyGroup>
40+
```
41+
42+
> [!WARNING]
43+
> Setting this property will generate a lot of data, particularly when editing files in the editor, as most key strokes invoke the source generators.
44+
3245
## Troubleshooting Uno.SourceGeneration based generation
3346

3447
When building, if you're having build error messages that looks like one of those:

src/SolutionTemplate/Uno.ProjectTemplates.Dotnet/content/unoapp-net6/.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"url": "http://localhost:5000",
1515
"webRoot": "${workspaceFolder}/UnoQuickStart.Wasm",
1616
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
17+
"timeout": 30000,
1718
"server": {
1819
"runtimeExecutable": "dotnet",
1920
"program": "run",
2021
"outputCapture": "std",
22+
"timeout": 30000,
2123
"cwd": "${workspaceFolder}/UnoQuickStart.Wasm"
2224
}
2325
},

src/SolutionTemplate/Uno.ProjectTemplates.Dotnet/content/unoapp-winui-net6/.template.config/template.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"defaultValue": "true",
108108
"description": "Enables the WebAssembly platform support project"
109109
},
110-
"Mobile": {
110+
"mobile": {
111111
"type": "parameter",
112112
"dataType": "bool",
113113
"defaultValue": "true",
@@ -125,6 +125,12 @@
125125
"defaultValue": "true",
126126
"description": "Enables the Skia/GTK platform support project"
127127
},
128+
"skia-linux-fb": {
129+
"type": "parameter",
130+
"dataType": "bool",
131+
"defaultValue": "true",
132+
"description": "Enables the Skia/Linux Framebuffer platform support project"
133+
},
128134
"winui-desktop": {
129135
"type": "parameter",
130136
"dataType": "bool",
@@ -152,9 +158,6 @@
152158
"condition": "Mobile",
153159
"path": "UnoWinUIQuickStart.Mobile\\UnoWinUIQuickStart.Mobile.csproj"
154160
},
155-
{
156-
"path": "UnoWinUIQuickStart.UWP\\UnoWinUIQuickStart.Uwp.csproj"
157-
},
158161
{
159162
"condition": "winui-desktop",
160163
"path": "UnoWinUIQuickStart.Windows\\UnoWinUIQuickStart.Windows.csproj"
@@ -174,6 +177,10 @@
174177
{
175178
"condition": "skia-wpf",
176179
"path": "UnoWinUIQuickStart.Skia.WPF.Host\\UnoWinUIQuickStart.Skia.WPF.Host.csproj"
180+
},
181+
{
182+
"condition": "skia-linux-fb",
183+
"path": "UnoWinUIQuickStart.Skia.Linux.FrameBuffer\\UnoWinUIQuickStart.Skia.Linux.FrameBuffer.csproj"
177184
}
178185
],
179186
"sources": [
@@ -213,6 +220,17 @@
213220
"UnoWinUIQuickStart.Skia.WPF.Host/**/*"
214221
]
215222
},
223+
{
224+
"condition": "(!skia-linux-fb)",
225+
"exclude": [
226+
"UnoWinUIQuickStart.Skia.Linux.FrameBuffer/**/*"
227+
]
228+
},
229+
{
230+
"exclude": [
231+
"UnoWinUIQuickStart.UWP/**/*"
232+
]
233+
},
216234
{
217235
"condition": "(!vscode)",
218236
"exclude": [

src/SolutionTemplate/Uno.ProjectTemplates.Dotnet/content/unoapp-winui-net6/.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"url": "http://localhost:5000",
1515
"webRoot": "${workspaceFolder}/UnoWinUIQuickStart.Wasm",
1616
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
17+
"timeout": 30000,
1718
"server": {
1819
"runtimeExecutable": "dotnet",
1920
"program": "run",
2021
"outputCapture": "std",
22+
"timeout": 30000,
2123
"cwd": "${workspaceFolder}/UnoWinUIQuickStart.Wasm"
2224
}
2325
},
@@ -30,7 +32,7 @@
3032
"request": "launch",
3133
"preLaunchTask": "build-skia-gtk",
3234
// If you have changed target frameworks, make sure to update the program path.
33-
"program": "${workspaceFolder}/UnoWinUIQuickStart.Skia.Gtk/bin/Debug/net5.0/UnoWinUIQuickStart.Skia.Gtk.dll",
35+
"program": "${workspaceFolder}/UnoWinUIQuickStart.Skia.Gtk/bin/Debug/net6.0/UnoWinUIQuickStart.Skia.Gtk.dll",
3436
"args": [],
3537
"env": {
3638
"DOTNET_MODIFIABLE_ASSEMBLIES": "debug"

src/SolutionTemplate/Uno.ProjectTemplates.Dotnet/content/unoapp-winui/.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"url": "http://localhost:5000",
1515
"webRoot": "${workspaceFolder}/UnoWinUIQuickStart.Wasm",
1616
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
17+
"timeout": 30000,
1718
"server": {
1819
"runtimeExecutable": "dotnet",
1920
"program": "run",
2021
"outputCapture": "std",
22+
"timeout": 30000,
2123
"cwd": "${workspaceFolder}/UnoWinUIQuickStart.Wasm"
2224
}
2325
},

src/SolutionTemplate/Uno.ProjectTemplates.Dotnet/content/unoapp/.vscode/launch.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"url": "http://localhost:5000",
1515
"webRoot": "${workspaceFolder}/UnoQuickStart.Wasm",
1616
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
17+
"timeout": 30000,
1718
"server": {
1819
"runtimeExecutable": "dotnet",
1920
"program": "run",
2021
"outputCapture": "std",
22+
"timeout": 30000,
2123
"cwd": "${workspaceFolder}/UnoQuickStart.Wasm"
2224
}
2325
},

src/SourceGenerators/Uno.UI.SourceGenerators/Content/Uno.UI.SourceGenerators.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<CompilerVisibleProperty Include="BuildingProject" />
5353
<CompilerVisibleProperty Include="DesignTimeBuild" />
5454
<CompilerVisibleProperty Include="UnoUISourceGeneratorDebuggerBreak" />
55+
<CompilerVisibleProperty Include="UnoXamlHistoricalOutputGenerationPath" />
5556
<CompilerVisibleProperty Include="IsHotReloadHost" />
5657

5758
<CompilerVisibleProperty Include="UseWPF" />

src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeGeneration.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ internal partial class XamlCodeGeneration
5858
private readonly bool _xamlResourcesTrimming;
5959
private readonly RoslynMetadataHelper _metadataHelper;
6060

61+
/// <summary>
62+
/// Path to output all the intermediate generated code, per process.
63+
/// </summary>
64+
/// <remarks>
65+
/// This is useful to troubleshoot transient generation issues in the context of
66+
/// C# hot reload.
67+
/// </remarks>
68+
private string? _historicalOutputGenerationPath;
69+
6170
/// <summary>
6271
/// If set, code generated from XAML will be annotated with the source method and line # in XamlFileGenerator, for easier debugging.
6372
/// </summary>
@@ -123,6 +132,8 @@ public XamlCodeGeneration(GeneratorExecutionContext context)
123132
_projectDirectory = Path.GetDirectoryName(_projectFullPath)
124133
?? throw new InvalidOperationException($"MSBuild property MSBuildProjectFullPath value {_projectFullPath} is not valid");
125134

135+
_historicalOutputGenerationPath = context.GetMSBuildPropertyValue("UnoXamlHistoricalOutputGenerationPath") is { Length: > 0 } value ? value : null;
136+
126137
var xamlItems = context.GetMSBuildItems("Page")
127138
.Concat(context.GetMSBuildItems("ApplicationDefinition"));
128139

@@ -334,6 +345,21 @@ public KeyValuePair<string, string>[] Generate(GenerationRunInfo generationRunIn
334345

335346
TrackGenerationDone(stopwatch.Elapsed);
336347

348+
if(_historicalOutputGenerationPath is { Length: > 0 } path)
349+
{
350+
// Dumps all the generated files to the output folder
351+
// in separate folder to troubleshoot transient compilation issues.
352+
353+
var dumpPath = Path.Combine(path, $"{DateTime.Now:yyyyMMdd-HHmmss-ffff}-{Process.GetCurrentProcess().ProcessName}");
354+
355+
Directory.CreateDirectory(dumpPath);
356+
357+
foreach(var file in outputFiles)
358+
{
359+
File.WriteAllText(Path.Combine(dumpPath , file.Key), file.Value);
360+
}
361+
}
362+
337363
return outputFiles.ToArray();
338364

339365
}

src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeGenerator.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
2222
public class XamlCodeGenerator : ISourceGenerator
2323
{
2424
private readonly GenerationRunInfoManager _generationRunInfoManager = new GenerationRunInfoManager();
25+
private readonly object _gate = new();
2526

2627
public void Initialize(GeneratorInitializationContext context)
2728
{
@@ -36,16 +37,24 @@ public void Execute(GeneratorExecutionContext context)
3637
// Debugger.Launch();
3738
//}
3839

39-
if (PlatformHelper.IsValidPlatform(context))
40+
//
41+
// Lock the current generator instance, as it may be invoked concurrently
42+
// in the context of omnisharp when saving and editing fast enough, causing
43+
// corruption issues in the GenerationRunInfoManager.
44+
//
45+
lock (_gate)
4046
{
41-
_generationRunInfoManager.Update(context);
47+
if (PlatformHelper.IsValidPlatform(context))
48+
{
49+
_generationRunInfoManager.Update(context);
4250

43-
var gen = new XamlCodeGeneration(context);
44-
var genereratedTrees = gen.Generate(_generationRunInfoManager.CreateRun());
51+
var gen = new XamlCodeGeneration(context);
52+
var genereratedTrees = gen.Generate(_generationRunInfoManager.CreateRun());
4553

46-
foreach (var tree in genereratedTrees)
47-
{
48-
context.AddSource(tree.Key, tree.Value);
54+
foreach (var tree in genereratedTrees)
55+
{
56+
context.AddSource(tree.Key, tree.Value);
57+
}
4958
}
5059
}
5160
}

src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.OpenGL.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private void FlushOpenGL()
2828
[Conditional("DEBUG")]
2929
private void ValidateOpenGL()
3030
{
31-
if (_gl != null)
31+
if (_gl == null)
3232
{
3333
throw new InvalidOperationException($"_gl cannot be null");
3434
}

src/Uno.UI.Runtime.Skia.Gtk/GLRenderSurfaceBase.OpenGLES.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private void FlushOpenGLES()
2828
[Conditional("DEBUG")]
2929
private void ValidateOpenGLES()
3030
{
31-
if (_gl != null)
31+
if (_gl == null)
3232
{
3333
throw new InvalidOperationException($"_glES cannot be null");
3434
}

src/Uno.UI.Runtime.Skia.Gtk/OpenGLRenderSurface.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public static bool IsSupported
3737
get
3838
{
3939
// OpenGL support on macOS is currently broken
40-
var isMacOs = !RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
40+
var isMacOs = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
4141

4242
try
4343
{
4444
var ctx = new Silk.NET.Core.Contexts.DefaultNativeContext(new GLCoreLibraryNameContainer().GetLibraryName());
4545

46-
using var glContext = GRGlInterface.Create();
46+
var isAvailable = ctx.TryGetProcAddress("glGetString", out _);
4747

48-
return glContext != null && !isMacOs;
48+
return isAvailable && !isMacOs;
4949
}
5050
catch(Exception e)
5151
{

0 commit comments

Comments
 (0)