build_support_macos.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. CI_DEPS_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+DEPS_VERSION_MAC: '([0-9\-]+)'/\1/p")
  11. CI_DEPS_HASH=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+DEPS_HASH_MAC: '([0-9a-f]+)'/\1/p")
  12. CI_QT_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+QT_VERSION_MAC: '([0-9\.]+)'/\1/p" | /usr/bin/head -1)
  13. CI_QT_HASH=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+QT_HASH_MAC: '([0-9a-f]+)'/\1/p")
  14. CI_MACOSX_DEPLOYMENT_TARGET=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+MACOSX_DEPLOYMENT_TARGET: '([0-9\.]+)'/\1/p")
  15. CI_OBS_VERSION=$(/bin/cat "${CI_WORKFLOW}" | /usr/bin/sed -En "s/[ ]+OBS_VERSION: '([0-9\.]+)'/\1/p")
  16. MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
  17. MACOS_MAJOR="$(echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 1)"
  18. MACOS_MINOR="$(echo ${MACOS_VERSION} | /usr/bin/cut -d '.' -f 2)"
  19. if [ "${TERM-}" -a -z "${CI}" ]; then
  20. COLOR_RED=$(/usr/bin/tput setaf 1)
  21. COLOR_GREEN=$(/usr/bin/tput setaf 2)
  22. COLOR_BLUE=$(/usr/bin/tput setaf 4)
  23. COLOR_ORANGE=$(/usr/bin/tput setaf 3)
  24. COLOR_RESET=$(/usr/bin/tput sgr0)
  25. else
  26. COLOR_RED=""
  27. COLOR_GREEN=""
  28. COLOR_BLUE=""
  29. COLOR_ORANGE=""
  30. COLOR_RESET=""
  31. fi
  32. ## DEFINE UTILITIES ##
  33. check_macos_version() {
  34. step "Check macOS version..."
  35. MIN_VERSION=${MACOSX_DEPLOYMENT_TARGET:-${CI_MACOSX_DEPLOYMENT_TARGET}}
  36. MIN_MAJOR=$(echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 1)
  37. MIN_MINOR=$(echo ${MIN_VERSION} | /usr/bin/cut -d '.' -f 2)
  38. if [ "${MACOS_MAJOR}" -lt "11" ] && [ "${MACOS_MINOR}" -lt "${MIN_MINOR}" ]; then
  39. error "WARNING: Minimum required macOS version is ${MIN_VERSION}, but running on ${MACOS_VERSION}"
  40. fi
  41. if [ "${MACOS_MAJOR}" -ge "11" ]; then
  42. export CODESIGN_LINKER="ON"
  43. fi
  44. }
  45. install_homebrew_deps() {
  46. if ! exists brew; then
  47. error "Homebrew not found - please install homebrew (https://brew.sh)"
  48. exit 1
  49. fi
  50. brew bundle --file "${CHECKOUT_DIR}/CI/include/Brewfile" ${QUIET:+--quiet}
  51. check_curl
  52. }
  53. check_curl() {
  54. if [ "${MACOS_MAJOR}" -lt "11" ] && [ "${MACOS_MINOR}" -lt "15" ]; then
  55. if [ ! -d /usr/local/opt/curl ]; then
  56. step "Installing Homebrew curl.."
  57. brew install curl
  58. fi
  59. CURLCMD="/usr/local/opt/curl/bin/curl"
  60. else
  61. CURLCMD="curl"
  62. fi
  63. if [ "${CI}" -o "${QUIET}" ]; then
  64. export CURLCMD="${CURLCMD} --silent --show-error --location -O"
  65. else
  66. export CURLCMD="${CURLCMD} --progress-bar --location --continue-at - -O"
  67. fi
  68. }
  69. check_archs() {
  70. step "Check Architecture..."
  71. ARCH="${ARCH:-universal}"
  72. if [ "${ARCH}" = "universal" ]; then
  73. CMAKE_ARCHS="x86_64;arm64"
  74. elif [ "${ARCH}" != "x86_64" -a "${ARCH}" != "arm64" ]; then
  75. caught_error "Unsupported architecture '${ARCH}' provided"
  76. else
  77. CMAKE_ARCHS="${ARCH}"
  78. fi
  79. }
  80. ## SET UP CODE SIGNING AND NOTARIZATION CREDENTIALS ##
  81. ##############################################################################
  82. # Apple Developer Identity needed:
  83. #
  84. # + Signing the code requires a developer identity in the system's keychain
  85. # + codesign will look up and find the identity automatically
  86. #
  87. ##############################################################################
  88. read_codesign_ident() {
  89. if [ ! -n "${CODESIGN_IDENT}" ]; then
  90. step "Code-signing Setup"
  91. read -p "${COLOR_ORANGE} + Apple developer application identity: ${COLOR_RESET}" CODESIGN_IDENT
  92. fi
  93. }
  94. read_codesign_ident_installer() {
  95. if [ ! -n "${CODESIGN_IDENT_INSTALLER}" ]; then
  96. step "Code-signing Setup for Installer"
  97. read -p "${COLOR_ORANGE} + Apple developer installer identity: ${COLOR_RESET}" CODESIGN_IDENT_INSTALLER
  98. fi
  99. }
  100. ##############################################################################
  101. # Apple Developer credentials necessary:
  102. #
  103. # + Signing for distribution and notarization require an active Apple
  104. # Developer membership
  105. # + An Apple Development identity is needed for code signing
  106. # (i.e. 'Apple Development: YOUR APPLE ID (PROVIDER)')
  107. # + Your Apple developer ID is needed for notarization
  108. # + An app-specific password is necessary for notarization from CLI
  109. # + This password will be stored in your macOS keychain under the identifier
  110. # 'OBS-Codesign-Password'with access Apple's 'altool' only.
  111. ##############################################################################
  112. read_codesign_pass() {
  113. step "Notarization Setup"
  114. if [ -z "${CODESIGN_IDENT_USER}" ]; then
  115. read -p "${COLOR_ORANGE} + Apple account id: ${COLOR_RESET}" CODESIGN_IDENT_USER
  116. fi
  117. if [ -z "${CODESIGN_IDENT_PASS}" ]; then
  118. CODESIGN_IDENT_PASS=$(stty -echo; read -p "${COLOR_ORANGE} + Apple developer password: ${COLOR_RESET}" secret; stty echo; echo $secret)
  119. echo ""
  120. fi
  121. step "Updating notarization keychain"
  122. echo -n "${COLOR_ORANGE}"
  123. /usr/bin/xcrun altool --store-password-in-keychain-item "OBS-Codesign-Password" -u "${CODESIGN_IDENT_USER}" -p "${CODESIGN_IDENT_PASS}"
  124. echo -n "${COLOR_RESET}"
  125. CODESIGN_IDENT_SHORT=$(echo "${CODESIGN_IDENT}" | /usr/bin/sed -En "s/.+\((.+)\)/\1/p")
  126. }