Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
j0shuams committed May 21, 2021
1 parent bfcc5dd commit 52f5c99
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 25 deletions.
30 changes: 28 additions & 2 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,34 @@ $(CsWinRTFilters)

<!-- Call The GuidPatch tool on the projection .dll -->
<Target Name="CsWinRTInvokeGuidPatcher" AfterTargets="Compile" BeforeTargets="Link">
<Message Text="Preparing to invoke GuidPatcher" />


<!-- You can use a Directory.Build.props file to set two properties as the path to the patcher and the winrt.runtime used
- CsWinRTGuidPatchPath
- CsWinRTGuidPatchRuntimeDll
-->
<PropertyGroup>
<CsWinRTGuidPatchExePath Condition="'$(CsWinRTGuidPatchPath)' != ''">$(CsWinRTGuidPatchPath)</CsWinRTGuidPatchExePath>
<CsWinRTGuidPatchRuntimeDll Condition="'$(CsWinRTGuidPatchRuntimePath)' != ''">$(CsWinRTGuidPatchRuntimePath)</CsWinRTGuidPatchRuntimeDll>

<CsWinRTGuidPatchExePath Condition="'$(CsWinRTGuidPatchPath)' == ''">$(CsWinRTPath)build\tools\</CsWinRTGuidPatchExePath>
<CsWinRTGuidPatchRuntimeDll Condition="'$(CsWinRTGuidPatchRuntimePath)' == ''">$(CsWinRTPath)lib\net5.0\</CsWinRTGuidPatchRuntimeDll>

<CsWinRTGuidPatchInput Condition="'$(CsWinRTGuidPatchInput)' == ''">@(BuiltProjectOutputGroupKeyOutput->'%(Identity)')</CsWinRTGuidPatchInput>
</PropertyGroup>


<Exec Command="$(CsWinRTGuidPatchExePath)GuidPatch.exe $(CsWinRTGuidPatchInput) $(CsWinRTGuidPatchRuntimeDll)" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="CsWinRTGuidPatchOutput" />
</Exec>
<!-- Special case when the GuidPatcherOutput doesn't exist? -->

<ItemGroup>
<PatchedFiles Include="$(_DirectoryBuildTargetsBasePath)\GuidPatcherOutput\*.dll" />
</ItemGroup>

<!-- what is the file handed to Link ? Can we pass the output one along? -->
<Copy SourceFiles="@(PatchedFiles)" DestinationFolder="$(TargetDir)" />

</Target>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets" Condition="Exists('$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets')"/>
Expand Down
5 changes: 5 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<DefineConstants>$(DefineConstants);MANUAL_IUNKNOWN</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<CsWinRTGuidPatchPath>$(MSBuildProjectDirectory)\Perf\GuidPatch\bin\$(Platform)\$(Configuration)\net5.0\</CsWinRTGuidPatchPath>
<CsWinRTGuidPatchRuntimePath>$(MSBuildProjectDirectory)\WinRT.Runtime\bin\$(Configuration)\net5.0\</CsWinRTGuidPatchRuntimePath>
</PropertyGroup>

<PropertyGroup>
<VersionNumber Condition="'$(VersionNumber)'==''">0.0.0.0</VersionNumber>
<VersionString Condition="'$(VersionString)'==''">0.0.0-private.0</VersionString>
Expand Down
2 changes: 1 addition & 1 deletion src/Perf/GuidPatch/GuidPatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64;x86</Platforms>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Perf/GuidPatch/GuidPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GuidPatcher
private readonly TypeDefinition guidDataBlockType;
private SignatureGenerator signatureGenerator;

public GuidPatcher(string assemblyPath, IAssemblyResolver assemblyResolver)
public GuidPatcher(string assemblyPath, IAssemblyResolver assemblyResolver, AssemblyDefinition winRTRuntime)
{
assembly = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred)
{
Expand All @@ -42,7 +42,7 @@ public GuidPatcher(string assemblyPath, IAssemblyResolver assemblyResolver)
ApplyWindowsRuntimeProjections = false
});

winRTRuntimeAssembly = assemblyResolver.Resolve(new AssemblyNameReference("WinRT.Runtime", default));
winRTRuntimeAssembly = winRTRuntime; // assemblyResolver.Resolve(new AssemblyNameReference("WinRT.Runtime", default));

guidImplementationDetailsType = new TypeDefinition(null, "<GuidPatcherImplementationDetails>", TypeAttributes.AutoClass | TypeAttributes.Sealed, assembly.MainModule.TypeSystem.Object);

Expand Down
46 changes: 31 additions & 15 deletions src/Perf/GuidPatch/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
using System;
using Mono.Cecil;
using System;
using System.IO;

namespace GuidPatch
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
if (args.Length != 2)
{
Console.WriteLine($"Expected to be given two arguments. Given {args.Length}");
}
else
{
/* The first argument given is the .dll to patch
The second argument is the folder to look for winrt.runtime in */
var resolver = new DefaultAssemblyResolver();

/*
var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory("TestData");
resolver.AddSearchDirectory("C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Ref/5.0.0/ref/net5.0");
var guidPatcher = new GuidPatcher(
"TestData/Windows.dll",
resolver);
int numPatches = guidPatcher.ProcessAssembly();
Directory.CreateDirectory("Output");
guidPatcher.SaveAssembly("Output");
Console.WriteLine($"{numPatches} IID calculations/fetches patched");
*/
try
{
resolver.AddSearchDirectory(args[1]);
AssemblyDefinition winRTRuntimeAssembly = resolver.Resolve(new AssemblyNameReference("WinRT.Runtime", default));
var guidPatcher = new GuidPatcher(
args[0],
resolver,
winRTRuntimeAssembly);
int numPatches = guidPatcher.ProcessAssembly();
Directory.CreateDirectory("GuidPatcherOutput");
guidPatcher.SaveAssembly("GuidPatcherOutput");
Console.WriteLine($"{numPatches} IID calculations/fetches patched");
}
catch (AssemblyResolutionException)
{
Console.WriteLine("Failed to resolve WinRT.Runtime, shutting down.");
return;
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ if ErrorLevel 1 (
exit /b !ErrorLevel!
)
if "%cswinrt_build_only%"=="true" goto :eof
if "%cswinrt_buildpack%"=="true" goto :package

:test
:unittest
Expand Down Expand Up @@ -184,7 +185,7 @@ set net5_runtime=%this_dir%WinRT.Runtime\bin\%cswinrt_configuration%\net5.0\WinR
set source_generator=%this_dir%Authoring\WinRT.SourceGenerator\bin\%cswinrt_configuration%\netstandard2.0\WinRT.SourceGenerator.dll
set winrt_host_%cswinrt_platform%=%this_dir%_build\%cswinrt_platform%\%cswinrt_configuration%\WinRT.Host\bin\WinRT.Host.dll
set winrt_shim=%this_dir%Authoring\WinRT.Host.Shim\bin\%cswinrt_configuration%\net5.0\WinRT.Host.Shim.dll
set guid_patch=%this_dir%Perf\GuidPatch\bin\%cswinrt_configuration%\net5.0\GuidPatch.exe
set guid_patch=%this_dir%Perf\GuidPatch\bin\%cswinrt_platform%\%cswinrt_configuration%\net5.0\GuidPatch.exe
echo Creating nuget package
call :exec %nuget_dir%\nuget pack %this_dir%..\nuget\Microsoft.Windows.CsWinRT.nuspec -Properties cswinrt_exe=%cswinrt_exe%;netstandard2_runtime=%netstandard2_runtime%;net5_runtime=%net5_runtime%;source_generator=%source_generator%;cswinrt_nuget_version=%cswinrt_version_string%;winrt_host_x86=%winrt_host_x86%;winrt_host_x64=%winrt_host_x64%;winrt_host_arm=%winrt_host_arm%;winrt_host_arm64=%winrt_host_arm64%;winrt_shim=%winrt_shim%;guid_patch=%guid_patch% -OutputDirectory %cswinrt_bin_dir% -NonInteractive -Verbosity Detailed -NoPackageAnalysis
goto :eof
Expand Down
5 changes: 1 addition & 4 deletions src/cswinrt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AuthoringWinUITest", "Tests
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Perf", "Perf", "{539DBDEF-3B49-4503-9BD3-7EB83C2179CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GuidPatch", "Perf\GuidPatch\GuidPatch.csproj", "{AE3B0611-2FBB-42AB-A245-B4E79868A5F9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GuidPatch", "Perf\GuidPatch\GuidPatch.csproj", "{AE3B0611-2FBB-42AB-A245-B4E79868A5F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -299,7 +299,6 @@ Global
{41E2A272-150F-42F5-AD40-047AAD9088A0}.Release|x86.Build.0 = Release|x86
{0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|Any CPU.ActiveCfg = Debug|Win32
{0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x64.ActiveCfg = Debug|x64
{0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x64.Build.0 = Debug|x64
{0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x86.ActiveCfg = Debug|Win32
{0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x86.Build.0 = Debug|Win32
{0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Release|Any CPU.ActiveCfg = Release|Win32
Expand Down Expand Up @@ -341,7 +340,6 @@ Global
{FC05C557-C974-4CB3-9DA7-BB5476710E91}.Release|x86.Build.0 = Release|Any CPU
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|Any CPU.ActiveCfg = Debug|x86
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x64.ActiveCfg = Debug|x64
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x64.Build.0 = Debug|x64
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x64.Deploy.0 = Debug|x64
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x86.ActiveCfg = Debug|x86
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x86.Build.0 = Debug|x86
Expand All @@ -355,7 +353,6 @@ Global
{75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Release|x86.Deploy.0 = Release|x86
{493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|Any CPU.ActiveCfg = Debug|Win32
{493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x64.ActiveCfg = Debug|x64
{493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x64.Build.0 = Debug|x64
{493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x86.ActiveCfg = Debug|Win32
{493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x86.Build.0 = Debug|Win32
{493C7729-2F21-4198-AB09-BDF56BF501D3}.Release|Any CPU.ActiveCfg = Release|Win32
Expand Down
1 change: 1 addition & 0 deletions src/cswinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Where <spec> is one or more of:
int result{};
writer w;

/* Special case the usage exceptions to print CLI options */
try
{
auto start = get_start_time();
Expand Down

0 comments on commit 52f5c99

Please sign in to comment.