02_build_obs.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/bash
  2. ##############################################################################
  3. # Linux build function
  4. ##############################################################################
  5. #
  6. # This script file can be included in build scripts for Linux or run directly
  7. #
  8. ##############################################################################
  9. # Halt on errors
  10. set -eE
  11. build_obs() {
  12. status "Build OBS"
  13. trap "caught_error 'build app'" ERR
  14. if [ -z "${CI}" ]; then
  15. _backup_artifacts
  16. fi
  17. step "Configure OBS..."
  18. _configure_obs
  19. ensure_dir "${CHECKOUT_DIR}/"
  20. step "Build OBS targets..."
  21. cmake --build ${BUILD_DIR}
  22. }
  23. # Function to configure OBS build
  24. _configure_obs() {
  25. ensure_dir "${CHECKOUT_DIR}"
  26. status "Configuration of OBS build system..."
  27. trap "caught_error 'configure build'" ERR
  28. check_ccache
  29. if [ "${TWITCH_CLIENTID}" -a "${TWITCH_HASH}" ]; then
  30. TWITCH_OPTIONS="-DTWITCH_CLIENTID='${TWITCH_CLIENTID}' -DTWITCH_HASH='${TWITCH_HASH}'"
  31. fi
  32. if [ "${RESTREAM_CLIENTID}" -a "${RESTREAM_HASH}" ]; then
  33. RESTREAM_OPTIONS="-DRESTREAM_CLIENTID='${RESTREAM_CLIENTID}' -DRESTREAM_HASH='${RESTREAM_HASH}'"
  34. fi
  35. if [ "${YOUTUBE_CLIENTID}" -a "${YOUTUBE_CLIENTID_HASH}" -a "${YOUTUBE_SECRET}" -a "{YOUTUBE_SECRET_HASH}" ]; then
  36. YOUTUBE_OPTIONS="-DYOUTUBE_CLIENTID='${YOUTUBE_CLIENTID}' -DYOUTUBE_CLIENTID_HASH='${YOUTUBE_CLIENTID_HASH}' -DYOUTUBE_SECRET='${YOUTUBE_SECRET}' -DYOUTUBE_SECRET_HASH='${YOUTUBE_SECRET_HASH}'"
  37. fi
  38. if [ "${PORTABLE}" ]; then
  39. PORTABLE_BUILD="ON"
  40. fi
  41. if [ "${DISABLE_PIPEWIRE}" ]; then
  42. PIPEWIRE_OPTION="-DENABLE_PIPEWIRE=OFF"
  43. fi
  44. cmake -S . -B ${BUILD_DIR} -G Ninja \
  45. -DCEF_ROOT_DIR="${DEPS_BUILD_DIR}/cef_binary_${LINUX_CEF_BUILD_VERSION:-${CI_LINUX_CEF_VERSION}}_linux64" \
  46. -DCMAKE_BUILD_TYPE=${BUILD_CONFIG} \
  47. -DLINUX_PORTABLE=${PORTABLE_BUILD:-OFF} \
  48. -DENABLE_AJA=OFF \
  49. ${PIPEWIRE_OPTION} \
  50. ${YOUTUBE_OPTIONS} \
  51. ${TWITCH_OPTIONS} \
  52. ${RESTREAM_OPTIONS} \
  53. ${CI:+-DENABLE_UNIT_TESTS=ON -DBUILD_FOR_DISTRIBUTION=${BUILD_FOR_DISTRIBUTION} -DOBS_BUILD_NUMBER=${GITHUB_RUN_ID}} \
  54. ${QUIET:+-Wno-deprecated -Wno-dev --log-level=ERROR}
  55. }
  56. # Function to backup previous build artifacts
  57. _backup_artifacts() {
  58. ensure_dir "${CHECKOUT_DIR}"
  59. if [ -d ${BUILD_DIR} ]; then
  60. status "Backup of old OBS build artifacts"
  61. CUR_DATE=$(date +"%Y-%m-%d@%H%M%S")
  62. NIGHTLY_DIR="${CHECKOUT_DIR}/nightly-${CUR_DATE}"
  63. PACKAGE_NAME=$(find ${BUILD_DIR} -maxdepth 1 -name "*.deb" | sort -rn | head -1)
  64. if [ "${PACKAGE_NAME}" ]; then
  65. step "Back up $(basename "${PACKAGE_NAME}")..."
  66. ensure_dir "${NIGHTLY_DIR}"
  67. mv "../${BUILD_DIR}/$(basename "${PACKAGE_NAME}")" ${NIGHTLY_DIR}/
  68. info "You can find ${PACKAGE_NAME} in ${NIGHTLY_DIR}"
  69. fi
  70. fi
  71. }
  72. build-obs-standalone() {
  73. CHECKOUT_DIR="$(git rev-parse --show-toplevel)"
  74. PRODUCT_NAME="OBS-Studio"
  75. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  76. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  77. source "${CHECKOUT_DIR}/CI/include/build_support_linux.sh"
  78. build_obs
  79. }
  80. print_usage() {
  81. echo -e "Usage: ${0}\n" \
  82. "-h, --help : Print this help\n" \
  83. "-q, --quiet : Suppress most build process output\n" \
  84. "-v, --verbose : Enable more verbose build process output\n" \
  85. "-p, --portable : Create portable build (default: off)\n" \
  86. "--disable-pipewire : Disable building with PipeWire support (default: off)\n" \
  87. "--build-dir : Specify alternative build directory (default: build)\n"
  88. }
  89. build-obs-main() {
  90. if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
  91. while true; do
  92. case "${1}" in
  93. -h | --help ) print_usage; exit 0 ;;
  94. -q | --quiet ) export QUIET=TRUE; shift ;;
  95. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  96. -p | --portable ) export PORTABLE=TRUE; shift ;;
  97. --disable-pipewire ) DISABLE_PIPEWIRE=TRUE; shift ;;
  98. --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
  99. -- ) shift; break ;;
  100. * ) break ;;
  101. esac
  102. done
  103. build-obs-standalone
  104. fi
  105. }
  106. build-obs-main $*