From 6b728cd6d027e2f9787e816c47e23ce0b62f7736 Mon Sep 17 00:00:00 2001 From: Michael Niksa Date: Thu, 26 Sep 2019 09:31:09 -0700 Subject: [PATCH] Add source linking information during the build (#2857) Copies source linking scripts and processes from Microsoft/Microsoft-UI-XAML. This embeds source information inside the PDBs in two formats: One for WinDBG using a PowerShell script that runs during the build, and one for Visual Studio using the Microsoft.SourceLink.GitHub NuGet pacakge. Sources are automatically pulled from raw.githubusercontent.com when debugging a release build inside either of these utilities as of this change. --- .../templates/build-console-steps.yml | 11 ++- build/scripts/Index-Pdbs.ps1 | 85 +++++++++++++++++++ src/cascadia/TerminalApp/TerminalApp.vcxproj | 34 ++++---- src/cascadia/TerminalApp/packages.config | 5 +- .../TerminalConnection.vcxproj | 16 +++- .../TerminalConnection.vcxproj.filters | 1 + .../TerminalConnection/packages.config | 5 +- .../TerminalControl/TerminalControl.vcxproj | 19 ++++- .../TerminalControl.vcxproj.filters | 3 +- src/cascadia/TerminalControl/packages.config | 5 +- .../TerminalSettings/TerminalSettings.vcxproj | 20 ++++- src/cascadia/TerminalSettings/packages.config | 5 +- .../WindowsTerminal/WindowsTerminal.vcxproj | 27 +++--- src/cascadia/WindowsTerminal/packages.config | 7 +- src/host/exe/Host.EXE.vcxproj | 20 +++++ src/host/exe/Host.EXE.vcxproj.filters | 6 ++ src/host/exe/packages.config | 6 ++ src/propsheet/packages.config | 6 ++ src/propsheet/propsheet.vcxproj | 20 ++++- src/propsheet/propsheet.vcxproj.filters | 21 ++++- src/winconpty/packages.config | 6 ++ src/winconpty/winconpty.vcxproj | 22 ++++- 22 files changed, 301 insertions(+), 49 deletions(-) create mode 100644 build/scripts/Index-Pdbs.ps1 create mode 100644 src/host/exe/packages.config create mode 100644 src/propsheet/packages.config create mode 100644 src/winconpty/packages.config diff --git a/build/pipelines/templates/build-console-steps.yml b/build/pipelines/templates/build-console-steps.yml index 61bc4a753b3..c25420cfc5f 100644 --- a/build/pipelines/templates/build-console-steps.yml +++ b/build/pipelines/templates/build-console-steps.yml @@ -54,6 +54,14 @@ steps: $Package = Get-ChildItem -Recurse -Filter "CascadiaPackage_*.msix" .\build\scripts\Test-WindowsTerminalPackage.ps1 -Verbose -Path $Package.FullName +- task: powershell@2 + displayName: 'Source Index PDBs' + inputs: + targetType: filePath + filePath: build\scripts\Index-Pdbs.ps1 + arguments: -SearchDir '$(Build.SourcesDirectory)' -SourceRoot '$(Build.SourcesDirectory)' -recursive -Verbose -CommitId $(Build.SourceVersion) + errorActionPreference: silentlyContinue + - task: VSTest@2 displayName: 'Run Unit Tests' inputs: @@ -81,7 +89,7 @@ steps: platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)' condition: and(succeeded(), eq(variables['BuildPlatform'], 'x64')) - + - task: CopyFiles@2 displayName: 'Copy *.appx/*.msix to Artifacts (Non-PR builds only)' inputs: @@ -101,3 +109,4 @@ steps: PathtoPublish: '$(Build.ArtifactStagingDirectory)/appx' ArtifactName: 'appx-$(BuildConfiguration)' condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) + diff --git a/build/scripts/Index-Pdbs.ps1 b/build/scripts/Index-Pdbs.ps1 new file mode 100644 index 00000000000..c0227b1feda --- /dev/null +++ b/build/scripts/Index-Pdbs.ps1 @@ -0,0 +1,85 @@ +[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 = "terminal", + [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" + + $ErrorActionPreference = "Continue" # Azure Pipelines defaults to "Stop", continue past errors in this script. + + $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://github.com/raw/%ORGANIZATION%/%REPO%/%COMMITID%/ +HTTP_EXTRACT_TARGET=%HTTP_ALIAS%%var2% +SRCSRVTRG=%HTTP_EXTRACT_TARGET% +SRC_INDEX=public +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 diff --git a/src/cascadia/TerminalApp/TerminalApp.vcxproj b/src/cascadia/TerminalApp/TerminalApp.vcxproj index 207c8923647..e4811c043c5 100644 --- a/src/cascadia/TerminalApp/TerminalApp.vcxproj +++ b/src/cascadia/TerminalApp/TerminalApp.vcxproj @@ -1,8 +1,9 @@ - + + + - @@ -21,7 +22,6 @@ - - - - + true true - - <_BinRoot Condition="'$(Platform)' != 'Win32'">$(OpenConsoleDir)$(Platform)\$(Configuration)\ <_BinRoot Condition="'$(Platform)' == 'Win32'">$(OpenConsoleDir)$(Configuration)\ - /INCLUDE:_DllMain@12 /INCLUDE:DllMain - - - - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + \ No newline at end of file diff --git a/src/cascadia/TerminalApp/packages.config b/src/cascadia/TerminalApp/packages.config index efa27692017..b07ee5571ad 100644 --- a/src/cascadia/TerminalApp/packages.config +++ b/src/cascadia/TerminalApp/packages.config @@ -1,6 +1,9 @@  + + + - + \ No newline at end of file diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj index cf277ae6486..fe1b6262359 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj @@ -1,5 +1,8 @@ + + + DynamicLibrary @@ -35,7 +38,7 @@ - + @@ -90,5 +93,14 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + - + + + + \ No newline at end of file diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters index ef69f54ecde..1381e4c7845 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj.filters @@ -15,6 +15,7 @@ + diff --git a/src/cascadia/TerminalConnection/packages.config b/src/cascadia/TerminalConnection/packages.config index 9bc27a32ead..76c9bfc934d 100644 --- a/src/cascadia/TerminalConnection/packages.config +++ b/src/cascadia/TerminalConnection/packages.config @@ -1,5 +1,8 @@  + + + - + \ No newline at end of file diff --git a/src/cascadia/TerminalControl/TerminalControl.vcxproj b/src/cascadia/TerminalControl/TerminalControl.vcxproj index a67e2ef476c..5e1b8c32539 100644 --- a/src/cascadia/TerminalControl/TerminalControl.vcxproj +++ b/src/cascadia/TerminalControl/TerminalControl.vcxproj @@ -1,5 +1,8 @@ + + + @@ -86,4 +89,18 @@ - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + \ No newline at end of file diff --git a/src/cascadia/TerminalControl/TerminalControl.vcxproj.filters b/src/cascadia/TerminalControl/TerminalControl.vcxproj.filters index 888488b3f7a..82e70b258d2 100644 --- a/src/cascadia/TerminalControl/TerminalControl.vcxproj.filters +++ b/src/cascadia/TerminalControl/TerminalControl.vcxproj.filters @@ -17,6 +17,7 @@ + @@ -37,4 +38,4 @@ - + \ No newline at end of file diff --git a/src/cascadia/TerminalControl/packages.config b/src/cascadia/TerminalControl/packages.config index e345a6ccd78..f5ce647a951 100644 --- a/src/cascadia/TerminalControl/packages.config +++ b/src/cascadia/TerminalControl/packages.config @@ -1,4 +1,7 @@  + + + - + \ No newline at end of file diff --git a/src/cascadia/TerminalSettings/TerminalSettings.vcxproj b/src/cascadia/TerminalSettings/TerminalSettings.vcxproj index b40d1d8ae43..359d64d3053 100644 --- a/src/cascadia/TerminalSettings/TerminalSettings.vcxproj +++ b/src/cascadia/TerminalSettings/TerminalSettings.vcxproj @@ -1,5 +1,8 @@ + + + @@ -47,7 +50,6 @@ - + so that the AppX Manifest contains their activatable classes. --> - - - true - @@ -113,15 +110,18 @@ + + + + + + - - - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + \ No newline at end of file diff --git a/src/host/exe/Host.EXE.vcxproj.filters b/src/host/exe/Host.EXE.vcxproj.filters index 09a26cd6011..78effa06956 100644 --- a/src/host/exe/Host.EXE.vcxproj.filters +++ b/src/host/exe/Host.EXE.vcxproj.filters @@ -38,4 +38,10 @@ + + + + + + \ No newline at end of file diff --git a/src/host/exe/packages.config b/src/host/exe/packages.config new file mode 100644 index 00000000000..1e6e046568a --- /dev/null +++ b/src/host/exe/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/propsheet/packages.config b/src/propsheet/packages.config new file mode 100644 index 00000000000..1e6e046568a --- /dev/null +++ b/src/propsheet/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/propsheet/propsheet.vcxproj b/src/propsheet/propsheet.vcxproj index 583eff62b9d..52c9e5f9306 100644 --- a/src/propsheet/propsheet.vcxproj +++ b/src/propsheet/propsheet.vcxproj @@ -1,5 +1,8 @@ + + + @@ -48,6 +51,7 @@ + DynamicLibrary @@ -83,4 +87,18 @@ - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + \ No newline at end of file diff --git a/src/propsheet/propsheet.vcxproj.filters b/src/propsheet/propsheet.vcxproj.filters index 32c98268a67..a5d081e3482 100644 --- a/src/propsheet/propsheet.vcxproj.filters +++ b/src/propsheet/propsheet.vcxproj.filters @@ -45,9 +45,6 @@ Source Files - - Source Files - Source Files @@ -63,6 +60,12 @@ Source Files + + Source Files + + + Source Files + @@ -95,6 +98,12 @@ Header Files + + Header Files + + + Header Files + @@ -110,5 +119,9 @@ Source Files + + + + - + \ No newline at end of file diff --git a/src/winconpty/packages.config b/src/winconpty/packages.config new file mode 100644 index 00000000000..1e6e046568a --- /dev/null +++ b/src/winconpty/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/winconpty/winconpty.vcxproj b/src/winconpty/winconpty.vcxproj index 6ffd09468e0..6ee6e7ebdbe 100644 --- a/src/winconpty/winconpty.vcxproj +++ b/src/winconpty/winconpty.vcxproj @@ -1,5 +1,8 @@ + + + @@ -8,6 +11,7 @@ + @@ -25,13 +29,25 @@ - winconpty.def - onecoreuap_apiset.lib;%(AdditionalDependencies) - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + + \ No newline at end of file