pre_post_util.ps1 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. . "$PSScriptRoot\util.ps1"
  6. . "$PSScriptRoot\locate_msbuild.ps1"
  7. function WriteCommonArguments() {
  8. WriteMessage " Source Path: $srcpath"
  9. WriteMessage " Object Path: $objpath"
  10. WriteMessage "Binaries Path: $binpath"
  11. }
  12. function GetBuildInfo($oauth, $commitHash) {
  13. # Get the git remote path and construct the rest API URI
  14. $gitExe = GetGitPath
  15. $remote = (iex "$gitExe remote -v")[0].split()[1].replace("_git", "_apis/git/repositories")
  16. $remote = $remote.replace("mshttps", "https")
  17. # Get the pushId and push date time to use that for build number and build date time
  18. $uri = ("{0}/commits/{1}?api-version=1.0" -f $remote, $commitHash)
  19. $oauthToken = Get-Content $oauth
  20. $header = @{Authorization=("Basic {0}" -f $oauthToken) }
  21. $info = Invoke-RestMethod -Headers $header -Uri $uri -Method GET
  22. return $info
  23. }
  24. function GetBuildPushId($info) {
  25. $buildPushId = $info.push.pushId
  26. $buildPushIdPart1 = [int]([math]::Floor($buildPushId / 65536))
  27. $buildPushIdPart2 = [int]($buildPushId % 65536)
  28. $buildPushIdString = "{0}.{1}" -f $buildPushIdPart1.ToString("00000"), $buildPushIdPart2.ToString("00000")
  29. return @($buildPushId, $buildPushIdPart1, $buildPushIdPart2, $buildPushIdString)
  30. }
  31. function ConstructBuildName($arch, $flavor, $subtype) {
  32. if ($subtype -eq "codecoverage") {
  33. # TODO eliminate tools' dependency on this particular formatting exception
  34. # Normalize the $BuildName of even if the $BuildType is e.g. x64_test_codecoverage
  35. return "${arch}_codecoverage"
  36. } elseif ($subtype -eq "pogo") {
  37. return "${arch}_${flavor}_${subtype}"
  38. } else {
  39. return "${arch}_${flavor}"
  40. }
  41. }
  42. # Compute paths
  43. if (("$arch" -eq "") -or ("$flavor" -eq "") -or ("$OuterScriptRoot" -eq ""))
  44. {
  45. WriteErrorMessage @"
  46. Required variables not set before script was included:
  47. `$arch = $arch
  48. `$flavor = $flavor
  49. `$OuterScriptRoot = $OuterScriptRoot
  50. "@
  51. throw "Cannot continue - required variables not set."
  52. }
  53. $srcpath = UseValueOrDefault $srcpath "$env:TF_BUILD_SOURCESDIRECTORY" (Resolve-Path "$OuterScriptRoot\..\..")
  54. $objpath = UseValueOrDefault $objpath "$env:TF_BUILD_BUILDDIRECTORY" "${srcpath}\Build\VcBuild\obj\${arch}_${flavor}"
  55. $binpath = UseValueOrDefault $binpath "$env:TF_BUILD_BINARIESDIRECTORY" "${srcpath}\Build\VcBuild"