Remove RuntimeInformation invalid workaroung

This commit is contained in:
Jérôme Laban 2019-01-17 10:01:24 -05:00
Родитель 4a78299d44
Коммит 9e87a2eeb5
4 изменённых файлов: 67 добавлений и 9 удалений

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

@ -29,7 +29,6 @@ using Uno.SourceGeneratorTasks.Helpers;
using Uno.SourceGeneratorTasks.Logger;
using System.Diagnostics;
using System.Globalization;
using Uno.SourceGeneration.Host.Server;
namespace Uno.SourceGeneratorTasks
{
@ -85,8 +84,12 @@ namespace Uno.SourceGeneratorTasks
_remoteLoggerProvider.TaskLog = logger;
return new SourceGeneratorEngine(
environment: environment,
assemblyReferenceProvider: DesktopGenerationServerHost.SharedAssemblyReferenceProvider
environment: environment
#if IS_BUILD_HOST
, assemblyReferenceProvider: Uno.SourceGeneration.Host.Server.DesktopGenerationServerHost.SharedAssemblyReferenceProvider
#else
, null
#endif
).Generate();
}

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

@ -13,6 +13,7 @@
<Compile Include="$(MSBuildThisFileDirectory)InternalSourceGeneratorContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProjectDetails.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProjectLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RemoteSourceGeneratorEngine.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SourceGeneratorEngine.cs" />
</ItemGroup>
</Project>

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

@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<DefineConstants>$(DefineConstants);HAS_BINLOG</DefineConstants>
<DefineConstants>$(DefineConstants);HAS_BINLOG;IS_BUILD_HOST</DefineConstants>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
@ -60,9 +60,6 @@
<PackageReference Include="System.Collections.Immutable">
<Version>1.3.1</Version>
</PackageReference>
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation">
<Version>4.0.1</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.4.0</Version>
</PackageReference>
@ -161,6 +158,10 @@
<ProjectReference Include="..\Uno.SourceGeneration\Uno.SourceGeneration.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Engine\" />
</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" />

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

@ -84,6 +84,7 @@ namespace Uno.SourceGeneratorTasks
public string[] GenereratedFiles { get; set; }
private CancellationTokenSource _sharedCompileCts;
private TaskLoggerProvider _taskLogger;
public override bool Execute()
{
@ -366,12 +367,20 @@ namespace Uno.SourceGeneratorTasks
{
throw new InvalidOperationException($"Unable to find Uno.SourceGeneration.Host.dll (in {devPath} or {installedPath})");
}
}
private void GenerateInProcess()
{
new SourceGeneratorEngine(CreateBuildEnvironment(), null);
Log.LogMessage(MessageImportance.Low, $"Using in-process generation mode");
var generationInfo = CreateDomain();
_taskLogger = new TaskLoggerProvider() { TaskLog = Log };
LogExtensionPoint.AmbientLoggerFactory.AddProvider(_taskLogger);
var remotableLogger = new Logger.RemotableLogger2(_taskLogger.CreateLogger("Logger.RemotableLogger"));
GenereratedFiles = generationInfo.Wrapper.Generate(remotableLogger, CreateBuildEnvironment());
}
public bool IsMonoMSBuildCompatible =>
@ -417,5 +426,49 @@ namespace Uno.SourceGeneratorTasks
Path.IsPathRooted(targetPath)
? targetPath
: Path.Combine(Path.GetDirectoryName(projectFile), targetPath);
private (RemoteSourceGeneratorEngine Wrapper, AppDomain Domain) CreateDomain()
{
var generatorLocations = SourceGenerators.Select(Path.GetFullPath).Select(Path.GetDirectoryName).Distinct();
var wrapperBasePath = Path.GetDirectoryName(new Uri(typeof(RemoteSourceGeneratorEngine).Assembly.CodeBase).LocalPath);
// We can create an app domain per OwnerFile and all Analyzers files
// so that if those change, we can spin off another one, and still avoid
// locking these assemblies.
//
// If the domain exists, keep it and continue generating content with it.
var setup = new AppDomainSetup();
setup.ApplicationBase = wrapperBasePath;
setup.ShadowCopyFiles = "true";
setup.ShadowCopyDirectories = string.Join(";", generatorLocations) + ";" + wrapperBasePath;
setup.PrivateBinPath = setup.ShadowCopyDirectories;
setup.ConfigurationFile = Path.Combine(wrapperBasePath, typeof(RemoteSourceGeneratorEngine).Assembly.GetName().Name + ".dll.config");
// Loader optimization must not use MultiDomainHost, otherwise MSBuild assemblies may
// be shared incorrectly when multiple versions are loaded in different domains.
// The loader must specify SingleDomain, otherwise in contexts where devenv.exe is the
// current process, the default optimization is "MultiDomain" and assemblies are
// incorrectly reused.
setup.LoaderOptimization = LoaderOptimization.SingleDomain;
var domain = AppDomain.CreateDomain("Generators-" + Guid.NewGuid(), null, setup);
Log.LogMessage($"[{Process.GetCurrentProcess().ProcessName}] Creating object {typeof(RemoteSourceGeneratorEngine).Assembly.CodeBase} with {typeof(RemoteSourceGeneratorEngine).FullName}. wrapperBasePath {wrapperBasePath} ");
var newHost = domain.CreateInstanceFromAndUnwrap(
typeof(RemoteSourceGeneratorEngine).Assembly.CodeBase,
typeof(RemoteSourceGeneratorEngine).FullName
) as RemoteSourceGeneratorEngine;
var msbuildBasePath = Path.GetDirectoryName(new Uri(typeof(Microsoft.Build.Logging.ConsoleLogger).Assembly.CodeBase).LocalPath);
newHost.MSBuildBasePath = msbuildBasePath;
newHost.AdditionalAssemblies = AdditionalAssemblies;
newHost.Initialize();
return (newHost, domain);
}
}
}