Include MicrosoftDocs/Win32 in the Win32Docs package (#1561)

* Add MicrosoftDocs/win32 to Win32Docs.

Description and HelpLink should be populated. Need to add conditional logic for parsing other sections.

* Updated path filters.

* Reenable publishing artifacts.

* Increase versionHeightOffset.

* Skip non-reference content and handle missing api_name.

* Handle missing ms.topic.

* Parse return and remarks.

* Ignore sdk-api files when checking for reference topics.

* Only use title for MicrosoftDocs/win32.

* Scrape parameters and fields.

* Trim in ParseTextSection.

* Refactored regular expressions.

* Added MicrosoftDocs/Console-Docs.

Includes refactorings to make the code more repo-agnostic.

* Fix handling of edge cases.

* Generate Documentation attribute remaps when creating Win32Docs.

* Updated path.

* Code cleanup.

* Fixed Code Analysis warnings.

* Replace . with :: in metadata mappings.

* Added quotes.
This commit is contained in:
Mike Battista 2023-05-05 08:57:51 -07:00 коммит произвёл GitHub
Родитель 0f3f7cb460
Коммит 4e6e7451f8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 702 добавлений и 624 удалений

4
.gitmodules поставляемый
Просмотреть файл

@ -6,3 +6,7 @@
path = ext/win32
url = https://github.com/MicrosoftDocs/win32
shallow = true
[submodule "ext/Console-Docs"]
path = ext/Console-Docs
url = https://github.com/MicrosoftDocs/Console-Docs
shallow = true

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

@ -20,7 +20,7 @@
Outputs="@(DocOutputPath)"
Condition=" '$(DesignTimeBuild)' != 'true' ">
<Message Importance="high" Text="Generating @(DocOutputPath->'%(FullPath)'). This may take a few minutes..." />
<Exec Command="dotnet @(ScraperTool) ../../ext/sdk-api/sdk-api-src/content @(DocOutputPath)"
<Exec Command="dotnet @(ScraperTool) '../../ext/sdk-api/sdk-api-src/content;../../ext/win32/desktop-src;../../ext/Console-Docs/docs' @(DocOutputPath)"
StandardOutputImportance="high"/>
</Target>

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

@ -74,15 +74,15 @@ namespace ScrapeDocs
string? enumName = null;
if (uses.Count == 1)
{
var oneValue = uses[0];
if (oneValue.ParameterName.Contains("flags", StringComparison.OrdinalIgnoreCase))
var (methodName, parameterName, _, _) = uses[0];
if (parameterName.Contains("flags", StringComparison.OrdinalIgnoreCase))
{
// Only appears in one method, on a parameter named something like "flags".
enumName = $"{oneValue.MethodName}Flags";
enumName = $"{methodName}Flags";
}
else
{
enumName = $"{oneValue.MethodName}_{oneValue.ParameterName}Flags";
enumName = $"{methodName}_{parameterName}Flags";
}
}
else
@ -106,7 +106,7 @@ namespace ScrapeDocs
if (commonPrefixLength > 1 && firstName[commonPrefixLength - 1] == '_')
{
// The enum values share a common prefix suitable to imply a name for the enum.
enumName = firstName.Substring(0, commonPrefixLength - 1);
enumName = firstName[..(commonPrefixLength - 1)];
}
}
}

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

@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Avoids disrupting code organization.", Scope = "member", Target = "~M:ScrapeDocs.Program.ParseDocFile(System.String)~System.Collections.Generic.List{System.ValueTuple{System.String,Microsoft.Windows.SDK.Win32Docs.ApiDetails,System.Collections.Generic.IReadOnlyDictionary{System.String,ScrapeDocs.DocEnum},System.Collections.Generic.IReadOnlyDictionary{System.String,ScrapeDocs.DocEnum}}}")]

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -0,0 +1,8 @@
{
"profiles": {
"ScrapeDocs": {
"commandName": "Project",
"commandLineArgs": "../../../ext/win32/desktop-src ../../../bin/Debug/apidocs.msgpack"
}
}
}

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

@ -7,13 +7,21 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0|AnyCPU'">
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Microsoft.Windows.SDK.Win32Docs\ApiDetails.cs" Link="ApiDetails.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="YamlDotNet" Version="11.1.1" />
<PackageReference Include="MessagePack" Version="2.2.85" />
<PackageReference Include="YamlDotNet" Version="11.1.1" />
</ItemGroup>
</Project>

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

@ -2,9 +2,10 @@
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"inherit": true,
"version": "0.1-alpha",
"versionHeightOffset": 0, // manually +1 each time the ext/sdk-api submodule tree is updated
"versionHeightOffset": 1, // manually +1 each time the ext/sdk-api submodule tree is updated
"pathFilters": [
".",
"../ext/sdk-api" // doesn't work yet: https://github.com/dotnet/Nerdbank.GitVersioning/issues/625
"../ext/sdk-api", // doesn't work yet: https://github.com/dotnet/Nerdbank.GitVersioning/issues/625
"../ext/win32" // doesn't work yet: https://github.com/dotnet/Nerdbank.GitVersioning/issues/625
]
}

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

@ -117,9 +117,12 @@ jobs:
MaxConcurrency: 50
MaxRetryAttempts: 5
condition: and(succeeded(), eq(variables['SignFiles'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
# - publish: bin/Packages/$(BuildConfiguration)/NuGet
# artifact: ApiDocsNuGetPackages
# displayName: 📢 Publish package
- publish: bin/Packages/$(BuildConfiguration)/NuGet
artifact: ApiDocsNuGetPackages
displayName: 📢 Publish package
- publish: bin/$(BuildConfiguration)/netstandard2.0/documentationMappings.rsp
artifact: ApiDocsMetadata
displayName: 📢 Publish metadata
# # There's a problem on microsoft.visualstudio.com that requires the guid instead of NuGetCommand@2
# # Don't publish if we're using pre-generated source
# - task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2

1
ext/Console-Docs Submodule

@ -0,0 +1 @@
Subproject commit d85d81928ac3df56565acc32a1ea1db80a3fb6c6

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

@ -1,100 +0,0 @@
. "$PSScriptRoot\CommonUtils.ps1"
$documentationMappingsRsp = Join-Path $windowsWin32ProjectRoot "documentationMappings.rsp"
Write-Host "Writing to $documentationMappingsRsp..."
$output = [System.Text.StringBuilder]::new()
$output.AppendLine("--memberRemap") | Out-Null
$paths = @(
(Join-Path $MicrosoftDocsSdkApiPath "sdk-api-src\content")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\AD")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\ADSI")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Bits")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Controls")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\dataxchg")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\DevIO")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\DevNotes")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\dlgbox")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\dwm")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\extensible-storage-engine")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\gdi")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\hidpi")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\inputdev")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\inputmsg")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Intl")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\menurc")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Multimedia")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\OpenGL")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Power")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\printdocs")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\RRAS")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecAuthN")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecAuthZ")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecBioMet")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecCertEnroll")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecCNG")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecCNG")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecCrypto")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SecMgmt")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\shell")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Shutdown")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\SysInfo")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\tablet")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\Tapi")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\TermServ")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\TSF")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\wia")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\wic")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\WinAuto")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\winmsg")
(Join-Path $MicrosoftDocsWin32Path "desktop-src\wintouch")
)
Get-ChildItem $paths -Include "*.md" -Exclude "index.md", "TOC.md" -Recurse |
ForEach-Object {
$content = Get-Content $_ -TotalCount 20
if ($_.FullName.StartsWith($MicrosoftDocsSdkApiPath)) {
$api = [regex]::Match($content, "title: ([^\s\(]+)").Groups[1].Value -replace "\.", "::"
$output.AppendLine("$api=[Documentation(""https://docs.microsoft.com/windows/win32/api/$($_.Directory.Name)/$($_.BaseName)"")]") | Out-Null
}
elseif ($_.FullName.StartsWith($MicrosoftDocsWin32Path)) {
$match = [regex]::Match($content, "ms.topic: ([^\s]+)")
if ($match.Success -and $match.Groups[1].Value -eq "reference") {
$baseApi = [regex]::Match($content, "title: ([^\s\(]+)").Groups[1].Value
$api_names = $content | Select-String "api_name" -Context 0,3
if ($api_names -ne $null) {
$match = [regex]::Matches($api_names, "- ($($baseApi -replace "::", "\.")[\w\.:]*)")
# If api_names includes variants of the base API, create mappings for each.
# Example: ext/win32/desktop-src/printdocs/addprinter.md
if ($match.Count -gt 0 -and $match.Groups[1].Value -eq ($baseApi -replace "::", "\.")) {
$apis = $match.Groups | Where-Object { $_.Name -eq "1" } | ForEach-Object { $_.Value -replace "\.", "::"}
foreach ($api in $apis) {
$output.AppendLine("$api=[Documentation(""https://docs.microsoft.com/windows/win32/$($_.Directory.Name)/$($_.BaseName)"")]") | Out-Null
}
}
# If api_names doesn't include the base API, create a mapping just for the base API.
# Example: ext/win32/desktop-src/Controls/em-getfileline.md
else {
$api = $baseApi -replace "\.", "::"
$output.AppendLine("$api=[Documentation(""https://docs.microsoft.com/windows/win32/$($_.Directory.Name)/$($_.BaseName)"")]") | Out-Null
}
}
else {
$api = $baseApi -replace "\.", "::"
$output.AppendLine("$api=[Documentation(""https://docs.microsoft.com/windows/win32/$($_.Directory.Name)/$($_.BaseName)"")]") | Out-Null
}
}
}
}
[System.IO.File]::WriteAllLines($documentationMappingsRsp, $output.ToString())