Restore in-process source generation for vs4mac below 16.0

This commit is contained in:
Jérôme Laban 2019-01-17 09:59:43 -05:00
Родитель f45eda0924
Коммит 4a78299d44
12 изменённых файлов: 83 добавлений и 65 удалений

Просмотреть файл

@ -47,8 +47,12 @@ namespace Uno.SourceGeneration.Host
public SourceGeneratorEngine(BuildEnvironment environment, Func<string, MetadataReferenceProperties, PortableExecutableReference> assemblyReferenceProvider)
{
_environment = environment;
if (assemblyReferenceProvider != null)
{
_resolver = new Resolver(assemblyReferenceProvider);
}
}
public string[] Generate()
{
@ -296,7 +300,11 @@ namespace Uno.SourceGeneration.Host
};
var project = await ws.OpenProjectAsync(_environment.ProjectFile);
if (_resolver != null)
{
project = project.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataReferenceResolver: _resolver));
}
var metadataLessProjects = ws
.CurrentSolution

Просмотреть файл

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>08631d97-b757-4226-897f-9839b1205ab5</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Uno.SourceGeneration.Engine.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)GeneratorLogger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)InternalSourceGeneratorContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProjectDetails.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProjectLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SourceGeneratorEngine.cs" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>08631d97-b757-4226-897f-9839b1205ab5</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Uno.SourceGeneration.Engine.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

Просмотреть файл

@ -162,6 +162,6 @@
</ItemGroup>
<Import Project="..\Uno.SourceGenerationHost.Shared\Uno.SourceGenerationHost.Shared.projitems" Label="Shared" />
<Import Project="..\Uno.SourceGeneration.Engine.Shared\Uno.SourceGeneration.Engine.Shared.projitems" Label="Shared" />
<Import Project="..\Uno.SourceGeneration.Protocol\Uno.SourceGeneration.Protocol.projitems" Label="Shared" />
</Project>

Просмотреть файл

@ -54,8 +54,12 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Uno.SourceGeneration.Host.S
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{67EB84F7-DAA3-4657-B6D0-D7FA9FD23C45}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Uno.SourceGeneration.Engine.Shared", "Uno.SourceGeneration.Engine.Shared\Uno.SourceGeneration.Engine.Shared.shproj", "{08631D97-B757-4226-897F-9839B1205AB5}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Uno.SourceGeneration.Engine.Shared\Uno.SourceGeneration.Engine.Shared.projitems*{08631d97-b757-4226-897f-9839b1205ab5}*SharedItemsImports = 13
Uno.SourceGeneration.Engine.Shared\Uno.SourceGeneration.Engine.Shared.projitems*{0a1cc471-6080-415f-8947-e41d8534395e}*SharedItemsImports = 4
Uno.SourceGeneration.Protocol\Uno.SourceGeneration.Protocol.projitems*{0a1cc471-6080-415f-8947-e41d8534395e}*SharedItemsImports = 4
Uno.SourceGeneration.Protocol\Uno.SourceGeneration.Protocol.projitems*{76548c37-4928-45e7-8db1-63a85a7f65d6}*SharedItemsImports = 13
EndGlobalSection

Просмотреть файл

@ -1,60 +0,0 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Uno.SourceGeneration.Host.GenerationServer
{
public class HostCollection
{
private readonly DateTime _hostOwnerFileTimeStamp;
private readonly DateTime[] _analyzersTimeStamps;
private readonly DomainEntry _entry;
public ConcurrentBag<(string Wrapper, AppDomain Domain)> Hosts { get; } = new ConcurrentBag<(string, AppDomain)>();
public HostCollection(DomainEntry entry)
{
_entry = entry;
_hostOwnerFileTimeStamp = File.GetLastWriteTime(entry.OwnerFile);
_analyzersTimeStamps = entry.Analyzers.Select(e => File.GetLastWriteTime(e)).ToArray();
}
public bool IsInvalid =>
File.GetLastWriteTime(Entry.OwnerFile) != _hostOwnerFileTimeStamp
|| !Entry.Analyzers.Select(e => File.GetLastWriteTime(e)).SequenceEqual(_analyzersTimeStamps);
public DomainEntry Entry => _entry;
}
public class DomainEntry
{
public DomainEntry(string ownerFile, string platform, string[] analyzers)
{
OwnerFile = ownerFile;
Analyzers = analyzers;
Platform = platform;
}
public string[] Analyzers { get; }
public string OwnerFile { get; }
/// <remarks>
/// Platform segregation is required as domains may load assemblies that are
/// not redirected the same way. (e.g. Xamarin.Android vs. Xamarin.iOS).
/// </remarks>
public string Platform { get; }
public override bool Equals(object o)
=> o is DomainEntry other
&& OwnerFile == other.OwnerFile
&& Platform == other.Platform
&& Analyzers.SequenceEqual(other.Analyzers);
public override int GetHashCode() => OwnerFile.GetHashCode() ^ Platform.GetHashCode();
}
}

Просмотреть файл

@ -28,6 +28,7 @@ using Uno.SourceGeneration.Host.GenerationClient;
using Uno.SourceGeneration.Host.Messages;
using Uno.SourceGeneratorTasks.Helpers;
using System.Runtime.InteropServices;
using Uno.SourceGeneration.Host;
[assembly: CommitHashAttribute("<developer build>")]
@ -105,10 +106,14 @@ namespace Uno.SourceGeneratorTasks
{
GenerateWithHostController();
}
else
else if(IsMonoMSBuildCompatible)
{
GenerateWithHost();
}
else
{
GenerateInProcess();
}
return true;
}
@ -137,6 +142,8 @@ namespace Uno.SourceGeneratorTasks
}
}
}
public bool SupportsGenerationController
=> (bool.TryParse(UseGenerationController, out var result) && result)
&& (
@ -333,6 +340,7 @@ namespace Uno.SourceGeneratorTasks
}
}
private string GetHostPath()
{
var currentPath = Path.GetDirectoryName(new Uri(GetType().Assembly.CodeBase).LocalPath);
@ -361,6 +369,33 @@ namespace Uno.SourceGeneratorTasks
}
private void GenerateInProcess()
{
new SourceGeneratorEngine(CreateBuildEnvironment(), null);
}
public bool IsMonoMSBuildCompatible =>
// Starting from vs16.0 the following errors does not happen. Below this version, we continue to use
// the current process to run the generators.
//
// System.TypeInitializationException: The type initializer for 'Microsoft.Build.Collections.MSBuildNameIgnoreCaseComparer' threw an exception. ---> System.EntryPointNotFoundException: GetSystemInfo
// at(wrapper managed-to-native) Microsoft.Build.Shared.NativeMethodsShared.GetSystemInfo(Microsoft.Build.Shared.NativeMethodsShared/SYSTEM_INFO&)
// at Microsoft.Build.Shared.NativeMethodsShared+SystemInformationData..ctor ()[0x00023] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Shared.NativeMethodsShared.get_SystemInformation ()[0x0001e] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Shared.NativeMethodsShared.get_ProcessorArchitecture ()[0x00000] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Collections.MSBuildNameIgnoreCaseComparer..cctor ()[0x00010] in <61115f75067146fab35b10183e6ee379>:0
// --- End of inner exception stack trace ---
// at Microsoft.Build.Collections.PropertyDictionary`1[T]..ctor ()[0x00006] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey, TValue] globalProperties, System.Collections.Generic.IEnumerable`1[T] loggers, System.Collections.Generic.IEnumerable`1[T] remoteLoggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations, System.Int32 maxNodeCount, System.Boolean onlyLogCriticalEvents) [0x00112] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Evaluation.ProjectCollection..ctor(System.Collections.Generic.IDictionary`2[TKey, TValue] globalProperties, System.Collections.Generic.IEnumerable`1[T] loggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations) [0x00000] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Evaluation.ProjectCollection..ctor(System.Collections.Generic.IDictionary`2[TKey, TValue] globalProperties) [0x00000] in <61115f75067146fab35b10183e6ee379>:0
// at Microsoft.Build.Evaluation.ProjectCollection..ctor() [0x00000] in <61115f75067146fab35b10183e6ee379>:0
// at Uno.SourceGeneration.Host.ProjectLoader.LoadProjectDetails(Uno.SourceGeneratorTasks.BuildEnvironment environment) [0x00216] in <b845ad5dce324939bc8243d198321524>:0
// at Uno.SourceGeneration.Host.SourceGeneratorHost.Generate() [0x00014] in <b845ad5dce324939bc8243d198321524>:0
string.Compare(FileVersionInfo.GetVersionInfo(new Uri(typeof(Microsoft.Build.Utilities.Task).Assembly.Location).LocalPath).FileVersion, "16.0") >= 0;
private BuildEnvironment CreateBuildEnvironment()
=> new BuildEnvironment
{

Просмотреть файл

@ -120,7 +120,6 @@
<Link>AssemblyVersion.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tasks\HostCollection.cs" />
<Compile Include="Tasks\SourceGenerationTask.cs" />
</ItemGroup>
<ItemGroup>
@ -141,6 +140,7 @@
<None Include="Uno.SourceGenerationTasks.targets" />
</ItemGroup>
<Import Project="..\Uno.SourceGeneration.Protocol\Uno.SourceGeneration.Protocol.projitems" Label="Shared" />
<Import Project="..\Uno.SourceGeneration.Engine.Shared\Uno.SourceGeneration.Engine.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
</PropertyGroup>