|
@@ -17,56 +17,76 @@ setopt FUNCTION_ARGZERO
|
|
# setopt XTRACE
|
|
# setopt XTRACE
|
|
|
|
|
|
autoload -Uz is-at-least && if ! is-at-least 5.2; then
|
|
autoload -Uz is-at-least && if ! is-at-least 5.2; then
|
|
- print -u2 -PR "%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade Zsh to fix this issue."
|
|
|
|
|
|
+ print -u2 -PR "${CI:+::error::}%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade Zsh to fix this issue."
|
|
exit 1
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
|
|
-_trap_error() {
|
|
|
|
- print -u2 -PR '%F{1} ✖︎ script execution error%f'
|
|
|
|
- print -PR -e "
|
|
|
|
|
|
+TRAPEXIT() {
|
|
|
|
+ local return_value=$?
|
|
|
|
+
|
|
|
|
+ if (( ${+CI} )) unset NSUnbufferedIO
|
|
|
|
+
|
|
|
|
+ return ${return_value}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+TRAPZERR() {
|
|
|
|
+ if (( ${_loglevel:-3} > 2 )) {
|
|
|
|
+ print -u2 -PR "${CI:+::error::}%F{1} ✖︎ script execution error%f"
|
|
|
|
+ print -PR -e "
|
|
Callstack:
|
|
Callstack:
|
|
${(j:\n :)funcfiletrace}
|
|
${(j:\n :)funcfiletrace}
|
|
- "
|
|
|
|
|
|
+ "
|
|
|
|
+ }
|
|
|
|
+
|
|
exit 2
|
|
exit 2
|
|
}
|
|
}
|
|
|
|
|
|
build() {
|
|
build() {
|
|
if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${ZSH_ARGZERO:A:h}
|
|
if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${ZSH_ARGZERO:A:h}
|
|
local host_os=${${(s:-:)ZSH_ARGZERO:t:r}[2]}
|
|
local host_os=${${(s:-:)ZSH_ARGZERO:t:r}[2]}
|
|
- local target="${host_os}-${CPUTYPE}"
|
|
|
|
local project_root=${SCRIPT_HOME:A:h:h}
|
|
local project_root=${SCRIPT_HOME:A:h:h}
|
|
- local buildspec_file="${project_root}/buildspec.json"
|
|
|
|
-
|
|
|
|
- trap '_trap_error' ZERR
|
|
|
|
|
|
+ local buildspec_file=${project_root}/buildspec.json
|
|
|
|
|
|
fpath=("${SCRIPT_HOME}/utils.zsh" ${fpath})
|
|
fpath=("${SCRIPT_HOME}/utils.zsh" ${fpath})
|
|
- autoload -Uz log_info log_error log_output set_loglevel check_${host_os} setup_${host_os} setup_obs setup_ccache
|
|
|
|
|
|
+ autoload -Uz log_group log_info log_error log_output set_loglevel check_${host_os} setup_ccache
|
|
|
|
|
|
if [[ ! -r ${buildspec_file} ]] {
|
|
if [[ ! -r ${buildspec_file} ]] {
|
|
log_error \
|
|
log_error \
|
|
- 'No buildspec.json found. Please create a build specification for your project.' \
|
|
|
|
- 'A buildspec.json.template file is provided in the repository to get you started.'
|
|
|
|
|
|
+ 'No buildspec.json found. Please create a build specification for your project.'
|
|
return 2
|
|
return 2
|
|
}
|
|
}
|
|
|
|
|
|
typeset -g -a skips=()
|
|
typeset -g -a skips=()
|
|
- local -i _verbosity=1
|
|
|
|
- local -r _version='1.0.0'
|
|
|
|
|
|
+ local -i verbosity=1
|
|
|
|
+ local -r _version='2.0.0'
|
|
local -r -a _valid_targets=(
|
|
local -r -a _valid_targets=(
|
|
- macos-x86_64
|
|
|
|
- macos-arm64
|
|
|
|
macos-universal
|
|
macos-universal
|
|
linux-x86_64
|
|
linux-x86_64
|
|
linux-aarch64
|
|
linux-aarch64
|
|
)
|
|
)
|
|
|
|
+ local target
|
|
|
|
+ local config='RelWithDebInfo'
|
|
local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel)
|
|
local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel)
|
|
- if [[ ${host_os} == 'macos' ]] {
|
|
|
|
- local -r -a _valid_generators=(Xcode Ninja 'Unix Makefiles')
|
|
|
|
- local generator="${${CI:+Ninja}:-Xcode}"
|
|
|
|
- } else {
|
|
|
|
|
|
+ local -i codesign=0
|
|
|
|
+
|
|
|
|
+ if [[ ${host_os} == linux ]] {
|
|
local -r -a _valid_generators=(Ninja 'Unix Makefiles')
|
|
local -r -a _valid_generators=(Ninja 'Unix Makefiles')
|
|
local generator='Ninja'
|
|
local generator='Ninja'
|
|
|
|
+ local -r _usage_host="
|
|
|
|
+%F{yellow} Additional options for Linux builds%f
|
|
|
|
+ -----------------------------------------------------------------------------
|
|
|
|
+ %B--generator%b Specify build system to generate
|
|
|
|
+ Available generators:
|
|
|
|
+ - Ninja
|
|
|
|
+ - Unix Makefiles"
|
|
|
|
+ } elif [[ ${host_os} == macos ]] {
|
|
|
|
+ local -r _usage_host="
|
|
|
|
+%F{yellow} Additional options for macOS builds%f
|
|
|
|
+ -----------------------------------------------------------------------------
|
|
|
|
+ %B-s | --codesign%b Enable codesigning (macOS only)"
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ local -i print_config=0
|
|
local -r _usage="
|
|
local -r _usage="
|
|
Usage: %B${functrace[1]%:*}%b <option> [<options>]
|
|
Usage: %B${functrace[1]%:*}%b <option> [<options>]
|
|
|
|
|
|
@@ -74,26 +94,21 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
|
|
|
|
|
|
%F{yellow} Build configuration options%f
|
|
%F{yellow} Build configuration options%f
|
|
-----------------------------------------------------------------------------
|
|
-----------------------------------------------------------------------------
|
|
- %B-t | --target%b Specify target - default: %B%F{green}${host_os}-${CPUTYPE}%f%b
|
|
|
|
- %B-c | --config%b Build configuration - default: %B%F{green}RelWithDebInfo%f%b
|
|
|
|
- %B-s | --codesign%b Enable codesigning (macOS only)
|
|
|
|
- %B--generator%b Specify build system to generate - default: %B%F{green}Ninja%f%b
|
|
|
|
- Available generators:
|
|
|
|
- - Ninja
|
|
|
|
- - Unix Makefiles
|
|
|
|
- - Xcode (macOS only)
|
|
|
|
|
|
+ %B-t | --target%b Specify target
|
|
|
|
+ %B-c | --config%b Build configuration
|
|
|
|
+ %B--skip-[all|build|deps]%b Skip all|building|checking for dependencies
|
|
|
|
|
|
%F{yellow} Output options%f
|
|
%F{yellow} Output options%f
|
|
-----------------------------------------------------------------------------
|
|
-----------------------------------------------------------------------------
|
|
%B-q | --quiet%b Quiet (error output only)
|
|
%B-q | --quiet%b Quiet (error output only)
|
|
%B-v | --verbose%b Verbose (more detailed output)
|
|
%B-v | --verbose%b Verbose (more detailed output)
|
|
- %B--skip-[all|build|deps|unpack]%b Skip all|building OBS|checking for dependencies|unpacking dependencies
|
|
|
|
%B--debug%b Debug (very detailed and added output)
|
|
%B--debug%b Debug (very detailed and added output)
|
|
|
|
|
|
%F{yellow} General options%f
|
|
%F{yellow} General options%f
|
|
-----------------------------------------------------------------------------
|
|
-----------------------------------------------------------------------------
|
|
%B-h | --help%b Print this usage help
|
|
%B-h | --help%b Print this usage help
|
|
- %B-V | --version%b Print script version information"
|
|
|
|
|
|
+ %B-V | --version%b Print script version information
|
|
|
|
+${_usage_host:-}"
|
|
|
|
|
|
local -a args
|
|
local -a args
|
|
while (( # )) {
|
|
while (( # )) {
|
|
@@ -127,27 +142,30 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
|
|
log_output ${_usage}
|
|
log_output ${_usage}
|
|
exit 2
|
|
exit 2
|
|
}
|
|
}
|
|
- BUILD_CONFIG=${2}
|
|
|
|
|
|
+ config=${2}
|
|
shift 2
|
|
shift 2
|
|
;;
|
|
;;
|
|
- -s|--codesign) CODESIGN=1; shift ;;
|
|
|
|
- -q|--quiet) (( _verbosity -= 1 )) || true; shift ;;
|
|
|
|
- -v|--verbose) (( _verbosity += 1 )); shift ;;
|
|
|
|
|
|
+ -s|--codesign) codesign=1; shift ;;
|
|
|
|
+ -q|--quiet) (( verbosity -= 1 )) || true; shift ;;
|
|
|
|
+ -v|--verbose) (( verbosity += 1 )); shift ;;
|
|
-h|--help) log_output ${_usage}; exit 0 ;;
|
|
-h|--help) log_output ${_usage}; exit 0 ;;
|
|
-V|--version) print -Pr "${_version}"; exit 0 ;;
|
|
-V|--version) print -Pr "${_version}"; exit 0 ;;
|
|
- --debug) _verbosity=3; shift ;;
|
|
|
|
|
|
+ --debug) verbosity=3; shift ;;
|
|
--generator)
|
|
--generator)
|
|
- if (( ! ${_valid_generators[(Ie)${2}]} )) {
|
|
|
|
- log_error "Invalid value %B${2}%b for option %B${1}%b"
|
|
|
|
- log_output ${_usage}
|
|
|
|
- exit 2
|
|
|
|
|
|
+ if [[ ${host_os} == linux ]] {
|
|
|
|
+ if (( ! ${_valid_generators[(Ie)${2}]} )) {
|
|
|
|
+ log_error "Invalid value %B${2}%b for option %B${1}%b"
|
|
|
|
+ log_output ${_usage}
|
|
|
|
+ exit 2
|
|
|
|
+ }
|
|
|
|
+ generator=${2}
|
|
}
|
|
}
|
|
- generator=${2}
|
|
|
|
shift 2
|
|
shift 2
|
|
;;
|
|
;;
|
|
|
|
+ --print-config) print_config=1; skips+=(deps); shift ;;
|
|
--skip-*)
|
|
--skip-*)
|
|
- local _skip="${${(s:-:)1}[-1]}"
|
|
|
|
- local _check=(all deps unpack build)
|
|
|
|
|
|
+ local -r _skip="${${(s:-:)1}[-1]}"
|
|
|
|
+ local -r -a _check=(all build deps)
|
|
(( ${_check[(Ie)${_skip}]} )) || log_warning "Invalid skip mode %B${_skip}%b supplied"
|
|
(( ${_check[(Ie)${_skip}]} )) || log_warning "Invalid skip mode %B${_skip}%b supplied"
|
|
typeset -g -a skips=(${skips} ${_skip})
|
|
typeset -g -a skips=(${skips} ${_skip})
|
|
shift
|
|
shift
|
|
@@ -156,110 +174,119 @@ Usage: %B${functrace[1]%:*}%b <option> [<options>]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ : "${target:="${host_os}-${CPUTYPE}"}"
|
|
|
|
+
|
|
set -- ${(@)args}
|
|
set -- ${(@)args}
|
|
- set_loglevel ${_verbosity}
|
|
|
|
|
|
+ set_loglevel ${verbosity}
|
|
|
|
|
|
- check_${host_os}
|
|
|
|
- setup_ccache
|
|
|
|
|
|
+ if (( ! (${skips[(Ie)all]} + ${skips[(Ie)deps]}) )) {
|
|
|
|
+ check_${host_os}
|
|
|
|
+ setup_ccache
|
|
|
|
+ }
|
|
|
|
|
|
- typeset -g QT_VERSION
|
|
|
|
- typeset -g DEPLOYMENT_TARGET
|
|
|
|
- typeset -g OBS_DEPS_VERSION
|
|
|
|
- setup_${host_os}
|
|
|
|
|
|
+ if [[ ${host_os} == linux ]] {
|
|
|
|
+ autoload -Uz setup_linux && setup_linux
|
|
|
|
+ }
|
|
|
|
|
|
local product_name
|
|
local product_name
|
|
local product_version
|
|
local product_version
|
|
- local product_author
|
|
|
|
- local product_email
|
|
|
|
-
|
|
|
|
- IFS=/ read -r product_name product_version product_author product_email <<< \
|
|
|
|
- "$(jq -r '. | {name, version, author, email} | join("/")' ${buildspec_file})"
|
|
|
|
-
|
|
|
|
- product_author=\"${product_author}\"
|
|
|
|
- product_email=\"${product_email}\"
|
|
|
|
-
|
|
|
|
- case ${host_os} {
|
|
|
|
- macos)
|
|
|
|
- sed -i '' \
|
|
|
|
- "s/project(\(.*\) VERSION \(.*\))/project(${product_name} VERSION ${product_version})/" \
|
|
|
|
- "${project_root}/CMakeLists.txt"
|
|
|
|
- sed -i '' \
|
|
|
|
- "s/set(PLUGIN_AUTHOR \(.*\))/set(PLUGIN_AUTHOR ${product_author})/"\
|
|
|
|
- "${project_root}/CMakeLists.txt"
|
|
|
|
- sed -i '' \
|
|
|
|
- "s/set(LINUX_MAINTAINER_EMAIL \(.*\))/set(LINUX_MAINTAINER_EMAIL ${product_email})/"\
|
|
|
|
- "${project_root}/CMakeLists.txt"
|
|
|
|
- ;;
|
|
|
|
- linux)
|
|
|
|
- sed -i'' \
|
|
|
|
- "s/project(\(.*\) VERSION \(.*\))/project(${product_name} VERSION ${product_version})/"\
|
|
|
|
- "${project_root}/CMakeLists.txt"
|
|
|
|
- sed -i'' \
|
|
|
|
- "s/set(PLUGIN_AUTHOR \(.*\))/set(PLUGIN_AUTHOR ${product_author})/"\
|
|
|
|
- "${project_root}/CMakeLists.txt"
|
|
|
|
- sed -i'' \
|
|
|
|
- "s/set(LINUX_MAINTAINER_EMAIL \(.*\))/set(LINUX_MAINTAINER_EMAIL ${product_email})/"\
|
|
|
|
- "${project_root}/CMakeLists.txt"
|
|
|
|
- ;;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- setup_obs
|
|
|
|
|
|
+ read -r product_name product_version <<< \
|
|
|
|
+ "$(jq -r '. | {name, version} | join(" ")' ${buildspec_file})"
|
|
|
|
|
|
pushd ${project_root}
|
|
pushd ${project_root}
|
|
if (( ! (${skips[(Ie)all]} + ${skips[(Ie)build]}) )) {
|
|
if (( ! (${skips[(Ie)all]} + ${skips[(Ie)build]}) )) {
|
|
- log_info "Configuring ${product_name}..."
|
|
|
|
-
|
|
|
|
- local _plugin_deps="${project_root:h}/obs-build-dependencies/plugin-deps-${OBS_DEPS_VERSION}-qt${QT_VERSION}-${target##*-}"
|
|
|
|
- local -a cmake_args=(
|
|
|
|
- -DCMAKE_BUILD_TYPE=${BUILD_CONFIG:-RelWithDebInfo}
|
|
|
|
- -DQT_VERSION=${QT_VERSION}
|
|
|
|
- -DCMAKE_PREFIX_PATH="${_plugin_deps}"
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if (( _loglevel == 0 )) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR)
|
|
|
|
- if (( _loglevel > 2 )) cmake_args+=(--debug-output)
|
|
|
|
|
|
+ log_group "Configuring ${product_name}..."
|
|
|
|
|
|
- local num_procs
|
|
|
|
|
|
+ local -a cmake_args=()
|
|
|
|
+ local -a cmake_build_args=(--build)
|
|
|
|
+ local -a cmake_install_args=(--install)
|
|
|
|
+
|
|
|
|
+ case ${_loglevel} {
|
|
|
|
+ 0) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR) ;;
|
|
|
|
+ 1) ;;
|
|
|
|
+ 2) cmake_build_args+=(--verbose) ;;
|
|
|
|
+ *) cmake_args+=(--debug-output) ;;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ local -r _preset="${target%%-*}${CI:+-ci}"
|
|
case ${target} {
|
|
case ${target} {
|
|
macos-*)
|
|
macos-*)
|
|
- autoload -Uz read_codesign
|
|
|
|
- if (( ${+CODESIGN} )) {
|
|
|
|
- read_codesign
|
|
|
|
|
|
+ if (( ${+CI} )) typeset -gx NSUnbufferedIO=YES
|
|
|
|
+
|
|
|
|
+ cmake_args+=(
|
|
|
|
+ --preset ${_preset}
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if (( codesign )) {
|
|
|
|
+ autoload -Uz read_codesign_team && read_codesign_team
|
|
|
|
+
|
|
|
|
+ if [[ -z ${CODESIGN_TEAM} ]] {
|
|
|
|
+ autoload -Uz read_codesign && read_codesign
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
cmake_args+=(
|
|
cmake_args+=(
|
|
- -DCMAKE_FRAMEWORK_PATH="${_plugin_deps}/Frameworks"
|
|
|
|
- -DCMAKE_OSX_ARCHITECTURES=${${target##*-}//universal/x86_64;arm64}
|
|
|
|
- -DCMAKE_OSX_DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET:-10.15}
|
|
|
|
- -DOBS_CODESIGN_LINKER=ON
|
|
|
|
- -DOBS_BUNDLE_CODESIGN_IDENTITY="${CODESIGN_IDENT:--}"
|
|
|
|
|
|
+ -DCODESIGN_TEAM=${CODESIGN_TEAM:-}
|
|
|
|
+ -DCODESIGN_IDENTITY=${CODESIGN_IDENT:--}
|
|
)
|
|
)
|
|
- num_procs=$(( $(sysctl -n hw.ncpu) + 1 ))
|
|
|
|
|
|
+
|
|
|
|
+ cmake_build_args+=(--preset ${_preset} --parallel --config ${config} -- ONLY_ACTIVE_ARCH=NO -arch arm64 -arch x86_64)
|
|
|
|
+ cmake_install_args+=(build_macos --config ${config} --prefix "${project_root}/release/${config}")
|
|
|
|
+
|
|
|
|
+ local -a xcbeautify_opts=()
|
|
|
|
+ if (( _loglevel == 0 )) xcbeautify_opts+=(--quiet)
|
|
;;
|
|
;;
|
|
linux-*)
|
|
linux-*)
|
|
- if (( ${+CI} )) {
|
|
|
|
- cmake_args+=(-DCMAKE_INSTALL_PREFIX=/usr -DLINUX_PORTABLE=OFF)
|
|
|
|
|
|
+ cmake_args+=(
|
|
|
|
+ --preset ${_preset}-${target##*-}
|
|
|
|
+ -G "${generator}"
|
|
|
|
+ -DQT_VERSION=${QT_VERSION:-6}
|
|
|
|
+ -DCMAKE_BUILD_TYPE=${config}
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ local cmake_version
|
|
|
|
+ read -r _ _ cmake_version <<< "$(cmake --version)"
|
|
|
|
+
|
|
|
|
+ if [[ ${CPUTYPE} != ${target##*-} ]] {
|
|
|
|
+ if is-at-least 3.21.0 ${cmake_version}; then
|
|
|
|
+ cmake_args+=(--toolchain "${project_root}/cmake/linux/toolchains/${target##*-}-linux-gcc.cmake")
|
|
|
|
+ else
|
|
|
|
+ cmake_args+=(-D"CMAKE_TOOLCHAIN_FILE=${project_root}/cmake/linux/toolchains/${target##*-}-linux-gcc.cmake")
|
|
|
|
+ fi
|
|
}
|
|
}
|
|
- num_procs=$(( $(nproc) + 1 ))
|
|
|
|
|
|
+
|
|
|
|
+ cmake_build_args+=(--preset ${_preset}-${target##*-} --config ${config})
|
|
|
|
+ if [[ ${generator} == 'Unix Makefiles' ]] {
|
|
|
|
+ cmake_build_args+=(--parallel $(( $(nproc) + 1 )))
|
|
|
|
+ } else {
|
|
|
|
+ cmake_build_args+=(--parallel)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cmake_install_args+=(build_${target##*-} --prefix ${project_root}/release/${config})
|
|
;;
|
|
;;
|
|
}
|
|
}
|
|
|
|
|
|
- log_debug "Attempting to configure ${product_name} with CMake arguments: ${cmake_args}"
|
|
|
|
- cmake -S . -B build_${target##*-} -G ${generator} ${cmake_args}
|
|
|
|
|
|
+ log_debug "Attempting to configure with CMake arguments: ${cmake_args}"
|
|
|
|
|
|
- log_info "Building ${product_name}..."
|
|
|
|
- local -a cmake_args=()
|
|
|
|
- if (( _loglevel > 1 )) cmake_args+=(--verbose)
|
|
|
|
- if [[ ${generator} == 'Unix Makefiles' ]] cmake_args+=(--parallel ${num_procs})
|
|
|
|
- cmake --build build_${target##*-} --config ${BUILD_CONFIG:-RelWithDebInfo} ${cmake_args}
|
|
|
|
|
|
+ cmake ${cmake_args}
|
|
|
|
+
|
|
|
|
+ log_group "Building ${product_name}..."
|
|
|
|
+ if [[ ${host_os} == macos ]] {
|
|
|
|
+ if (( _loglevel > 1 )) {
|
|
|
|
+ cmake ${cmake_build_args}
|
|
|
|
+ } else {
|
|
|
|
+ cmake ${cmake_build_args} 2>&1 | xcbeautify ${xcbeautify_opts}
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ cmake ${cmake_build_args}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- log_info "Installing ${product_name}..."
|
|
|
|
- local -a cmake_args=()
|
|
|
|
- if (( _loglevel > 1 )) cmake_args+=(--verbose)
|
|
|
|
- cmake --install build_${target##*-} --config ${BUILD_CONFIG:-RelWithDebInfo} --prefix "${project_root}/release" ${cmake_args}
|
|
|
|
|
|
+ log_group "Installing ${product_name}..."
|
|
|
|
+ if (( _loglevel > 1 )) cmake_install_args+=(--verbose)
|
|
|
|
+ cmake ${cmake_install_args}
|
|
popd
|
|
popd
|
|
|
|
+ log_group
|
|
}
|
|
}
|
|
|
|
|
|
build ${@}
|
|
build ${@}
|