finalize_build.ps1 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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")]
  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. )
  20. $sourcesDir = $Env:BUILD_SOURCESDIRECTORY
  21. $coreSourcesDir = Join-Path $sourcesDir $corePathSegment
  22. $OuterScriptRoot = $PSScriptRoot
  23. . "$PSScriptRoot\pre_post_util.ps1"
  24. $buildName = ConstructBuildName -arch $arch -flavor $flavor -subtype $subtype
  25. #
  26. # Clean up the sentinel which previously marked this build flavor as incomplete.
  27. #
  28. Remove-Item -Path $Env:FlavorBuildIncompleteFile -Force
  29. #
  30. # Copy all logs to DropPath
  31. #
  32. $buildlogsDropPath = Join-Path $Env:DropPath "buildlogs"
  33. $logsDropPath = Join-Path $Env:DropPath "logs"
  34. $testlogsDropPath = Join-Path $Env:DropPath "testlogs"
  35. New-Item -Force -ItemType Directory -Path $buildlogsDropPath
  36. New-Item -Force -ItemType Directory -Path $logsDropPath
  37. New-Item -Force -ItemType Directory -Path $testlogsDropPath
  38. $buildlogsSourcePath = Join-Path $Env:BinariesDirectory "buildlogs"
  39. $logsSourcePath = Join-Path $Env:BinariesDirectory "logs"
  40. $testlogsSourcePath = Join-Path $Env:BinariesDirectory "testlogs"
  41. if (Test-Path $buildlogsSourcePath) {
  42. Copy-Item -Verbose -Recurse -Force (Join-Path $buildlogsSourcePath "*") $buildlogsDropPath
  43. }
  44. if (Test-Path $logsSourcePath) {
  45. Copy-Item -Verbose -Recurse -Force (Join-Path $logsSourcePath "*") $logsDropPath
  46. }
  47. if (Test-Path $testlogsSourcePath) {
  48. Copy-Item -Verbose -Recurse -Force (Join-Path $testlogsSourcePath "*") $testlogsDropPath
  49. }
  50. #
  51. # Create build status JSON file for this flavor.
  52. #
  53. $buildErrFile = Join-Path $buildLogsDropPath "build.${buildName}.err"
  54. $testSummaryFile = Join-Path $testLogsDropPath "summary.${arch}${flavor}.log"
  55. # if build.*.err contains any text then there were build errors
  56. $BuildSucceeded = $true
  57. if (Test-Path $buildErrFile) {
  58. # build errors file has non-zero length iff the build failed
  59. $BuildSucceeded = (Get-Item $buildErrFile).length -eq 0
  60. }
  61. # if summary.*.err contains any text then there were test failures
  62. $TestsPassed = $true
  63. if (Test-Path $testSummaryFile) {
  64. # summary file has non-zero length iff the tests failed
  65. $TestsPassed = (Get-Item $testSummaryFile).length -eq 0
  66. }
  67. $Status = "passed"
  68. if ((-not $BuildSucceeded) -or (-not $TestsPassed)) {
  69. $Status = "failed"
  70. }
  71. $buildFlavorJsonFile = Join-Path $Env:DropPath "${Env:BuildName}.json"
  72. $buildFlavorJson = New-Object System.Object
  73. $buildFlavorJson | Add-Member -type NoteProperty -name buildName -value $Env:BuildName
  74. $buildFlavorJson | Add-Member -type NoteProperty -name status -value $Status
  75. $buildFlavorJson | Add-Member -type NoteProperty -name BuildSucceeded -value $BuildSucceeded
  76. $buildFlavorJson | Add-Member -type NoteProperty -name testsPassed -value $TestsPassed
  77. $buildFlavorJson | Add-Member -type NoteProperty -name arch -value $Env:BuildPlatform
  78. $buildFlavorJson | Add-Member -type NoteProperty -name flavor -value $Env:BuildConfiguration
  79. $buildFlavorJson | Add-Member -type NoteProperty -name subtype -value $Env:BuildSubtype
  80. $buildFlavorJson | ConvertTo-Json | Write-Output
  81. $buildFlavorJson | ConvertTo-Json | Out-File $buildFlavorJsonFile -Encoding utf8
  82. #
  83. # Copy outputs to metadata directory
  84. #
  85. $metadataDir = Join-Path $coreSourcesDir "metadata"
  86. New-Item -Force -ItemType Directory -Path $metadataDir
  87. Copy-Item -Verbose -Force (Join-Path $sourcesDir "ComputedEnvironment.cmd") $metadataDir
  88. Copy-Item -Verbose -Force (Join-Path $coreSourcesDir "Build\scripts\compose_build.ps1") $metadataDir
  89. Copy-Item -Verbose -Force (Join-Path $Env:BinariesDirectory "change.json") $metadataDir
  90. Copy-Item -Verbose -Force (Join-Path $Env:BinariesDirectory "change.txt") $metadataDir
  91. Copy-Item -Verbose -Force $buildFlavorJsonFile $metadataDir
  92. # Search for *.nuspec files and copy them to $metadataDir
  93. Get-ChildItem -Path (Join-Path $sourcesDir "Build") "*.nuspec" `
  94. | % { Copy-Item -Verbose -Force $_.FullName $metadataDir }
  95. #
  96. # Copy POGO directory if present for this build
  97. #
  98. $PogoFolder = Join-Path $Env:BinariesDirectory "bin\${Env:BuildType}_pogo"
  99. if (Test-Path $PogoFolder) {
  100. $BinDropPath = Join-Path $Env:DropPath "bin"
  101. Write-Output "Copying `"$PogoFolder`" to `"$BinDropPath`"..."
  102. Copy-Item -Verbose $PogoFolder $BinDropPath -Recurse -Force
  103. }