build.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 " --help Print help and exit (short: -h)"
  12. echo ""
  13. echo "Actions:"
  14. echo " --pack Package build outputs into NuGet packages"
  15. echo " --test Run all unit tests in the solution (short: -t)"
  16. echo " --rebuild Run ../.autogen.sh"
  17. echo " --skipnative Do not build runtime"
  18. echo " --skipmscorlib Do not build System.Private.CoreLib"
  19. echo ""
  20. echo "Command line arguments starting with '/p:' are passed through to MSBuild."
  21. echo "Arguments can also be passed in with a single hyphen."
  22. }
  23. pack=false
  24. configuration='Debug'
  25. properties=''
  26. force_rebuild=false
  27. test=false
  28. skipmscorlib=false
  29. skipnative=false
  30. while [[ $# > 0 ]]; do
  31. opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
  32. case "$opt" in
  33. -help|-h)
  34. usage
  35. exit 0
  36. ;;
  37. -configuration|-c)
  38. properties="$properties $1 $2"
  39. configuration=$2
  40. shift
  41. ;;
  42. -pack)
  43. pack=true
  44. ;;
  45. -test|-t)
  46. test=true
  47. ;;
  48. -rebuild)
  49. force_rebuild=true
  50. ;;
  51. -skipmscorlib)
  52. skipmscorlib=true
  53. ;;
  54. -skipnative)
  55. skipnative=true
  56. ;;
  57. -p:*|/p:*)
  58. properties="$properties $1"
  59. ;;
  60. -m:*|/m:*)
  61. properties="$properties $1"
  62. ;;
  63. -bl:*|/bl:*)
  64. properties="$properties $1"
  65. ;;
  66. -dl:*|/dl:*)
  67. properties="$properties $1"
  68. ;;
  69. *)
  70. echo "Invalid argument: $1"
  71. usage
  72. exit 1
  73. ;;
  74. esac
  75. shift
  76. done
  77. CPU_COUNT=$(getconf _NPROCESSORS_ONLN || echo 4)
  78. # run .././autogen.sh only once or if "--rebuild" argument is provided
  79. if [[ "$force_rebuild" == "true" || ! -f .configured ]]; then
  80. (cd .. && ./autogen.sh --with-core=only)
  81. touch .configured
  82. fi
  83. # build mono runtime
  84. if [ "$skipnative" = "false" ]; then
  85. make runtime -j$CPU_COUNT
  86. fi
  87. # build System.Private.CoreLib (../mcs/class/System.Private.CoreLib)
  88. if [ "$skipmscorlib" = "false" ]; then
  89. make bcl CORLIB_BUILD_FLAGS="$properties"
  90. fi
  91. # create a nupkg with runtime and System.Private.CoreLib
  92. if [ "$pack" = "true" ]; then
  93. make nupkg
  94. fi
  95. # run all xunit tests
  96. if [ "$test" = "true" ]; then
  97. make update-tests-corefx
  98. for testdir in corefx/tests/extracted/*; do
  99. ../scripts/ci/./run-step.sh --label=$(basename $testdir) --timeout=15m make run-tests-corefx-$(basename $testdir)
  100. done
  101. fi