build.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/usr/bin/env bash
  2. # Stop script if unbound variable found (use ${var:-} if intentional)
  3. set -u
  4. # Stop script if command returns non-zero exit code.
  5. # Prevents hidden errors caused by missing error code propagation.
  6. set -e
  7. usage()
  8. {
  9. echo "Common settings:"
  10. echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
  11. echo " --verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
  12. echo " --binaryLog Create MSBuild binary log (short: -bl)"
  13. echo " --help Print help and exit (short: -h)"
  14. echo ""
  15. echo "Actions:"
  16. echo " --restore Restore dependencies (short: -r)"
  17. echo " --build Build solution (short: -b)"
  18. echo " --sourceBuild Source-build the solution (short: -sb)"
  19. echo " Will additionally trigger the following actions: --restore, --build, --pack"
  20. echo " If --configuration is not set explicitly, will also set it to 'Release'"
  21. echo " --rebuild Rebuild solution"
  22. echo " --test Run all unit tests in the solution (short: -t)"
  23. echo " --integrationTest Run all integration tests in the solution"
  24. echo " --performanceTest Run all performance tests in the solution"
  25. echo " --pack Package build outputs into NuGet packages and Willow components"
  26. echo " --sign Sign build outputs"
  27. echo " --publish Publish artifacts (e.g. symbols)"
  28. echo " --clean Clean the solution"
  29. echo ""
  30. echo "Advanced settings:"
  31. echo " --projects <value> Project or solution file(s) to build"
  32. echo " --ci Set when running on CI server"
  33. echo " --excludeCIBinarylog Don't output binary log (short: -nobl)"
  34. echo " --prepareMachine Prepare machine for CI run, clean up processes after build"
  35. echo " --nodeReuse <value> Sets nodereuse msbuild parameter ('true' or 'false')"
  36. echo " --warnAsError <value> Sets warnaserror msbuild parameter ('true' or 'false')"
  37. echo ""
  38. echo "Command line arguments not listed above are passed thru to msbuild."
  39. echo "Arguments can also be passed in with a single hyphen."
  40. }
  41. source="${BASH_SOURCE[0]}"
  42. # resolve $source until the file is no longer a symlink
  43. while [[ -h "$source" ]]; do
  44. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  45. source="$(readlink "$source")"
  46. # if $source was a relative symlink, we need to resolve it relative to the path where the
  47. # symlink file was located
  48. [[ $source != /* ]] && source="$scriptroot/$source"
  49. done
  50. scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
  51. restore=false
  52. build=false
  53. source_build=false
  54. rebuild=false
  55. test=false
  56. integration_test=false
  57. performance_test=false
  58. pack=false
  59. publish=false
  60. sign=false
  61. public=false
  62. ci=false
  63. clean=false
  64. warn_as_error=true
  65. node_reuse=true
  66. binary_log=false
  67. exclude_ci_binary_log=false
  68. pipelines_log=false
  69. projects=''
  70. configuration=''
  71. prepare_machine=false
  72. verbosity='minimal'
  73. runtime_source_feed=''
  74. runtime_source_feed_key=''
  75. properties=''
  76. while [[ $# > 0 ]]; do
  77. opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")"
  78. case "$opt" in
  79. -help|-h)
  80. usage
  81. exit 0
  82. ;;
  83. -clean)
  84. clean=true
  85. ;;
  86. -configuration|-c)
  87. configuration=$2
  88. shift
  89. ;;
  90. -verbosity|-v)
  91. verbosity=$2
  92. shift
  93. ;;
  94. -binarylog|-bl)
  95. binary_log=true
  96. ;;
  97. -excludeCIBinarylog|-nobl)
  98. exclude_ci_binary_log=true
  99. ;;
  100. -pipelineslog|-pl)
  101. pipelines_log=true
  102. ;;
  103. -restore|-r)
  104. restore=true
  105. ;;
  106. -build|-b)
  107. build=true
  108. ;;
  109. -rebuild)
  110. rebuild=true
  111. ;;
  112. -pack)
  113. pack=true
  114. ;;
  115. -sourcebuild|-sb)
  116. build=true
  117. source_build=true
  118. restore=true
  119. pack=true
  120. ;;
  121. -test|-t)
  122. test=true
  123. ;;
  124. -integrationtest)
  125. integration_test=true
  126. ;;
  127. -performancetest)
  128. performance_test=true
  129. ;;
  130. -sign)
  131. sign=true
  132. ;;
  133. -publish)
  134. publish=true
  135. ;;
  136. -preparemachine)
  137. prepare_machine=true
  138. ;;
  139. -projects)
  140. projects=$2
  141. shift
  142. ;;
  143. -ci)
  144. ci=true
  145. ;;
  146. -warnaserror)
  147. warn_as_error=$2
  148. shift
  149. ;;
  150. -nodereuse)
  151. node_reuse=$2
  152. shift
  153. ;;
  154. -runtimesourcefeed)
  155. runtime_source_feed=$2
  156. shift
  157. ;;
  158. -runtimesourcefeedkey)
  159. runtime_source_feed_key=$2
  160. shift
  161. ;;
  162. *)
  163. properties="$properties $1"
  164. ;;
  165. esac
  166. shift
  167. done
  168. if [[ -z "$configuration" ]]; then
  169. if [[ "$source_build" = true ]]; then configuration="Release"; else configuration="Debug"; fi
  170. fi
  171. if [[ "$ci" == true ]]; then
  172. pipelines_log=true
  173. node_reuse=false
  174. if [[ "$exclude_ci_binary_log" == false ]]; then
  175. binary_log=true
  176. fi
  177. fi
  178. . "$scriptroot/tools.sh"
  179. function InitializeCustomToolset {
  180. local script="$eng_root/restore-toolset.sh"
  181. if [[ -a "$script" ]]; then
  182. . "$script"
  183. fi
  184. }
  185. function Build {
  186. InitializeToolset
  187. InitializeCustomToolset
  188. if [[ ! -z "$projects" ]]; then
  189. properties="$properties /p:Projects=$projects"
  190. fi
  191. local bl=""
  192. if [[ "$binary_log" == true ]]; then
  193. bl="/bl:\"$log_dir/Build.binlog\""
  194. fi
  195. MSBuild $_InitializeToolset \
  196. $bl \
  197. /p:Configuration=$configuration \
  198. /p:RepoRoot="$repo_root" \
  199. /p:Restore=$restore \
  200. /p:Build=$build \
  201. /p:ArcadeBuildFromSource=$source_build \
  202. /p:Rebuild=$rebuild \
  203. /p:Test=$test \
  204. /p:Pack=$pack \
  205. /p:IntegrationTest=$integration_test \
  206. /p:PerformanceTest=$performance_test \
  207. /p:Sign=$sign \
  208. /p:Publish=$publish \
  209. $properties
  210. ExitWithExitCode 0
  211. }
  212. if [[ "$clean" == true ]]; then
  213. if [ -d "$artifacts_dir" ]; then
  214. rm -rf $artifacts_dir
  215. echo "Artifacts directory deleted."
  216. fi
  217. exit 0
  218. fi
  219. if [[ "$restore" == true ]]; then
  220. InitializeNativeTools
  221. fi
  222. Build