Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
asklar committed May 29, 2022
1 parent 74db7e1 commit e835a0a
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/Authoring/cswinmd/CsWinMD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RollForward>Major</RollForward>
<LangVersion>preview</LangVersion>
<Authors>Microsoft Corporation</Authors>
<Company>Microsoft Corporation</Company>
<Product>C#/WinRT</Product>
<PackageId>CsWinMD</PackageId>
<PackageId>Microsoft.Windows.CsWinMD</PackageId>

<FileVersion>$(VersionNumber)</FileVersion>
<Version>$(VersionNumber)</Version>
Expand Down
23 changes: 19 additions & 4 deletions src/Authoring/cswinmd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ class Program
/// <param name="verbose">Verbose logging</param>
/// <param name="nologo">Don't print logo</param>
/// Uses System.CommandLine.Dragonfruit
#nullable enable
public static void Main(string[] i, string o, string? sdkVersion, bool? verbose, bool? nologo)
{
if (!nologo.HasValue || !nologo.Value)
{
Console.WriteLine($"CSWinMD {Assembly.GetExecutingAssembly().GetName().Version}");
}
var outFolder = string.IsNullOrEmpty(o) ? Environment.GetEnvironmentVariable("TEMP") : o;
var outFolder = string.IsNullOrEmpty(o) ? Environment.GetEnvironmentVariable("TEMP")! : o!;
try
{
if (i.Length == 0)
{
Console.Error.WriteLine("No C# source files specified");
return;
} else if (i.Length > 1)
{
throw new NotImplementedException("Compiling more than one file is not yet implemented");
}

string inputFile = i[0];
Expand Down Expand Up @@ -87,7 +91,7 @@ public static void Main(string[] i, string o, string? sdkVersion, bool? verbose,
Directory.CreateDirectory(outFolder);
}
var cp = new ConfigProvider();
var config = cp.GlobalOptions as ConfigOptions;
var config = (cp.GlobalOptions as ConfigOptions)!;
config.Values["build_property.AssemblyName"] = assemblyName;
config.Values["build_property.AssemblyVersion"] = "0.0.0.1";
config.Values["build_property.CsWinRTGeneratedFilesDir"] = outFolder;
Expand All @@ -106,12 +110,16 @@ public static void Main(string[] i, string o, string? sdkVersion, bool? verbose,
var res = d.GetRunResult();
if (!res.Diagnostics.IsEmpty)
{
Console.WriteLine();
foreach (var v in res.Diagnostics)
{
Console.WriteLine(v.GetMessage());
Console.WriteLine($"\t\tIn {v.Location.GetLineSpan()}");
}
Console.WriteLine();
} else
{
Console.WriteLine($" => {outFolder}\\{componentName}.winmd");
}
}
catch (Exception e)
Expand All @@ -130,23 +138,30 @@ public static void Main(string[] i, string o, string? sdkVersion, bool? verbose,
}
}


private static bool IsVersion(string v)
{
return Version.TryParse(Path.GetFileName(v), out var _);
}

[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "CSWinMD only runs on Windows")]
private static string GetWindowsWinMdPath(string? sdkVersion)
{
using var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
using var roots = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows Kits\Installed Roots");
var kitsRoot10 = (string)roots.GetValue("KitsRoot10");
var kitsRoot10 = (string)roots!.GetValue("KitsRoot10")!;
var unionMetadata = Path.Combine(kitsRoot10, "UnionMetadata");
if (sdkVersion == null)
{
var dirs = Directory.EnumerateDirectories(unionMetadata);
sdkVersion = Path.GetFileName(dirs.Where(IsVersion).Last());
var versions = dirs.Where(IsVersion).ToList();
versions.Sort();
sdkVersion = Path.GetFileName(versions.Last());
}
var path = Path.Combine(kitsRoot10, "UnionMetadata", sdkVersion, "Windows.winmd");
return path;
}

#nullable restore
}
}
12 changes: 6 additions & 6 deletions src/Authoring/cswinmd/build/cswinmd.targets
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ProduceWinMDFromCSharpComponent" BeforeTargets="InsertComponentWinMD">
<Target Name="CSWinMDProduceWinMDFromCSharpComponent" BeforeTargets="CSWinMDInsertComponentWinMD">
<PropertyGroup>
<CsWinMDPath Condition="'$(CsWinMDPath)'==''">$(MSBuildThisFileDirectory)..\tools\CsWinMD.exe</CsWinMDPath>
<CsWinMDOutputPath Condition="'$(CsWinMDOutputPath)'==''">$(OutDir)cswinmd-$(ProjectName)</CsWinMDOutputPath>
</PropertyGroup>
<Message Text="Producing winmd for %(CSharpCppComponent.Identity)" Importance="High" />
<Message Text="$(CsWinMDPath) -i %(CSharpCppComponent.FullPath) -o $(CsWinMDOutputPath)" Importance="High" />
<Message Text="Producing winmd for %(CSWinMDComponent.Identity)" Importance="High" />
<Message Text="$(CsWinMDPath) -i %(CSWinMDComponent.FullPath) -o $(CsWinMDOutputPath)" Importance="High" />
<MakeDir Directories="$(CSWinMDOutputPath)" />
<Exec Command="$(CsWinMDPath) -i %(CSharpCppComponent.FullPath) -o $(CsWinMDOutputPath)" />
<Exec Command="$(CsWinMDPath) -i %(CSWinMDComponent.FullPath) -o $(CsWinMDOutputPath)" />
</Target>

<Target Name="InsertComponentWinMD" AfterTargets="GetCppWinRTMdMergeInputs;CppWinRTMergeProjectWinMDInputs" BeforeTargets="CppWinRTMakeComponentProjection">
<Target Name="CSWinMDInsertComponentWinMD" AfterTargets="GetCppWinRTMdMergeInputs;CppWinRTMergeProjectWinMDInputs" BeforeTargets="CppWinRTMakeComponentProjection">
<ItemGroup>
<CppWinRTMdMergeInputs Include="@(CSharpCppComponent->'$(CsWinMDOutputPath)\%(FileName).winmd')">
<CppWinRTMdMergeInputs Include="@(CSWinMDComponent->'$(CsWinMDOutputPath)\%(FileName).winmd')">
<IsWinMDFile>true</IsWinMDFile>
</CppWinRTMdMergeInputs>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CppComponent
namespace CSWinMDComponent
{
public enum E1
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<CppWinRTGenerateWindowsMetadata>true</CppWinRTGenerateWindowsMetadata>
<MinimalCoreWin>true</MinimalCoreWin>
<ProjectGuid>{d10dc47a-db45-491c-852e-2b2165f25f86}</ProjectGuid>
<ProjectName>CppComponent</ProjectName>
<RootNamespace>CppComponent</RootNamespace>
<ProjectName>CSWinMDComponent</ProjectName>
<RootNamespace>CSWinMDComponent</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
Expand Down Expand Up @@ -98,7 +98,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<ModuleDefinitionFile>CppComponent.def</ModuleDefinitionFile>
<ModuleDefinitionFile>CSWinMDComponent.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
Expand Down Expand Up @@ -128,8 +128,8 @@
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="CppComponent.cs" />
<None Include="CppComponent.def" />
<None Include="CSWinMDComponent.cs" />
<None Include="CSWinMDComponent.def" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -139,7 +139,7 @@
</Text>
</ItemGroup>
<ItemGroup>
<CSharpCppComponent Include="CppComponent.cs" />
<CSWinMDComponent Include="CSWinMDComponent.cs" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<PropertyGroup Label="CSWinMD overrides">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<ClInclude Include="Class1.h" />
</ItemGroup>
<ItemGroup>
<None Include="CppComponent.def" />
<None Include="CppComponent.cs" />
<None Include="CSWinMDComponent.def" />
<None Include="CSWinMDComponent.cs" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions src/Tests/CSWinMDComponent/Class1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "pch.h"

#include <winrt/CSWinMDComponent.h>

#include "Class1.h"
#include <Class1.g.cpp>

namespace winrt::CSWinMDComponent::implementation
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Class1.g.h"
#include <iostream>

namespace winrt::CppComponent::implementation
namespace winrt::CSWinMDComponent::implementation
{
struct Class1 : Class1T<Class1>
{
Expand All @@ -13,7 +13,7 @@ namespace winrt::CppComponent::implementation
}
};
}
namespace winrt::CppComponent::factory_implementation
namespace winrt::CSWinMDComponent::factory_implementation
{
struct Class1 : Class1T<Class1, implementation::Class1>
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions src/Tests/CppComponent/Class1.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/cswinrt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OOPExe", "Tests\OOPExe\OOPE
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CsWinMD", "Authoring\CsWinMD\CsWinMD.csproj", "{B63DC238-AF5B-4790-B038-4F5ABE09F963}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppComponent", "Tests\CppComponent\CppComponent.vcxproj", "{D10DC47A-DB45-491C-852E-2B2165F25F86}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSWinMDComponent", "Tests\CSWinMDComponent\CSWinMDComponent.vcxproj", "{D10DC47A-DB45-491C-852E-2B2165F25F86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit e835a0a

Please sign in to comment.