feat: add Godot C# compatibility and shared codegen weaving
Validate ShrinkSDK Workspace / unity (push) Failing after 3m18s
Validate ShrinkSDK Workspace / unity (push) Failing after 3m18s
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>ShrinkSDK.CodeGen.Task</AssemblyName>
|
||||
<RootNamespace>ShrinkSDK.CodeGen</RootNamespace>
|
||||
<PackageId>ShrinkSDK.CodeGen</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<Description>MSBuild integration for ShrinkSDK Cecil weaving.</Description>
|
||||
<IsPackable>true</IsPackable>
|
||||
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
|
||||
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeShrinkCodeGenDependencies</TargetsForTfmSpecificBuildOutput>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ShrinkSDK.CodeGen.Core\ShrinkSDK.CodeGen.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.CodeGen.Analyzers\ShrinkSDK.CodeGen.Analyzers.csproj" ReferenceOutputAssembly="false" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.6" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Build.Framework" Version="17.14.28" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.14.28" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="buildTransitive\ShrinkSDK.CodeGen.props" Pack="true" PackagePath="buildTransitive\ShrinkSDK.CodeGen.props" />
|
||||
<None Include="buildTransitive\ShrinkSDK.CodeGen.targets" Pack="true" PackagePath="buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
<None Include="..\ShrinkSDK.CodeGen.Analyzers\bin\$(Configuration)\netstandard2.0\ShrinkSDK.CodeGen.Analyzers.dll"
|
||||
Pack="true" PackagePath="analyzers\dotnet\cs\ShrinkSDK.CodeGen.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Target Name="IncludeShrinkCodeGenDependencies" DependsOnTargets="Build">
|
||||
<ItemGroup>
|
||||
<BuildOutputInPackage Include="$(OutputPath)ShrinkSDK.CodeGen.Core.dll" />
|
||||
<BuildOutputInPackage Include="$(OutputPath)Mono.Cecil.dll" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,98 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
namespace ShrinkSDK.CodeGen;
|
||||
|
||||
public sealed class ShrinkWeaveTask : Task
|
||||
{
|
||||
[Required]
|
||||
public string AssemblyPath { get; set; } = string.Empty;
|
||||
|
||||
public string? PdbPath { get; set; }
|
||||
public ITaskItem[] ReferencePaths { get; set; } = Array.Empty<ITaskItem>();
|
||||
public string? StrongNameKeyFile { get; set; }
|
||||
|
||||
[Output] public bool Changed { get; private set; }
|
||||
[Output] public int InstanceSubscriberCount { get; private set; }
|
||||
[Output] public int StaticSubscriberCount { get; private set; }
|
||||
[Output] public int RegistryEntryCount { get; private set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
if (!File.Exists(AssemblyPath))
|
||||
{
|
||||
Log.LogError($"[ShrinkSDK.CodeGen] Intermediate assembly does not exist: {AssemblyPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(AssemblyPath))!;
|
||||
var temporaryAssembly = Path.Combine(assemblyDirectory, $".{Path.GetFileName(AssemblyPath)}.{Guid.NewGuid():N}.tmp");
|
||||
var hasPdb = !string.IsNullOrWhiteSpace(PdbPath) && File.Exists(PdbPath);
|
||||
var temporaryPdb = hasPdb
|
||||
? Path.Combine(assemblyDirectory, $".{Path.GetFileName(PdbPath)}.{Guid.NewGuid():N}.tmp")
|
||||
: null;
|
||||
try
|
||||
{
|
||||
var result = ShrinkAssemblyWeaver.Weave(
|
||||
AssemblyPath,
|
||||
hasPdb ? PdbPath : null,
|
||||
ReferencePaths.Select(item => item.ItemSpec),
|
||||
temporaryAssembly,
|
||||
temporaryPdb,
|
||||
ShrinkCodeGenPlatform.EngineNeutral,
|
||||
StrongNameKeyFile);
|
||||
foreach (var diagnostic in result.Diagnostics)
|
||||
{
|
||||
switch (diagnostic.Severity)
|
||||
{
|
||||
case ShrinkCodeGenDiagnosticSeverity.Warning:
|
||||
Log.LogWarning($"[ShrinkSDK.CodeGen] {diagnostic.Message}");
|
||||
break;
|
||||
case ShrinkCodeGenDiagnosticSeverity.Error:
|
||||
Log.LogError($"[ShrinkSDK.CodeGen] {diagnostic.Message}");
|
||||
break;
|
||||
default:
|
||||
Log.LogMessage(MessageImportance.Low, $"[ShrinkSDK.CodeGen] {diagnostic.Message}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!result.Succeeded)
|
||||
return false;
|
||||
|
||||
Changed = result.Changed;
|
||||
InstanceSubscriberCount = result.InstanceSubscribers;
|
||||
StaticSubscriberCount = result.StaticSubscribers;
|
||||
RegistryEntryCount = result.RegistryEntries;
|
||||
if (Changed)
|
||||
{
|
||||
File.Move(temporaryAssembly, AssemblyPath, true);
|
||||
if (hasPdb && temporaryPdb != null)
|
||||
File.Move(temporaryPdb, PdbPath!, true);
|
||||
}
|
||||
Log.LogMessage(MessageImportance.High,
|
||||
$"[ShrinkSDK.CodeGen] {Path.GetFileName(AssemblyPath)} woven: instance={InstanceSubscriberCount}, static={StaticSubscriberCount}, registry={RegistryEntryCount}.");
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.LogErrorFromException(exception, true);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
TryDelete(temporaryAssembly);
|
||||
if (temporaryPdb != null) TryDelete(temporaryPdb);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryDelete(string path)
|
||||
{
|
||||
try { if (File.Exists(path)) File.Delete(path); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ShrinkCodeGenEnabled Condition="'$(ShrinkCodeGenEnabled)' == ''">true</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<_ShrinkCodeGenTaskAssembly Condition="'$(_ShrinkCodeGenTaskAssembly)' == ''">$(MSBuildThisFileDirectory)..\tools\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
</PropertyGroup>
|
||||
<UsingTask TaskName="ShrinkSDK.CodeGen.ShrinkWeaveTask" AssemblyFile="$(_ShrinkCodeGenTaskAssembly)" />
|
||||
<Target Name="ShrinkCodeGenWeave"
|
||||
AfterTargets="CoreCompile"
|
||||
BeforeTargets="CopyFilesToOutputDirectory"
|
||||
Condition="'$(ShrinkCodeGenEnabled)' == 'true' and '$(DesignTimeBuild)' != 'true'">
|
||||
<PropertyGroup>
|
||||
<_ShrinkCodeGenIntermediateAssembly>$(IntermediateOutputPath)$(TargetName).dll</_ShrinkCodeGenIntermediateAssembly>
|
||||
</PropertyGroup>
|
||||
<ShrinkWeaveTask AssemblyPath="$(_ShrinkCodeGenIntermediateAssembly)"
|
||||
PdbPath="$(IntermediateOutputPath)$(TargetName).pdb"
|
||||
ReferencePaths="@(ReferencePath)"
|
||||
StrongNameKeyFile="$(ShrinkCodeGenStrongNameKeyFile)" />
|
||||
</Target>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user