-
Notifications
You must be signed in to change notification settings - Fork 120
/
RecompileIdlFilesForScraping.ps1
85 lines (68 loc) · 4.58 KB
/
RecompileIdlFilesForScraping.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
. "$PSScriptRoot\CommonUtils.ps1"
Install-BuildTools
$cppPkgPath = Get-WinSdkCppPkgPath
$sdkBinDir = "$cppPkgPath\c\bin\$([System.IO.Path]::GetFileName($cppPkgPath) -replace "\d+$", "0")\x86"
$sdkIncludeDir = (Get-ChildItem -Path "$cppPkgPath\c\include").FullName
$midl = Join-Path $sdkBinDir "midl.exe"
if (!(Test-Path $sdkBinDir)) {
Write-Error "Couldn't find $sdkBinDir."
exit -1
}
if (!(Test-Path $sdkIncludeDir)) {
Write-Error "Couldn't find $sdkIncludeDir."
exit -1
}
$d3dPkgPath = Get-BuildToolsNugetPropsProperty("PkgMicrosoft_Direct3D_D3D12")
$d3dIncludeDir = Join-Path $d3dPkgPath "build/native/include/"
if (!(Test-Path $d3dIncludeDir)) {
Write-Error "Couldn't find $d3dIncludeDir."
exit -1
}
$vcDirPath = Get-VcDirPath -Arch x86 -HostArch x86
if (!$env:Path.Contains($vcDirPath)) {
$env:Path += ";$vcDirPath"
}
Write-Host "Cleaning $recompiledIdlHeadersDir and $recompiledIdlHeadersScratchDir..."
Reset-Directory $recompiledIdlHeadersDir
Reset-Directory $recompiledIdlHeadersScratchDir
Write-Host "Copying SDK headers from $sdkIncludeDir to $recompiledIdlHeadersDir..."
Copy-Item "$sdkIncludeDir\um" "$recompiledIdlHeadersDir" -Recurse
Copy-Item "$sdkIncludeDir\shared" "$recompiledIdlHeadersDir" -Recurse
Copy-Item "$sdkIncludeDir\winrt" "$recompiledIdlHeadersDir" -Recurse
Copy-Item "$sdkIncludeDir\ucrt" "$recompiledIdlHeadersDir" -Recurse
Write-Host "Copying D3D headers from $d3dIncludeDir to $recompiledIdlHeadersDir..."
Copy-Item "$d3dIncludeDir\*.*" "$recompiledIdlHeadersDir\um" -Exclude "dxgiformat.*" -Recurse
Copy-Item "$d3dIncludeDir\dxgiformat.*" "$recompiledIdlHeadersDir\shared" -Recurse
Write-Host "Copying additional headers from $windowsWin32ProjectRoot\AdditionalHeaders to $recompiledIdlHeadersDir\um..."
Copy-Item "$windowsWin32ProjectRoot\AdditionalHeaders\*" "$recompiledIdlHeadersDir\um" -Recurse
Write-Host "Converting MIDL attributes to SAL annotations..."
$idlFilesToRecompile = [System.Collections.ArrayList]@()
$idlFilesToExclude = "cellularapi_oem", "certbcli", "dxgicommon", "dxgitype", "microsoft.diagnostics.appanalysis", "PortableDeviceConnectImports", "wincrypt" | ForEach-Object { "$_.idl" }
Get-ChildItem "$recompiledIdlHeadersDir\um\*.idl", "$recompiledIdlHeadersDir\shared\*.idl" -Exclude $idlFilesToExclude | ForEach-Object {
# Convert MIDL attributes to SAL annotations in all IDL files. Some IDL files are included in others like strmif.idl.
& $PSScriptRoot\ConvertMidlAttributesToSalAnnotations.ps1 $_.FullName (Join-Path $recompiledIdlHeadersScratchDir $_.Name)
# Queue IDL files for recompilation only if they have corresponding headers that were generated by MIDL.
$idlHeader = [System.IO.Path]::ChangeExtension($_.FullName, "h")
if ((Test-Path $idlHeader) -and (Select-String "File created by MIDL compiler" $idlHeader -Quiet -SimpleMatch)) {
$idlFilesToRecompile.Add($_) | Out-Null
}
}
$ErrorActionPreference = "Continue"
Write-Host "Recompiling MIDL headers with SAL annotations into $recompiledIdlHeadersDir..."
$idlFilesToRecompile | ForEach-Object -ThrottleLimit ([System.Math]::Max([System.Environment]::ProcessorCount / 2, 2)) -Parallel {
$inputFileName = (Join-Path $using:recompiledIdlHeadersScratchDir $_.Name).ToLowerInvariant()
$outputHeader = [System.IO.Path]::ChangeExtension($inputFileName, "h")
$outputLog = [System.IO.Path]::ChangeExtension($inputFileName, "txt")
& $using:midl $inputFileName /out $using:recompiledIdlHeadersScratchDir /header $outputHeader /no_warn /DUNICODE /D_UNICODE /DWINVER=0x0A00 -D_APISET_MINWIN_VERSION=0x010F /DNTDDI_VERSION=0x0A00000C /DBUILD_UMS_ENABLED=0 /DBUILD_WOW64_ENABLED=0 /DBUILD_ARM64X_ENABLED=0 /DEXECUTABLE_WRITES_SUPPORT=0 -D_USE_DECLSPECS_FOR_SAL=1 -D_CONTROL_FLOW_GUARD_SVCTAB=1 -DMIDL_PASS=1 /Di386 /D_X86_ /D_WCHAR_T_DEFINED /no_stamp /nologo /no_settings_comment /lcid 1033 /sal /win32 /target NT100 /Zp8 /I$using:recompiledIdlHeadersScratchDir /I$using:recompiledIdlHeadersDir\um /I$using:recompiledIdlHeadersDir\shared /I$using:recompiledIdlHeadersDir\winrt /I"$using:PSScriptRoot\inc" 3>&1 2>&1 > $outputLog
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed for $($_.FullName)`n$(Get-Content $outputLog -Raw)"
} else {
Write-Host "Compiled $($_.Name)"
# This line gets pulled out in the Windows build of the header otherwise it won't compile.
if ($_.BaseName -eq "d3d10_1") {
(Get-Content $outputHeader -Raw).Replace("#include ""d3d10.h""`r`n", "") | Set-Content $outputHeader
}
Copy-Item $outputHeader ([System.IO.Path]::ChangeExtension($_.FullName, "h"))
}
}
$ErrorActionPreference = "Stop"