finalize_build.ps1 4.9 KB

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