run_build.ps1 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Use this script to run a build command for the given BuildType (arch, flavor, subtype)
  6. param (
  7. [ValidateSet("x86", "x64", "arm")]
  8. [Parameter(Mandatory=$True)]
  9. [string]$arch,
  10. # We do not use ValidateSet here because this $flavor param is used to name the BuildConfuration
  11. # from the solution file. MsBuild will determine whether it is valid.
  12. [Parameter(Mandatory=$True)]
  13. [string]$flavor,
  14. [ValidateSet("default", "codecoverage", "pogo")]
  15. [string]$subtype = "default",
  16. [Parameter(Mandatory=$True)]
  17. [string]$solutionFile = "",
  18. [switch]$clean,
  19. # $binDir will be inferred if not provided.
  20. [string]$binDir = "",
  21. [string]$buildlogsSubdir = "buildlogs",
  22. # assume NuGet is on the path, otherwise the caller must specify an explicit path
  23. [string]$nugetExe = "NuGet.exe",
  24. [string]$logFile = ""
  25. )
  26. $OuterScriptRoot = $PSScriptRoot
  27. . $PSScriptRoot\pre_post_util.ps1
  28. if (($logFile -eq "") -and (Test-Path Env:\TF_BUILD_BINARIESDIRECTORY)) {
  29. $logFile = "${Env:TF_BUILD_BINARIESDIRECTORY}\logs\run_build.${Env:BuildName}.log"
  30. if (Test-Path -Path $logFile) {
  31. Remove-Item $logFile -Force
  32. }
  33. }
  34. #
  35. # NuGet restore
  36. #
  37. ExecuteCommand "& $nugetExe restore $solutionFile -NonInteractive"
  38. #
  39. # Setup and build
  40. #
  41. $msbuildExe = Locate-MSBuild
  42. if (-not $msbuildExe) {
  43. WriteErrorMessage "Could not find msbuild.exe -- exiting..."
  44. exit 1
  45. }
  46. $binDir = UseValueOrDefault "$binDir" "${Env:BinariesDirectory}" "${Env:BUILD_SOURCESDIRECTORY}\Build\VcBuild"
  47. $buildlogsPath = Join-Path $binDir $buildlogsSubdir
  48. $defaultParams = "$solutionFile /nologo /m /nr:false /p:platform=`"${arch}`" /p:configuration=`"${flavor}`""
  49. $loggingParams = @(
  50. "/fl1 `"/flp1:logfile=${buildlogsPath}\build.${Env:BuildName}.log;verbosity=normal`"",
  51. "/fl2 `"/flp2:logfile=${buildlogsPath}\build.${Env:BuildName}.err;errorsonly`"",
  52. "/fl3 `"/flp3:logfile=${buildlogsPath}\build.${Env:BuildName}.wrn;warningsonly`"",
  53. "/verbosity:normal"
  54. ) -join " "
  55. $targets = ""
  56. if ($clean) {
  57. $targets += "`"/t:Clean,Rebuild`""
  58. }
  59. if ($subtype -eq "codecoverage") {
  60. $subtypeParams = "/p:ENABLE_CODECOVERAGE=true"
  61. }
  62. $buildCommand = "& `"$msbuildExe`" $targets $defaultParams $loggingParams $subtypeParams"
  63. ExecuteCommand "$buildCommand"