Skip to content

Commit

Permalink
fix: don't reset runinfos on full builds as generations are no longer…
Browse files Browse the repository at this point in the history
… ignored
  • Loading branch information
jeromelaban committed Nov 10, 2022
1 parent 0ed0b87 commit e006082
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,6 @@
<Message Importance="low"
Condition="'$(UnoUIUseRoslynSourceGenerators)'==''"
Text="Uno.UI is using Uno.SourceGenerators" />

<WriteLinesToFile File="$(IntermediateOutputPath)\build-time-generator.touch" />
</Target>

<Target Name="_RemoveRoslynUnoSourceGeneration" BeforeTargets="CoreCompile" Condition="'$(UnoUIUseRoslynSourceGenerators)'=='false' or '$(WindowsAppSDKWinUI)'=='true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
internal class GenerationRunInfoManager
{
private List<GenerationRunInfo> _runs = new List<GenerationRunInfo>();
private DateTime _previousWriteTime;

internal GenerationRunInfoManager()
{
Expand All @@ -35,51 +34,5 @@ internal GenerationRunInfo CreateRun()
return runInfo;
}

internal void Update(GeneratorExecutionContext context)
{
var intermediateOutputPath = context.GetMSBuildPropertyValue("IntermediateOutputPath");

if (intermediateOutputPath != null)
{
var runFilePath = Path.Combine(intermediateOutputPath, "build-time-generator.touch");

if (File.Exists(runFilePath))
{
var lastWriteTime = new FileInfo(runFilePath).LastWriteTime;

if(lastWriteTime > _previousWriteTime)
{
_previousWriteTime = lastWriteTime;

// Clear the existing runs if a full build has been started
_runs.Clear();
}
}
}

if(GetIsDesignTimeBuild(context)
&& !GetIsHotReloadHost(context)
&& !Process.GetCurrentProcess().ProcessName.Equals("devenv", StringComparison.InvariantCultureIgnoreCase))
{
// Design-time builds need to clear runs for the x:Name values to be regenerated, in the context of OmniSharp.
// In the context of HotReload, we need to skip this, as the HotReload service sets DesignTimeBuild to build
// to true, preventing existing runs to be kept active.
//
// Devenv is also added to the conditions as there's no explicit way
// for knowing that we're in a hot-reload session.
//
_runs.Clear();
}
}

private bool GetIsDesignTimeBuild(GeneratorExecutionContext context)
{
return bool.TryParse(context.GetMSBuildPropertyValue("DesignTimeBuild"), out var value) && value;
}

private bool GetIsHotReloadHost(GeneratorExecutionContext context)
{
return bool.TryParse(context.GetMSBuildPropertyValue("IsHotReloadHost"), out var value) && value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public void Execute(GeneratorExecutionContext context)
{
if (PlatformHelper.IsValidPlatform(context))
{
_generationRunInfoManager.Update(context);

var gen = new XamlCodeGeneration(context);
var generatedTrees = gen.Generate(_generationRunInfoManager.CreateRun());

Expand Down

0 comments on commit e006082

Please sign in to comment.