build.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2015-present, Facebook, Inc.
  4. # All rights reserved.
  5. #
  6. # This source code is licensed under the BSD-style license found in the
  7. # LICENSE file in the root directory of this source tree. An additional grant
  8. # of patent rights can be found in the PATENTS file in the same directory.
  9. #
  10. set -ex
  11. function define_xc_macros() {
  12. XC_MACROS="CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO"
  13. case "$TARGET" in
  14. "lib" ) XC_TARGET="WebDriverAgentLib";;
  15. "runner" ) XC_TARGET="WebDriverAgentRunner";;
  16. "tv_lib" ) XC_TARGET="WebDriverAgentLib_tvOS";;
  17. "tv_runner" ) XC_TARGET="WebDriverAgentRunner_tvOS";;
  18. *) echo "Unknown TARGET"; exit 1 ;;
  19. esac
  20. case "${DEST:-}" in
  21. "iphone" ) XC_DESTINATION="name=`echo $IPHONE_MODEL | tr -d "'"`,OS=$IOS_VERSION";;
  22. "ipad" ) XC_DESTINATION="name=`echo $IPAD_MODEL | tr -d "'"`,OS=$IOS_VERSION";;
  23. "tv" ) XC_DESTINATION="name=`echo $TV_MODEL | tr -d "'"`,OS=$TV_VERSION";;
  24. "generic" ) XC_DESTINATION="generic/platform=iOS";;
  25. "tv_generic" ) XC_DESTINATION="generic/platform=tvOS" XC_MACROS="${XC_MACROS} ARCHS=arm64";; # tvOS only supports arm64
  26. esac
  27. case "$ACTION" in
  28. "build" ) XC_ACTION="build";;
  29. "analyze" )
  30. XC_ACTION="analyze"
  31. XC_MACROS="${XC_MACROS} CLANG_ANALYZER_OUTPUT=plist-html CLANG_ANALYZER_OUTPUT_DIR=\"$(pwd)/clang\""
  32. ;;
  33. "unit_test" ) XC_ACTION="test -only-testing:UnitTests";;
  34. "tv_unit_test" ) XC_ACTION="test -only-testing:UnitTests_tvOS";;
  35. esac
  36. case "$SDK" in
  37. "sim" ) XC_SDK="iphonesimulator";;
  38. "device" ) XC_SDK="iphoneos";;
  39. "tv_sim" ) XC_SDK="appletvsimulator";;
  40. "tv_device" ) XC_SDK="appletvos";;
  41. *) echo "Unknown SDK"; exit 1 ;;
  42. esac
  43. case "${CODE_SIGN:-}" in
  44. "no" ) XC_MACROS="${XC_MACROS} CODE_SIGNING_ALLOWED=NO";;
  45. esac
  46. }
  47. function analyze() {
  48. xcbuild
  49. if [[ -z $(find clang -name "*.html") ]]; then
  50. echo "Static Analyzer found no issues"
  51. else
  52. echo "Static Analyzer found some issues"
  53. exit 1
  54. fi
  55. }
  56. function xcbuild() {
  57. destination=""
  58. output_command=cat
  59. if [ $(which xcpretty) ] ; then
  60. output_command=xcpretty
  61. fi
  62. XC_BUILD_ARGS=(-project "WebDriverAgent.xcodeproj")
  63. XC_BUILD_ARGS+=(-scheme "$XC_TARGET")
  64. XC_BUILD_ARGS+=(-sdk "$XC_SDK")
  65. XC_BUILD_ARGS+=($XC_ACTION)
  66. if [[ -n "$XC_DESTINATION" ]]; then
  67. XC_BUILD_ARGS+=(-destination "${XC_DESTINATION}")
  68. fi
  69. if [[ -n "$DERIVED_DATA_PATH" ]]; then
  70. XC_BUILD_ARGS+=(-derivedDataPath ${DERIVED_DATA_PATH})
  71. fi
  72. XC_BUILD_ARGS+=($XC_MACROS $EXTRA_XC_ARGS)
  73. xcodebuild "${XC_BUILD_ARGS[@]}" | $output_command && exit ${PIPESTATUS[0]}
  74. }
  75. function fastlane_test() {
  76. bundle install
  77. if [[ -n "$XC_DESTINATION" ]]; then
  78. SDK="$XC_SDK" DEST="$XC_DESTINATION" SCHEME="$1" bundle exec fastlane test
  79. else
  80. SDK="$XC_SDK" SCHEME="$1" bundle exec fastlane test
  81. fi
  82. }
  83. define_xc_macros
  84. case "$ACTION" in
  85. "analyze" ) analyze ;;
  86. "int_test_1" ) fastlane_test IntegrationTests_1 ;;
  87. "int_test_2" ) fastlane_test IntegrationTests_2 ;;
  88. "int_test_3" ) fastlane_test IntegrationTests_3 ;;
  89. *) xcbuild ;;
  90. esac