Ignore case when testing for duplicates.

This commit is contained in:
Mike Battista 2023-03-13 14:20:50 -07:00
Родитель c1891e082e
Коммит 076d1ffad9
6 изменённых файлов: 39 добавлений и 15 удалений

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

@ -17,7 +17,7 @@
<icon>images\windows.png</icon>
<repository type="git" url="https://github.com/microsoft/win32metadata.git" />
<dependencies>
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="45.0.5-preview" />
<dependency id="Microsoft.Windows.SDK.Win32Metadata" version="45.0.9-preview" />
</dependencies>
</metadata>

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

@ -61,9 +61,10 @@ namespace WinmdUtilsProgram
var showDuplicateConstants = new Command("showDuplicateConstants", "Show duplicate constants in a single winmd files.")
{
new Option<FileInfo>("--winmd", "The winmd to inspect.") { IsRequired = true }.ExistingOnly(),
new Option<string>("--allowItem", "Item to allow and not flag as an error.", ArgumentArity.OneOrMore)
};
showDuplicateConstants.Handler = CommandHandler.Create<FileInfo, IConsole>(ShowDuplicateConstants);
showDuplicateConstants.Handler = CommandHandler.Create<FileInfo, string[], IConsole>(ShowDuplicateConstants);
var showEmptyDelegates = new Command("showEmptyDelegates", "Show delegates that have no parameters.")
{
@ -498,9 +499,10 @@ namespace WinmdUtilsProgram
return suggestedRemappingsFound ? -1 : 0;
}
public static int ShowDuplicateConstants(FileInfo winmd, IConsole console)
public static int ShowDuplicateConstants(FileInfo winmd, string[] allowItem, IConsole console)
{
DecompilerTypeSystem winmd1 = DecompilerTypeSystemUtils.CreateTypeSystemFromFile(winmd.FullName);
HashSet<string> allowTable = new HashSet<string>(allowItem);
Dictionary<string, List<string>> nameToOwner = new Dictionary<string, List<string>>();
foreach (var type in winmd1.GetTopLevelTypeDefinitions())
@ -531,10 +533,10 @@ namespace WinmdUtilsProgram
type.GetAttributes().Any(a => a.AttributeType.Name == "GuidAttribute") &&
!type.GetFields().Any())
{
if (!nameToOwner.TryGetValue(type.Name, out var owners))
if (!nameToOwner.TryGetValue(type.Name.ToUpper(), out var owners))
{
owners = new List<string>();
nameToOwner[type.Name] = owners;
nameToOwner[type.Name.ToUpper()] = owners;
}
owners.Add(type.FullName);
@ -549,10 +551,10 @@ namespace WinmdUtilsProgram
continue;
}
if (!nameToOwner.TryGetValue(field.Name, out var owners))
if (!nameToOwner.TryGetValue(field.Name.ToUpper(), out var owners))
{
owners = new List<string>();
nameToOwner[field.Name] = owners;
nameToOwner[field.Name.ToUpper()] = owners;
}
owners.Add(type.FullName);
@ -563,6 +565,11 @@ namespace WinmdUtilsProgram
bool dupsFound = false;
foreach (var pair in nameToOwner)
{
if (allowTable.Contains(pair.Key))
{
continue;
}
if (pair.Value.Count > 1)
{
if (dupsFound == false)
@ -645,10 +652,10 @@ namespace WinmdUtilsProgram
typeName += $"({archInfo})";
}
if (!nameToNamespaces.TryGetValue(typeName, out var namespaces))
if (!nameToNamespaces.TryGetValue(typeName.ToUpper(), out var namespaces))
{
namespaces = new List<string>();
nameToNamespaces[typeName] = namespaces;
nameToNamespaces[typeName.ToUpper()] = namespaces;
}
namespaces.Add(type1.Namespace);
@ -1054,10 +1061,10 @@ namespace WinmdUtilsProgram
fullImport += $"({archInfo})";
}
if (!dllImportsToClassNames.TryGetValue(fullImport, out var classNames))
if (!dllImportsToClassNames.TryGetValue(fullImport.ToUpper(), out var classNames))
{
classNames = new List<string>();
dllImportsToClassNames[fullImport] = classNames;
dllImportsToClassNames[fullImport.ToUpper()] = classNames;
}
classNames.Add(type1.FullName);

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

@ -22,15 +22,15 @@
},
"showDuplicateConstants": {
"commandName": "Project",
"commandLineArgs": "showDuplicateConstants --winmd $(ProjectDir)..\\..\\bin\\Windows.Win32.winmd"
"commandLineArgs": "showDuplicateConstants --winmd $(ProjectDir)..\\..\\bin\\Windows.Win32.winmd @$(ProjectDir)..\\..\\tests\\Windows.Win32.Tests\\assets\\duplicateConstantsAllowList.rsp"
},
"showEmptyDelegates": {
"commandName": "Project",
"commandLineArgs": "showEmptyDelegates --winmd $(ProjectDir)..\\..\\bin\\Windows.Win32.winmd @$(ProjectDir)..\\..\\tests\\emptyDelegatesAllowList.rsp"
"commandLineArgs": "showEmptyDelegates --winmd $(ProjectDir)..\\..\\bin\\Windows.Win32.winmd @$(ProjectDir)..\\..\\tests\\Windows.Win32.Tests\\assets\\emptyDelegatesAllowList.rsp"
},
"showPointersToDelegates": {
"commandName": "Project",
"commandLineArgs": "showPointersToDelegates --winmd $(ProjectDir)..\\..\\bin\\Windows.Win32.winmd @$(ProjectDir)..\\..\\tests\\pointersToDelegatesAllowList.rsp"
"commandLineArgs": "showPointersToDelegates --winmd $(ProjectDir)..\\..\\bin\\Windows.Win32.winmd @$(ProjectDir)..\\..\\tests\\Windows.Win32.Tests\\assets\\pointersToDelegatesAllowList.rsp"
},
"showSuggestedRemappings": {
"commandName": "Project",

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

@ -31,7 +31,8 @@ namespace Windows.Win32.Tests
[Fact]
public void NoDuplicateConstants()
{
string args = $"showDuplicateConstants --winmd \"{TestUtils.Win32WinmdPath}\"";
string allowedDuplicateConstantsFileName = TestUtils.GetAssetFile("duplicateConstantsAllowList.rsp");
string args = $"showDuplicateConstants --winmd \"{TestUtils.Win32WinmdPath}\" \"@{allowedDuplicateConstantsFileName}\"";
this.ExecWinmdUtils(args);
}

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

@ -44,6 +44,9 @@
<None Update="assets\suggestedRemappingsAllowList.rsp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="assets\duplicateConstantsAllowList.rsp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="InterfacesToVerify.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

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

@ -0,0 +1,13 @@
--allowItem
SUCCESS
DRIVERVERSION
DISPID_OBJECT
DISPID_ENABLED
DISPID_HWND
DISPID_TEXT
DISPID_MAXLENGTH
DISPID_SCROLLBARS
DISPID_MULTILINE
DISPID_REFRESH
HTMLINPUTIMAGE
UNKNOWN