Skip to content

Commit 1dd744a

Browse files
authored
Fix platform case sensitivity issue with CsWin32Generator tool (#1499)
* Add regression test for case sensitivity. * Fix case sensitivity issue with platform.
1 parent c4abe00 commit 1dd744a

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/CsWin32Generator/Program.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,23 @@ private GeneratorOptions LoadGeneratorOptions(FileInfo? nativeMethodsJson)
388388
}
389389
}
390390

391-
Platform compilationPlatform = platform switch
391+
Platform compilationPlatform = Platform.AnyCpu;
392+
if (platform.Equals("x86", StringComparison.OrdinalIgnoreCase))
392393
{
393-
"x86" => Platform.X86,
394-
"x64" => Platform.X64,
395-
"arm64" => Platform.Arm64,
396-
_ => Platform.AnyCpu,
397-
};
394+
compilationPlatform = Platform.X86;
395+
}
396+
else if (platform.Equals("x64", StringComparison.OrdinalIgnoreCase))
397+
{
398+
compilationPlatform = Platform.X64;
399+
}
400+
else if (platform.Equals("arm64", StringComparison.OrdinalIgnoreCase))
401+
{
402+
compilationPlatform = Platform.Arm64;
403+
}
404+
else if (platform.Equals("AnyCPU", StringComparison.OrdinalIgnoreCase))
405+
{
406+
compilationPlatform = Platform.AnyCpu;
407+
}
398408

399409
var compilationOptions = new CSharpCompilationOptions(
400410
outputKind: OutputKind.DynamicallyLinkedLibrary,

test/CsWin32Generator.Tests/CsWin32GeneratorTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ public async Task TestGenerateSomethingInWin32System()
8888
await this.InvokeGeneratorAndCompileFromFact();
8989
}
9090

91+
[Theory]
92+
[InlineData("x64")]
93+
[InlineData("X64")]
94+
[InlineData("arm64")]
95+
[InlineData("ARM64")]
96+
public async Task TestPlatformCaseSensitivity(string platform)
97+
{
98+
this.platform = platform;
99+
this.nativeMethods.Add("SetWindowLongPtr");
100+
await this.InvokeGeneratorAndCompile();
101+
}
102+
91103
[Theory]
92104
[InlineData("IMFMediaKeySession", "get_KeySystem", "winmdroot.Foundation.BSTR* keySystem")]
93105
[InlineData("AddPrinterW", "AddPrinter", "winmdroot.Foundation.PWSTR pName, uint Level, Span<byte> pPrinter")]

test/CsWin32Generator.Tests/CsWin32GeneratorTestsBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public partial class CsWin32GeneratorTestsBase : GeneratorTestBase
3030
protected List<string> additionalReferences = new();
3131
protected string assemblyName = "TestAssembly";
3232
protected string? keyFile;
33+
protected string platform = "x64";
3334

3435
public CsWin32GeneratorTestsBase(ITestOutputHelper logger)
3536
: base(logger)
@@ -104,7 +105,7 @@ protected async Task InvokeGenerator(string outputPath, string testCase, TestOpt
104105
args.AddRange(["--native-methods-txt", nativeMethodsTxtPath]);
105106
args.AddRange(["--metadata-paths", win32winmd]);
106107
args.AddRange(["--output-path", outputPath]);
107-
args.AddRange(["--platform", "x64"]);
108+
args.AddRange(["--platform", this.platform]);
108109
if (this.nativeMethodsJson is string)
109110
{
110111
string nativeMethodsJsonPath = Path.Combine(Path.GetDirectoryName(typeof(CsWin32GeneratorTests).Assembly.Location)!, "TestContent", this.nativeMethodsJson);

0 commit comments

Comments
 (0)