build_support_macos.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. ##############################################################################
  3. # macOS support functions
  4. ##############################################################################
  5. #
  6. # This script file can be included in build scripts for macOS.
  7. #
  8. ##############################################################################
  9. # Setup build environment
  10. WORKFLOW_CONTENT=$(/bin/cat "${CI_WORKFLOW}")
  11. MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
  12. MACOS_MAJOR="$(echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 1)"
  13. MACOS_MINOR="$(echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 2)"
  14. if [ "${TERM-}" -a -z "${CI}" ]; then
  15. COLOR_RED=$(/usr/bin/tput setaf 1)
  16. COLOR_GREEN=$(/usr/bin/tput setaf 2)
  17. COLOR_BLUE=$(/usr/bin/tput setaf 4)
  18. COLOR_ORANGE=$(/usr/bin/tput setaf 3)
  19. COLOR_RESET=$(/usr/bin/tput sgr0)
  20. else
  21. COLOR_RED=""
  22. COLOR_GREEN=""
  23. COLOR_BLUE=""
  24. COLOR_ORANGE=""
  25. COLOR_RESET=""
  26. fi
  27. ## DEFINE UTILITIES ##
  28. check_macos_version() {
  29. ARCH="${ARCH:-${CURRENT_ARCH}}"
  30. case "${ARCH}" in
  31. x86_64) ;;
  32. arm64) ;;
  33. *) caught_error "Unsupported architecture '${ARCH}' provided" ;;
  34. esac
  35. step "Check macOS version..."
  36. MIN_VERSION="11.0"
  37. MIN_MAJOR=$(echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 1)
  38. MIN_MINOR=$(echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 2)
  39. if [ "${MACOS_MAJOR}" -lt "11" -a "${MACOS_MINOR}" -lt "${MIN_MINOR}" ]; then
  40. error "ERROR: Minimum required macOS version is ${MIN_VERSION}, but running on ${MACOS_VERSION}"
  41. fi
  42. export CODESIGN_LINKER="ON"
  43. }
  44. install_homebrew_deps() {
  45. if ! exists brew; then
  46. caught_error "Homebrew not found - please install Homebrew (https://brew.sh)"
  47. fi
  48. brew bundle --file "${CHECKOUT_DIR}/CI/include/Brewfile" ${QUIET:+--quiet}
  49. check_curl
  50. }
  51. check_curl() {
  52. if [ "${MACOS_MAJOR}" -lt "11" -a "${MACOS_MINOR}" -lt "15" ]; then
  53. if [ ! -d /usr/local/opt/curl ]; then
  54. step "Install Homebrew curl..."
  55. brew install curl
  56. fi
  57. CURLCMD="/usr/local/opt/curl/bin/curl"
  58. else
  59. CURLCMD="curl"
  60. fi
  61. if [ "${CI}" -o "${QUIET}" ]; then
  62. export CURLCMD="${CURLCMD} --silent --show-error --location -O"
  63. else
  64. export CURLCMD="${CURLCMD} --progress-bar --location --continue-at - -O"
  65. fi
  66. }
  67. check_archs() {
  68. step "Check Architecture..."
  69. ARCH="${ARCH:-${CURRENT_ARCH}}"
  70. if [ "${ARCH}" = "universal" ]; then
  71. CMAKE_ARCHS="x86_64;arm64"
  72. elif [ "${ARCH}" != "x86_64" -a "${ARCH}" != "arm64" ]; then
  73. caught_error "Unsupported architecture '${ARCH}' provided"
  74. else
  75. CMAKE_ARCHS="${ARCH}"
  76. fi
  77. }
  78. _add_ccache_to_path() {
  79. if [ "${CMAKE_CCACHE_OPTIONS}" ]; then
  80. if [ "${CURRENT_ARCH}" == "arm64" ]; then
  81. PATH="/opt/homebrew/opt/ccache/libexec:${PATH}"
  82. else
  83. PATH="/usr/local/opt/ccache/libexec:${PATH}"
  84. fi
  85. status "Compiler Info:"
  86. local IFS=$'\n'
  87. for COMPILER_INFO in $(type cc c++ gcc g++ clang clang++ || true); do
  88. info "${COMPILER_INFO}"
  89. done
  90. fi
  91. }
  92. ## SET UP CODE SIGNING AND NOTARIZATION CREDENTIALS ##
  93. ##############################################################################
  94. # Apple Developer Identity needed:
  95. #
  96. # + Signing the code requires a developer identity in the system's keychain
  97. # + codesign will look up and find the identity automatically
  98. #
  99. ##############################################################################
  100. read_codesign_ident() {
  101. if [ -z "${CODESIGN_IDENT}" ]; then
  102. step "Set up code signing..."
  103. read -p "${COLOR_ORANGE} + Apple developer identity: ${COLOR_RESET}" CODESIGN_IDENT
  104. fi
  105. CODESIGN_IDENT_SHORT=$(echo "${CODESIGN_IDENT}" | /usr/bin/sed -En "s/.+\((.+)\)/\1/p")
  106. }
  107. ##############################################################################
  108. # Apple Developer credentials necessary:
  109. #
  110. # + Signing for distribution and notarization require an active Apple
  111. # Developer membership
  112. # + An Apple Development identity is needed for code signing
  113. # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)')
  114. # + Your Apple developer ID is needed for notarization
  115. # + An app-specific password is necessary for notarization from CLI
  116. # + This password will be stored in your macOS keychain under the identifier
  117. # 'OBS-Codesign-Password' with access Apple's 'notarytool' only.
  118. ##############################################################################
  119. read_codesign_pass() {
  120. step "Set up notarization..."
  121. if [ -z "${CODESIGN_IDENT_USER}" ]; then
  122. read -p "${COLOR_ORANGE} + Apple account id: ${COLOR_RESET}" CODESIGN_IDENT_USER
  123. fi
  124. if [ -z "${CODESIGN_IDENT_PASS}" ]; then
  125. CODESIGN_IDENT_PASS=$(stty -echo; read -p "${COLOR_ORANGE} + Apple developer password: ${COLOR_RESET}" secret; stty echo; echo $secret)
  126. echo ""
  127. fi
  128. step "Update notarization keychain..."
  129. echo -n "${COLOR_ORANGE}"
  130. /usr/bin/xcrun notarytool store-credentials "OBS-Codesign-Password" --apple-id "${CODESIGN_IDENT_USER}" --team-id "${CODESIGN_IDENT_SHORT}" --password "${CODESIGN_IDENT_PASS}"
  131. echo -n "${COLOR_RESET}"
  132. }