finalize_build.ps1 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #-------------------------------------------------------------------------------------------------------
  2. # Copyright (C) Microsoft. All rights reserved.
  3. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. #-------------------------------------------------------------------------------------------------------
  5. # Finalize Build Script
  6. #
  7. # This script is run as the final step in a build definition
  8. # to clean up and produce metadata about the build.
  9. param (
  10. [Parameter(Mandatory=$True)]
  11. [ValidateSet("x86", "x64", "arm", "arm64")]
  12. [string]$arch,
  13. [Parameter(Mandatory=$True)]
  14. [ValidateSet("debug", "release", "test", "codecoverage")]
  15. [string]$flavor,
  16. [ValidateSet("default", "codecoverage", "pogo")]
  17. [string]$subtype = "default",
  18. $corePathSegment = "", # e.g. "core"
  19. [string]$destinationBase = $Env:DropPath
  20. )
  21. . $PSScriptRoot\pre_post_util.ps1
  22. $sourcesDir, $_, $_, $_ = `
  23. ComputePaths `
  24. -arch $arch -flavor $flavor -subtype $subtype -OuterScriptRoot $PSScriptRoot
  25. $coreSourcesDir = Join-Path $sourcesDir $corePathSegment
  26. $buildName = ConstructBuildName -arch $arch -flavor $flavor -subtype $subtype
  27. #
  28. # Copy all logs to DropPath
  29. #
  30. $logBase = Join-Path $destinationBase "logs"
  31. $buildlogsDropPath = Join-Path $logBase "buildlogs"
  32. $logsDropPath = Join-Path $logBase "logs"
  33. $testlogsDropPath = Join-Path $logBase "testlogs"
  34. New-Item -Force -ItemType Directory -Path $buildlogsDropPath
  35. New-Item -Force -ItemType Directory -Path $logsDropPath
  36. New-Item -Force -ItemType Directory -Path $testlogsDropPath
  37. $buildlogsSourcePath = Join-Path $Env:BinariesDirectory "buildlogs"
  38. $logsSourcePath = Join-Path $Env:BinariesDirectory "logs"
  39. $testlogsSourcePath = Join-Path $Env:BinariesDirectory "testlogs"
  40. if (Test-Path $buildlogsSourcePath) {
  41. Copy-Item -Verbose -Recurse -Force (Join-Path $buildlogsSourcePath "*") $buildlogsDropPath
  42. }
  43. if (Test-Path $logsSourcePath) {
  44. Copy-Item -Verbose -Recurse -Force (Join-Path $logsSourcePath "*") $logsDropPath
  45. }
  46. if (Test-Path $testlogsSourcePath) {
  47. Copy-Item -Verbose -Recurse -Force (Join-Path $testlogsSourcePath "*") $testlogsDropPath
  48. }
  49. #
  50. # Create build status JSON file for this flavor.
  51. #
  52. $buildErrFile = Join-Path $buildLogsDropPath "build.${buildName}.err"
  53. $testSummaryFile = Join-Path $testLogsDropPath "summary.${arch}${flavor}.log"
  54. # if build.*.err contains any text then there were build errors
  55. $BuildSucceeded = $true
  56. if (Test-Path $buildErrFile) {
  57. # build errors file has non-zero length iff the build failed
  58. $BuildSucceeded = (Get-Item $buildErrFile).length -eq 0
  59. }
  60. # if summary.*.err contains any text then there were test failures
  61. $TestsPassed = $true
  62. if (Test-Path $testSummaryFile) {
  63. # summary file has non-zero length iff the tests failed
  64. $TestsPassed = (Get-Item $testSummaryFile).length -eq 0
  65. }
  66. $Status = "passed"
  67. if ((-not $BuildSucceeded) -or (-not $TestsPassed)) {
  68. $Status = "failed"
  69. }
  70. $buildFlavorJsonFile = Join-Path $logBase "${Env:BuildName}.json"
  71. $buildFlavorJson = New-Object System.Object
  72. $buildFlavorJson | Add-Member -type NoteProperty -name buildName -value $Env:BuildName
  73. $buildFlavorJson | Add-Member -type NoteProperty -name status -value $Status
  74. $buildFlavorJson | Add-Member -type NoteProperty -name BuildSucceeded -value $BuildSucceeded
  75. $buildFlavorJson | Add-Member -type NoteProperty -name testsPassed -value $TestsPassed
  76. $buildFlavorJson | Add-Member -type NoteProperty -name arch -value $Env:BuildPlatform
  77. $buildFlavorJson | Add-Member -type NoteProperty -name flavor -value $Env:BuildConfiguration
  78. $buildFlavorJson | Add-Member -type NoteProperty -name subtype -value $Env:BuildSubtype
  79. $buildFlavorJson | ConvertTo-Json | Write-Output
  80. $buildFlavorJson | ConvertTo-Json | Out-File $buildFlavorJsonFile -Encoding utf8
  81. #
  82. # Copy outputs to metadata directory
  83. #
  84. $metadataDir = Join-Path $coreSourcesDir "metadata"
  85. New-Item -Force -ItemType Directory -Path $metadataDir
  86. Copy-Item -Verbose -Force (Join-Path $sourcesDir "ComputedEnvironment.cmd") $metadataDir
  87. Copy-Item -Verbose -Force (Join-Path $coreSourcesDir "Build\scripts\compose_build.ps1") $metadataDir
  88. Copy-Item -Verbose -Force (Join-Path $Env:BinariesDirectory "change.json") $metadataDir
  89. Copy-Item -Verbose -Force (Join-Path $Env:BinariesDirectory "change.txt") $metadataDir
  90. Copy-Item -Verbose -Force $buildFlavorJsonFile $metadataDir
  91. # Search for *.nuspec files and copy them to $metadataDir
  92. Get-ChildItem -Path (Join-Path $sourcesDir "Build") "*.nuspec" `
  93. | ForEach-Object { Copy-Item -Verbose -Force $_.FullName $metadataDir }
  94. #
  95. # Copy binaries directory
  96. #
  97. $BinFolder = Join-Path $Env:BinariesDirectory "bin\${Env:BuildName}"
  98. $BinDropPath = Join-Path $destinationBase "bin"
  99. Write-Output "Copying `"$BinFolder`" to `"$BinDropPath`"..."
  100. md $BinDropPath
  101. Get-ChildItem -Path $BinFolder -Recurse |
  102. where {$_.FullName -notmatch ".*_ttdlog.*" } |
  103. Copy-Item -Verbose -Force -Destination {
  104. if ($_.PSIsContainer) {
  105. Join-Path $BinDropPath $_.Parent.FullName.Substring($BinFolder.length)
  106. } else {
  107. Join-Path $BinDropPath $_.FullName.Substring($BinFolder.length)
  108. }
  109. }
  110. #
  111. # Copy POGO directory if present for this build
  112. #
  113. $PogoFolder = Join-Path $Env:BinariesDirectory "bin\${Env:BuildType}_pogo"
  114. if (Test-Path $PogoFolder) {
  115. $PogoBinDropPath = Join-Path $destinationBase "bin_pogo"
  116. Write-Output "Copying `"$PogoFolder`" to `"$PogoBinDropPath`"..."
  117. Write-Output "##vso[task.setvariable variable=VSO_POGOPresent;]true"
  118. Copy-Item -Verbose $PogoFolder $PogoBinDropPath -Recurse -Force
  119. }