build_support_macos.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. CI_DEPS_VERSION=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+DEPS_VERSION_MAC: '([0-9\-]+)'/\1/p")
  12. CI_DEPS_HASH_X86_64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+DEPS_HASH_MAC_X86_64: '([0-9a-f]+)'/\1/p")
  13. CI_DEPS_HASH_ARM64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+DEPS_HASH_MAC_ARM64: '([0-9a-f]+)'/\1/p")
  14. CI_VLC_VERSION=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+VLC_VERSION_MAC: '([0-9\.]+)'/\1/p")
  15. CI_VLC_HASH=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+VLC_HASH_MAC: '([0-9a-f]+)'/\1/p")
  16. CI_SPARKLE_VERSION=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+SPARKLE_VERSION: '([0-9\.]+)'/\1/p")
  17. CI_SPARKLE_HASH=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+SPARKLE_HASH: '([0-9a-f]+)'/\1/p")
  18. CI_QT_VERSION=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+QT_VERSION_MAC: '([0-9\.]+)'/\1/p" | /usr/bin/head -1)
  19. CI_QT_HASH_X86_64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+QT_HASH_MAC_X86_64: '([0-9a-f]+)'/\1/p")
  20. CI_QT_HASH_ARM64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+QT_HASH_MAC_ARM64: '([0-9a-f]+)'/\1/p")
  21. CI_MACOSX_DEPLOYMENT_TARGET_X86_64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+MACOSX_DEPLOYMENT_TARGET_X86_64: '([0-9\.]+)'/\1/p")
  22. CI_MACOSX_DEPLOYMENT_TARGET_ARM64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+MACOSX_DEPLOYMENT_TARGET_ARM64: '([0-9\.]+)'/\1/p")
  23. CI_MACOS_CEF_VERSION=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+CEF_BUILD_VERSION_MAC: '([0-9]+)'/\1/p")
  24. CI_CEF_HASH_X86_64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+CEF_HASH_MAC_X86_64: '([0-9a-f]+)'/\1/p")
  25. CI_CEF_HASH_ARM64=$(echo "${WORKFLOW_CONTENT}" | /usr/bin/sed -En "s/[ ]+CEF_HASH_MAC_ARM64: '([0-9a-f]+)'/\1/p")
  26. MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
  27. MACOS_MAJOR="$(echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 1)"
  28. MACOS_MINOR="$(echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 2)"
  29. if [ "${TERM-}" -a -z "${CI}" ]; then
  30. COLOR_RED=$(/usr/bin/tput setaf 1)
  31. COLOR_GREEN=$(/usr/bin/tput setaf 2)
  32. COLOR_BLUE=$(/usr/bin/tput setaf 4)
  33. COLOR_ORANGE=$(/usr/bin/tput setaf 3)
  34. COLOR_RESET=$(/usr/bin/tput sgr0)
  35. else
  36. COLOR_RED=""
  37. COLOR_GREEN=""
  38. COLOR_BLUE=""
  39. COLOR_ORANGE=""
  40. COLOR_RESET=""
  41. fi
  42. ## DEFINE UTILITIES ##
  43. check_macos_version() {
  44. ARCH="${ARCH:-${CURRENT_ARCH}}"
  45. if [ "${ARCH}" = "x86_64" ]; then
  46. CI_MACOSX_DEPLOYMENT_TARGET="${CI_MACOSX_DEPLOYMENT_TARGET_X86_64}"
  47. CI_CEF_HASH="${CI_CEF_HASH_X86_64}"
  48. CI_QT_HASH="${CI_QT_HASH_X86_64}"
  49. CI_DEPS_HASH="${CI_DEPS_HASH_X86_64}"
  50. elif [ "${ARCH}" = "arm64" ]; then
  51. CI_MACOSX_DEPLOYMENT_TARGET="${CI_MACOSX_DEPLOYMENT_TARGET_ARM64}"
  52. CI_CEF_HASH="${CI_CEF_HASH_ARM64}"
  53. CI_QT_HASH="${CI_QT_HASH_ARM64}"
  54. CI_DEPS_HASH="${CI_DEPS_HASH_ARM64}"
  55. else
  56. caught_error "Unsupported architecture '${ARCH}' provided"
  57. fi
  58. step "Check macOS version..."
  59. MIN_VERSION=${MACOSX_DEPLOYMENT_TARGET:-${CI_MACOSX_DEPLOYMENT_TARGET}}
  60. MIN_MAJOR=$(echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 1)
  61. MIN_MINOR=$(echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 2)
  62. if [ "${MACOS_MAJOR}" -lt "11" -a "${MACOS_MINOR}" -lt "${MIN_MINOR}" ]; then
  63. error "ERROR: Minimum required macOS version is ${MIN_VERSION}, but running on ${MACOS_VERSION}"
  64. fi
  65. if [ "${MACOS_MAJOR}" -ge "11" ]; then
  66. export CODESIGN_LINKER="ON"
  67. fi
  68. }
  69. install_homebrew_deps() {
  70. if ! exists brew; then
  71. caught_error "Homebrew not found - please install Homebrew (https://brew.sh)"
  72. fi
  73. brew bundle --file "${CHECKOUT_DIR}/CI/include/Brewfile" ${QUIET:+--quiet}
  74. check_curl
  75. }
  76. check_curl() {
  77. if [ "${MACOS_MAJOR}" -lt "11" -a "${MACOS_MINOR}" -lt "15" ]; then
  78. if [ ! -d /usr/local/opt/curl ]; then
  79. step "Install Homebrew curl..."
  80. brew install curl
  81. fi
  82. CURLCMD="/usr/local/opt/curl/bin/curl"
  83. else
  84. CURLCMD="curl"
  85. fi
  86. if [ "${CI}" -o "${QUIET}" ]; then
  87. export CURLCMD="${CURLCMD} --silent --show-error --location -O"
  88. else
  89. export CURLCMD="${CURLCMD} --progress-bar --location --continue-at - -O"
  90. fi
  91. }
  92. check_archs() {
  93. step "Check Architecture..."
  94. ARCH="${ARCH:-${CURRENT_ARCH}}"
  95. if [ "${ARCH}" = "universal" ]; then
  96. CMAKE_ARCHS="x86_64;arm64"
  97. elif [ "${ARCH}" != "x86_64" -a "${ARCH}" != "arm64" ]; then
  98. caught_error "Unsupported architecture '${ARCH}' provided"
  99. else
  100. CMAKE_ARCHS="${ARCH}"
  101. fi
  102. }
  103. _add_ccache_to_path() {
  104. if [ "${CMAKE_CCACHE_OPTIONS}" ]; then
  105. if [ "${CURRENT_ARCH}" == "arm64" ]; then
  106. PATH="/opt/homebrew/opt/ccache/libexec:${PATH}"
  107. else
  108. PATH="/usr/local/opt/ccache/libexec:${PATH}"
  109. fi
  110. status "Compiler Info:"
  111. local IFS=$'\n'
  112. for COMPILER_INFO in $(type cc c++ gcc g++ clang clang++ || true); do
  113. info "${COMPILER_INFO}"
  114. done
  115. fi
  116. }
  117. ## SET UP CODE SIGNING AND NOTARIZATION CREDENTIALS ##
  118. ##############################################################################
  119. # Apple Developer Identity needed:
  120. #
  121. # + Signing the code requires a developer identity in the system's keychain
  122. # + codesign will look up and find the identity automatically
  123. #
  124. ##############################################################################
  125. read_codesign_ident() {
  126. if [ -z "${CODESIGN_IDENT}" ]; then
  127. step "Set up code signing..."
  128. read -p "${COLOR_ORANGE} + Apple developer identity: ${COLOR_RESET}" CODESIGN_IDENT
  129. fi
  130. }
  131. ##############################################################################
  132. # Apple Developer credentials necessary:
  133. #
  134. # + Signing for distribution and notarization require an active Apple
  135. # Developer membership
  136. # + An Apple Development identity is needed for code signing
  137. # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)')
  138. # + Your Apple developer ID is needed for notarization
  139. # + An app-specific password is necessary for notarization from CLI
  140. # + This password will be stored in your macOS keychain under the identifier
  141. # 'OBS-Codesign-Password' with access Apple's 'altool' only.
  142. ##############################################################################
  143. read_codesign_pass() {
  144. step "Set up notarization..."
  145. if [ -z "${CODESIGN_IDENT_USER}" ]; then
  146. read -p "${COLOR_ORANGE} + Apple account id: ${COLOR_RESET}" CODESIGN_IDENT_USER
  147. fi
  148. if [ -z "${CODESIGN_IDENT_PASS}" ]; then
  149. CODESIGN_IDENT_PASS=$(stty -echo; read -p "${COLOR_ORANGE} + Apple developer password: ${COLOR_RESET}" secret; stty echo; echo $secret)
  150. echo ""
  151. fi
  152. step "Update notarization keychain..."
  153. echo -n "${COLOR_ORANGE}"
  154. /usr/bin/xcrun altool --store-password-in-keychain-item "OBS-Codesign-Password" -u "${CODESIGN_IDENT_USER}" -p "${CODESIGN_IDENT_PASS}"
  155. echo -n "${COLOR_RESET}"
  156. CODESIGN_IDENT_SHORT=$(echo "${CODESIGN_IDENT}" | /usr/bin/sed -En "s/.+\((.+)\)/\1/p")
  157. }