Parcourir la source

CI: Update Linux build scripts

PatTheMav il y a 3 ans
Parent
commit
e59c86db9f

+ 103 - 0
CI/build-linux.sh

@@ -0,0 +1,103 @@
+#!/bin/bash
+
+##############################################################################
+# Linux plugin build script
+##############################################################################
+#
+# This script contains all steps necessary to:
+#
+#   * Build libobs and obs-frontend-api with all required dependencies
+#   * Build your plugin
+#   * Create debian package
+#
+# Parameters:
+#   -h, --help                      : Print usage help
+#   -q, --quiet                     : Suppress most build process output
+#   -v, --verbose                   : Enable more verbose build process output
+#   -p, --package                   : Create installer for plugin
+#   -b, --build-dir                 : Specify alternative build directory
+#                                     (default: build)
+#
+# Environment Variables (optional):
+#   OBS_VERSION         : OBS Version
+#
+##############################################################################
+
+# Halt on errors
+set -eE
+
+## SET UP ENVIRONMENT ##
+_RUN_OBS_BUILD_SCRIPT=TRUE
+
+CHECKOUT_DIR="$(git rev-parse --show-toplevel)"
+if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
+    source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
+fi
+PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
+DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
+OBS_BUILD_DIR="${CHECKOUT_DIR}/../obs-studio"
+source "${CHECKOUT_DIR}/CI/include/build_support.sh"
+source "${CHECKOUT_DIR}/CI/include/build_support_linux.sh"
+
+## DEPENDENCY INSTALLATION ##
+source "${CHECKOUT_DIR}/CI/linux/01_install_dependencies.sh"
+
+## OBS LIBRARY BUILD ##
+source "${CHECKOUT_DIR}/CI/linux/02_build_obs_libs.sh"
+
+## PLUGIN BUILD ##
+source "${CHECKOUT_DIR}/CI/linux/03_build_plugin.sh"
+
+## PLUGIN PACKAGE AND NOTARIZE ##
+source "${CHECKOUT_DIR}/CI/linux/04_package_plugin.sh"
+
+## MAIN SCRIPT FUNCTIONS ##
+print_usage() {
+    echo -e "build_linux.sh - Build script for ${PRODUCT_NAME}\n"
+    echo -e "Usage: ${0}\n" \
+        "-h, --help                     : Print this help\n" \
+        "-q, --quiet                    : Suppress most build process output\n" \
+        "-v, --verbose                  : Enable more verbose build process output\n" \
+        "-d, --skip-dependency-checks   : Skip dependency checks\n" \
+        "-p, --package                  : Create installer for plugin\n" \
+        "-b, --build-dir                : Specify alternative build directory (default: build)\n"
+
+}
+
+obs-build-main() {
+    while true; do
+        case "${1}" in
+            -h | --help ) print_usage; exit 0 ;;
+            -d | --skip-dependency-checks ) SKIP_DEP_CHECKS=TRUE; shift ;;
+            -q | --quiet ) export QUIET=TRUE; shift ;;
+            -v | --verbose ) export VERBOSE=TRUE; shift ;;
+            -p | --package ) PACKAGE=TRUE; shift ;;
+            -b | --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
+            -- ) shift; break ;;
+            * ) break ;;
+        esac
+    done
+
+    ensure_dir "${CHECKOUT_DIR}"
+    step "Fetching version tags..."
+    git fetch origin --tags
+    GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
+    GIT_HASH=$(git rev-parse --short HEAD)
+    GIT_TAG=$(git describe --tags --abbrev=0 2&>/dev/null || true)
+    FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-linux"
+
+    if [ -z "${SKIP_DEP_CHECKS}" ]; then
+        install_dependencies
+    fi
+
+    build_obs_libs
+    build_obs_plugin
+
+    if [ -n "${PACKAGE}" ]; then
+        package_obs_plugin
+    fi
+
+    cleanup
+}
+
+obs-build-main $*

+ 33 - 0
CI/include/build_support_linux.sh

@@ -0,0 +1,33 @@
+#!/bin/bash
+
+##############################################################################
+# Linux support functions
+##############################################################################
+#
+# This script file can be included in build scripts for Linux.
+#
+##############################################################################
+
+# Setup build environment
+
+CI_OBS_VERSION=$(cat "${CI_WORKFLOW}" | sed -En "s/[ ]+OBS_VERSION: '([0-9\.]+)'/\1/p")
+
+if [ "${TERM-}" -a -z "${CI}" ]; then
+    COLOR_RED=$(tput setaf 1)
+    COLOR_GREEN=$(tput setaf 2)
+    COLOR_BLUE=$(tput setaf 4)
+    COLOR_ORANGE=$(tput setaf 3)
+    COLOR_RESET=$(tput sgr0)
+else
+    COLOR_RED=""
+    COLOR_GREEN=""
+    COLOR_BLUE=""
+    COLOR_ORANGE=""
+    COLOR_RESET=""
+fi
+
+if [ "${CI}" -o "${QUIET}" ]; then
+    export CURLCMD="curl --silent --show-error --location -O"
+else
+    export CURLCMD="curl --progress-bar --location --continue-at - -O"
+fi

+ 127 - 0
CI/linux/01_install_dependencies.sh

@@ -0,0 +1,127 @@
+#!/bin/bash
+
+##############################################################################
+# Linux dependency management function
+##############################################################################
+#
+# This script file can be included in build scripts for Linux or run directly
+#
+##############################################################################
+
+# Halt on errors
+set -eE
+
+install_obs-studio() {
+    if [ -n "${OBS_BRANCH}" ]; then
+        CHECKOUT_REF="${OBS_BRANCH}"
+    else
+        CHECKOUT_REF="tags/${OBS_VERSION:-${CI_OBS_VERSION}}"
+    fi
+
+    ensure_dir "${OBS_BUILD_DIR}"
+
+    if [ ! -d "${OBS_BUILD_DIR}/.git" ]; then
+        git clone --recursive https://github.com/obsproject/obs-studio "$(pwd)"
+        git fetch origin --tags
+        git checkout ${CHECKOUT_REF} -b obs-plugin-build
+    else
+        if ! git show-ref --verify --quiet refs/heads/obs-plugin-build; then
+            git checkout ${CHECKOUT_REF} -b obs-plugin-build
+        else
+            git checkout obs-plugin-build
+        fi
+    fi
+}
+
+install_linux_dependencies() {
+    sudo dpkg --add-architecture amd64
+    sudo apt-get -qq update
+    sudo apt-get install -y \
+        build-essential \
+        ninja-build \
+        clang \
+        clang-format \
+        qtbase5-dev \
+        libqt5svg5-dev \
+        libqt5x11extras5-dev \
+        qtbase5-private-dev \
+        libwayland-dev \
+        libavcodec-dev \
+        libavdevice-dev \
+        libavfilter-dev \
+        libavformat-dev \
+        libavutil-dev \
+        libswresample-dev \
+        libswscale-dev \
+        libx264-dev \
+        libjansson-dev \
+        libpulse-dev \
+        libx11-dev \
+        libx11-xcb-dev \
+        libmbedtls-dev \
+        libgl1-mesa-dev \
+        pkg-config \
+        libcurl4-openssl-dev
+
+    if ! type cmake &>/dev/null; then
+        sudo apt-get install -y cmake
+    fi
+}
+
+install_dependencies() {
+    status "Installing build dependencies"
+    trap "caught_error 'install_dependencies'" ERR
+
+    BUILD_DEPS=(
+        "obs-studio ${OBS_VERSION:-${CI_OBS_VERSION}}"
+    )
+
+    install_linux_dependencies
+
+    for DEPENDENCY in "${BUILD_DEPS[@]}"; do
+        set -- ${DEPENDENCY}
+        trap "caught_error ${DEPENDENCY}" ERR
+        FUNC_NAME="install_${1}"
+        ${FUNC_NAME} ${2} ${3}
+    done
+}
+
+install-dependencies-standalone() {
+    CHECKOUT_DIR="$(git rev-parse --show-toplevel)"
+    if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
+        source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
+    fi
+    PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
+    DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
+    OBS_BUILD_DIR="${CHECKOUT_DIR}/../obs-studio"
+    source "${CHECKOUT_DIR}/CI/include/build_support.sh"
+    source "${CHECKOUT_DIR}/CI/include/build_support_linux.sh"
+
+    status "Setting up plugin build dependencies"
+    install_dependencies
+}
+
+print_usage() {
+    echo -e "Usage: ${0}\n" \
+            "-h, --help                     : Print this help\n" \
+            "-q, --quiet                    : Suppress most build process output\n" \
+            "-v, --verbose                  : Enable more verbose build process output\n"
+}
+
+install-dependencies-main() {
+    if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
+        while true; do
+            case "${1}" in
+                -h | --help ) print_usage; exit 0 ;;
+                -q | --quiet ) export QUIET=TRUE; shift ;;
+                -v | --verbose ) export VERBOSE=TRUE; shift ;;
+                -- ) shift; break ;;
+                * ) break ;;
+            esac
+        done
+
+        install-dependencies-standalone
+    fi
+}
+
+install-dependencies-main $*

+ 73 - 0
CI/linux/02_build_obs_libs.sh

@@ -0,0 +1,73 @@
+#!/bin/bash
+
+##############################################################################
+# Linux libobs library build function
+##############################################################################
+#
+# This script file can be included in build scripts for Linux or run directly
+#
+##############################################################################
+
+# Halt on errors
+set -eE
+
+build_obs_libs() {
+    status "Build libobs and obs-frontend-api"
+    trap "caught_error 'build_obs_libs'" ERR
+    check_ccache
+
+    ensure_dir "${OBS_BUILD_DIR}"
+
+    step "Configuring OBS build system"
+    check_ccache
+    cmake -S . -B plugin_${BUILD_DIR} -G Ninja ${CMAKE_CCACHE_OPTIONS} \
+        -DCMAKE_BUILD_TYPE=${BUILD_CONFIG} \
+        -DENABLE_PLUGINS=OFF \
+        -DENABLE_UI=ON \
+        -DENABLE_SCRIPTING=OFF \
+        -DENABLE_PIPEWIRE=OFF \
+        ${QUIET:+-Wno-deprecated -Wno-dev --log-level=ERROR}
+
+    step "Building libobs and obs-frontend-api"
+    cmake --build plugin_${BUILD_DIR} -t obs-frontend-api
+}
+
+build-obs-libs-standalone() {
+    CHECKOUT_DIR="$(git rev-parse --show-toplevel)"
+    if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
+        source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
+    fi
+    PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
+    OBS_BUILD_DIR="${CHECKOUT_DIR}/../obs-studio"
+    source "${CHECKOUT_DIR}/CI/include/build_support.sh"
+    source "${CHECKOUT_DIR}/CI/include/build_support_linux.sh"
+
+    build_obs_libs
+}
+
+print_usage() {
+    echo -e "Usage: ${0}\n" \
+            "-h, --help                     : Print this help\n" \
+            "-q, --quiet                    : Suppress most build process output\n" \
+            "-v, --verbose                  : Enable more verbose build process output\n" \
+            "--build-dir                    : Specify alternative build directory (default: build)\n"
+}
+
+build-obs-libs-main() {
+    if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
+        while true; do
+            case "${1}" in
+                -h | --help ) print_usage; exit 0 ;;
+                -q | --quiet ) export QUIET=TRUE; shift ;;
+                -v | --verbose ) export VERBOSE=TRUE; shift ;;
+                --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
+                -- ) shift; break ;;
+                * ) break ;;
+            esac
+        done
+
+        build-obs-libs-standalone
+    fi
+}
+
+build-obs-libs-main $*

+ 66 - 0
CI/linux/03_build_plugin.sh

@@ -0,0 +1,66 @@
+#!/bin/bash
+
+##############################################################################
+# Linux libobs plugin build function
+##############################################################################
+#
+# This script file can be included in build scripts for Linux or run directly
+#
+##############################################################################
+
+# Halt on errors
+set -eE
+
+build_obs_plugin() {
+    status "Build plugin ${PRODUCT_NAME}"
+    trap "caught_error 'builds_obs_plugin'" ERR
+
+    ensure_dir "${CHECKOUT_DIR}"
+
+    step "Configuring OBS plugin build system"
+    check_ccache
+
+    cmake -S . -B ${BUILD_DIR} -G Ninja ${CMAKE_CCACHE_OPTIONS} ${QUIET:+-Wno-deprecated -Wno-dev --log-level=ERROR}
+
+    step "Building OBS plugin"
+    cmake --build ${BUILD_DIR}
+}
+
+build-plugin-standalone() {
+    CHECKOUT_DIR="$(git rev-parse --show-toplevel)"
+    if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
+        source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
+    fi
+    PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
+    source "${CHECKOUT_DIR}/CI/include/build_support.sh"
+    source "${CHECKOUT_DIR}/CI/include/build_support_linux.sh"
+
+    build_obs_plugin
+}
+
+print_usage() {
+    echo -e "Usage: ${0}\n" \
+            "-h, --help                     : Print this help\n" \
+            "-q, --quiet                    : Suppress most build process output\n" \
+            "-v, --verbose                  : Enable more verbose build process output\n" \
+            "--build-dir                    : Specify alternative build directory (default: build)\n"
+}
+
+build-plugin-main() {
+    if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
+        while true; do
+            case "${1}" in
+                -h | --help ) print_usage; exit 0 ;;
+                -q | --quiet ) export QUIET=TRUE; shift ;;
+                -v | --verbose ) export VERBOSE=TRUE; shift ;;
+                --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
+                -- ) shift; break ;;
+                * ) break ;;
+            esac
+        done
+
+        build-plugin-standalone
+    fi
+}
+
+build-plugin-main $*

+ 68 - 0
CI/linux/04_package_plugin.sh

@@ -0,0 +1,68 @@
+#!/bin/bash
+
+##############################################################################
+# Linux libobs plugin build function
+##############################################################################
+#
+# This script file can be included in build scripts for Linux or run directly
+#
+##############################################################################
+
+# Halt on errors
+set -eE
+
+package_obs_plugin() {
+    status "Package OBS plugin ${PRODUCT_NAME}"
+    trap "caught_error 'package_obs_plugin'" ERR
+
+    ensure_dir "${CHECKOUT_DIR}"
+
+    step "Package ${PRODUCT_NAME}..."
+
+    cmake --build ${BUILD_DIR} -t package
+
+}
+
+package-plugin-standalone() {
+    CHECKOUT_DIR="$(git rev-parse --show-toplevel)"
+    if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
+        source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
+    fi
+    PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
+    source "${CHECKOUT_DIR}/CI/include/build_support.sh"
+    source "${CHECKOUT_DIR}/CI/include/build_support_linux.sh"
+
+    GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
+    GIT_HASH=$(git rev-parse --short HEAD)
+    GIT_TAG=$(git describe --tags --abbrev=0 2&>/dev/null || true)
+    FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-0.0.1}-${GIT_HASH}.deb"
+
+    package_obs_plugin
+}
+
+print_usage() {
+    echo -e "Usage: ${0}\n" \
+            "-h, --help                     : Print this help\n" \
+            "-q, --quiet                    : Suppress most build process output\n" \
+            "-v, --verbose                  : Enable more verbose build process output\n" \
+            "--build-dir                    : Specify alternative build directory (default: build)\n"
+}
+
+package-plugin-main() {
+    if [ ! -n "${_RUN_OBS_BUILD_SCRIPT}" ]; then
+        while true; do
+            case "${1}" in
+                -h | --help ) print_usage; exit 0 ;;
+                -q | --quiet ) export QUIET=TRUE; shift ;;
+                -v | --verbose ) export VERBOSE=TRUE; shift ;;
+                --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
+                -- ) shift; break ;;
+                * ) break ;;
+            esac
+        done
+
+        package-plugin-standalone
+    fi
+}
+
+package-plugin-main $*

+ 0 - 4
ci/ci_includes.sh.in

@@ -1,4 +0,0 @@
-PLUGIN_NAME="@CMAKE_PROJECT_NAME@"
-PLUGIN_VERSION="@CMAKE_PROJECT_VERSION@"
-MACOS_BUNDLEID="@MACOS_BUNDLEID@"
-LINUX_MAINTAINER_EMAIL="@LINUX_MAINTAINER_EMAIL@"

+ 0 - 6
ci/linux/build-ubuntu.sh

@@ -1,6 +0,0 @@
-#!/bin/sh
-set -ex
-
-mkdir build && cd build
-cmake -DCMAKE_INSTALL_PREFIX=/usr ..
-make -j4

+ 0 - 19
ci/linux/install-dependencies-ubuntu.sh

@@ -1,19 +0,0 @@
-#!/bin/sh
-set -ex
-
-sudo add-apt-repository -y ppa:obsproject/obs-studio
-sudo apt-get -qq update
-
-sudo apt-get install -y \
-	libc-dev-bin \
-	libc6-dev git \
-	build-essential \
-	checkinstall \
-	cmake \
-	obs-studio \
-	qtbase5-dev
-
-# Dirty hack
-sudo wget -O /usr/include/obs/obs-frontend-api.h https://raw.githubusercontent.com/obsproject/obs-studio/25.0.0/UI/obs-frontend-api/obs-frontend-api.h
-
-sudo ldconfig

+ 0 - 25
ci/linux/package-ubuntu.sh

@@ -1,25 +0,0 @@
-#!/bin/bash
-
-set -e
-
-script_dir=$(dirname "$0")
-source "$script_dir/../ci_includes.generated.sh"
-
-export GIT_HASH=$(git rev-parse --short HEAD)
-export PKG_VERSION="1-$GIT_HASH-$BRANCH_SHORT_NAME-git"
-
-if [[ "$BRANCH_FULL_NAME" =~ "^refs/tags/" ]]; then
-	export PKG_VERSION="$BRANCH_SHORT_NAME"
-fi
-
-cd ./build
-
-PAGER="cat" sudo checkinstall -y --type=debian --fstrans=no --nodoc \
-	--backup=no --deldoc=yes --install=no \
-	--pkgname="$PLUGIN_NAME" --pkgversion="$PKG_VERSION" \
-	--pkglicense="GPLv2.0" --maintainer="$LINUX_MAINTAINER_EMAIL" \
-	--pkggroup="video" \
-	--requires="obs-studio \(\>= 25.0.7\), libqt5core5a, libqt5widgets5, qt5-image-formats-plugins" \
-	--pakdir="../package"
-
-sudo chmod ao+r ../package/*