diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 6f9d1cbb6..797f9250f 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -4,6 +4,10 @@ on: workflow_call: workflow_dispatch: +env: + BUILD_TYPES: ${{ (github.ref_name == 'develop' || github.ref_name == 'main') && 'release debug' || 'release' }} + BUILD_TESTING: ${{ (github.ref_name != 'main') && 'testing' || '' }} + jobs: build-x64: runs-on: [self-hosted, macos, x64] @@ -14,12 +18,7 @@ jobs: uses: actions/checkout@v4 - name: Build - run: | - if [ "$GITHUB_REF_NAME" != "main" ]; then - bash osx/build-nzbget.sh x64 testing - else - bash osx/build-nzbget.sh x64 - fi + run: bash osx/build-nzbget.sh x64 ${{ env.BUILD_TYPES }} ${{ env.BUILD_TESTING }} - name: Upload full build log on failure uses: actions/upload-artifact@v4 @@ -36,7 +35,7 @@ jobs: SUFFIX="${GITHUB_REF_NAME/\//-}" for FILE in *.zip; do [ -f $FILE ] || continue - NEW_FILE=${FILE/-bin-macos-x64.zip/-$SUFFIX-bin-macos-x64.zip} + NEW_FILE=${FILE/-bin-macos-x64/-$SUFFIX-bin-macos-x64} mv $FILE $NEW_FILE done @@ -56,12 +55,7 @@ jobs: uses: actions/checkout@v4 - name: Build - run: | - if [ "$GITHUB_REF_NAME" != "main" ]; then - bash osx/build-nzbget.sh universal testing - else - bash osx/build-nzbget.sh universal - fi + run: bash osx/build-nzbget.sh universal ${{ env.BUILD_TYPES }} ${{ env.BUILD_TESTING }} - name: Upload full build log on failure uses: actions/upload-artifact@v4 @@ -78,7 +72,7 @@ jobs: SUFFIX="${GITHUB_REF_NAME/\//-}" for FILE in *.zip; do [ -f $FILE ] || continue - NEW_FILE=${FILE/-bin-macos-universal.zip/-$SUFFIX-bin-macos-universal.zip} + NEW_FILE=${FILE/-bin-macos-universal/-$SUFFIX-bin-macos-universal} mv $FILE $NEW_FILE done @@ -86,7 +80,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: nzbget-osx-installers-universal - path: build/*-universal.zip + path: build/*-universal*.zip retention-days: 5 sign-universal: @@ -109,17 +103,24 @@ jobs: NOTARY_KEY_ID: ${{ secrets.OSX_NOTARY_KEY_ID }} NOTARY_KEY_ISSUER: ${{ secrets.OSX_NOTARY_KEY_ISSUER }} run: | - mkdir -p build - cp osx/sign/* build - cp nzbget-osx-installers-universal/*.zip build/ - cd build - bash nzbget-sign.sh *.zip + mkdir -p build_signed + for FILE in nzbget-osx-installers-universal/*.zip; do + [ -f $FILE ] || continue + mkdir -p build + cp osx/sign/* build + cp $FILE build/ + cd build + bash nzbget-sign.sh *.zip + cd .. + cp build/*.dmg build_signed + rm -rf build + done - name: Upload signed build artifacts uses: actions/upload-artifact@v4 with: name: nzbget-osx-installers-universal-signed - path: build/*.dmg + path: build_signed/*.dmg retention-days: 5 combine-osx-artifacts: diff --git a/cmake/common.cmake b/cmake/common.cmake index cbeb9f6ef..1a73f4eb5 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -15,6 +15,8 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "riscv32|rv32") endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(DEBUG 1) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang") add_compile_options(-Weverything -Wno-c++98-compat) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/cmake/config.h.in b/cmake/config.h.in index 6225fa2ea..2aa98f632 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -1,3 +1,6 @@ +/* Define to 1 to include debug-code */ +#cmakedefine DEBUG + /* Name of package */ #cmakedefine PACKAGE "@PACKAGE@" diff --git a/cmake/windows.cmake b/cmake/windows.cmake index c6f786227..bc6cfcd52 100644 --- a/cmake/windows.cmake +++ b/cmake/windows.cmake @@ -16,6 +16,10 @@ find_package(Threads REQUIRED) find_package(LibXml2 REQUIRED) find_package(Boost REQUIRED COMPONENTS json) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(LIBS ${LIBS} dbghelp.lib) +endif() + set(LIBS ${LIBS} Threads::Threads Boost::json LibXml2::LibXml2 winmm.lib) set(INCLUDES ${INCLUDES} ${Boost_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR}) diff --git a/daemon/main/StackTrace.cpp b/daemon/main/StackTrace.cpp index 3b720a02b..072d1b2dc 100644 --- a/daemon/main/StackTrace.cpp +++ b/daemon/main/StackTrace.cpp @@ -128,7 +128,7 @@ void PrintBacktrace(PCONTEXT context) srcFileName = ""; } - info("%s (%i) : %s", *srcFileName, lineNumber, *symName); + error("Stacktrace: %s (%i) : %s", *srcFileName, lineNumber, *symName); if (sfStackFrame.AddrReturn.Offset == 0) { @@ -209,7 +209,7 @@ void PrintBacktrace() error("Obtained %zd stack frames", size); for (i = 0; i < size; i++) { - error("%s", strings[i]); + error("Stacktrace: %s", strings[i]); } free(strings); diff --git a/lib/regex/regex.c b/lib/regex/regex.c index c60ddbfd0..7500e2883 100644 --- a/lib/regex/regex.c +++ b/lib/regex/regex.c @@ -1465,7 +1465,7 @@ re_string_reconstruct(re_string_t* pstr, int idx, int eflags) pstr->valid_len - offset); pstr->valid_len -= offset; pstr->valid_raw_len -= offset; -#if DEBUG +#ifdef DEBUG assert(pstr->valid_len > 0); #endif } diff --git a/osx/build-nzbget.sh b/osx/build-nzbget.sh index 1d8de7974..01d57c888 100755 --- a/osx/build-nzbget.sh +++ b/osx/build-nzbget.sh @@ -31,174 +31,199 @@ JOBS=$(sysctl -n hw.ncpu) # command-line params handling ALL_ARCHS="x64 arm64" -ARCH_PARAM="" -if [ $# -gt 0 ]; then - ARCH_PARAM=$1 +ARCHS="" +CONFIGS="" +UNIVERSAL="no" +TESTING="no" + +for PARAM in "$@" +do + case $PARAM in + x64|arm64) + ARCHS=`echo "$ARCHS $PARAM" | xargs` + ;; + release|debug) + CONFIGS=`echo "$CONFIGS $PARAM" | xargs` + ;; + universal) + UNIVERSAL="yes" + ;; + testing) + TESTING="yes" + ;; + *) + echo "Invalid parameter: $PARAM" + echo "Script usage: bash osx/build-nzbget.sh [arch] [testing] [release] [debug]" + echo "arch can be: x64 arm64 universal" + exit 1 + ;; + esac +done + +if [ "$ARCHS" == "" ]; then + ARCHS="$ALL_ARCHS" fi -case $ARCH_PARAM in - x64|arm64) - ARCHS=$ARCH_PARAM - ;; - universal) - ARCHS=$ALL_ARCHS - ;; - "") - ARCH_PARAM="universal" - ARCHS=$ALL_ARCHS - ;; - *) - echo "Invalid architecture specified: $ARCH_PARAM" - echo "Script usage: bash osx/build-nzbget.sh [arch] [testing]" - echo "arch can be: x64 arm64 universal" - exit 1 - ;; -esac +if [ "$CONFIGS" == "" ]; then + CONFIGS="release" +fi # version handling VERSION=$(grep "set(VERSION " CMakeLists.txt | cut -d '"' -f 2) VERSION_SUFFIX="" -if [ $# -gt 1 ]; then - if [ "$2" == "testing" ]; then - VERSION_SUFFIX="-testing-$(date '+%Y%m%d')" - fi +if [ "$TESTING" == "yes" ]; then + VERSION_SUFFIX="-testing-$(date '+%Y%m%d')" fi # create directories and cleanup mkdir -p build rm -rf build/* -for ARCH in $ARCHS; do - - echo "Make $ARCH nzbget package..." - - # use vcpkg libs for build and link daemon - LIB_PATH=$HOME/vcpkg/installed/$ARCH-osx/lib - INCLUDE_PATH=$HOME/vcpkg/installed/$ARCH-osx/include - - - NZBGET_PATH=build/nzbget-$ARCH - BUILD_PATH=build/release-$ARCH - mkdir $NZBGET_PATH - mkdir $BUILD_PATH - - export LIBS="-liconv -lncurses $LIB_PATH/libboost_json.a $LIB_PATH/libxml2.a $LIB_PATH/libz.a $LIB_PATH/libssl.a $LIB_PATH/libcrypto.a $LIB_PATH/liblzma.a" - export INCLUDES="$INCLUDE_PATH/;$INCLUDE_PATH/libxml2/" - - # copy macOS project to package - cp -r osx "$NZBGET_PATH/" - DAEMON_PATH=osx/Resources/daemon/usr/local +NZBGET_ROOT=$PWD +for CONFIG in $CONFIGS; do + for ARCH in $ARCHS; do + + echo "Make $ARCH nzbget package..." + cd $NZBGET_ROOT + + # use vcpkg libs for build and link daemon + LIB_PATH=$HOME/vcpkg/installed/$ARCH-osx/lib + INCLUDE_PATH=$HOME/vcpkg/installed/$ARCH-osx/include + + + NZBGET_PATH=build/nzbget-$CONFIG-$ARCH + BUILD_PATH=build/$CONFIG-$ARCH + mkdir -p $NZBGET_PATH + mkdir -p $BUILD_PATH + + export LIBS="-liconv -lncurses $LIB_PATH/libboost_json.a $LIB_PATH/libxml2.a $LIB_PATH/libz.a $LIB_PATH/libssl.a $LIB_PATH/libcrypto.a $LIB_PATH/liblzma.a" + export INCLUDES="$INCLUDE_PATH/;$INCLUDE_PATH/libxml2/" + + # copy macOS project to package + cp -r osx "$NZBGET_PATH/" + DAEMON_PATH=osx/Resources/daemon/usr/local + + # make static daemon binary + cd $BUILD_PATH + if [ "$ARCH" == "x64" ]; then + CMAKE_ARCH="x86_64" + else + CMAKE_ARCH=$ARCH + fi + + if [ "$CONFIG" == "debug" ]; then + CMAKE_BUILD_TYPE="Debug" + SUFFIX="-debug" + else + CMAKE_BUILD_TYPE="Release" + SUFFIX="" + fi + + cmake ../.. \ + -DENABLE_STATIC=ON \ + -DCMAKE_INSTALL_PREFIX="$PWD/../../$NZBGET_PATH/$DAEMON_PATH" \ + -DCMAKE_SYSTEM_NAME="Darwin" \ + -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ + -DVERSION_SUFFIX="$VERSION_SUFFIX" \ + -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_ARCH \ + -DCMAKE_OSX_ARCHITECTURES=$CMAKE_ARCH + + BUILD_STATUS="" + cmake --build . -j $JOBS 2>build.log || BUILD_STATUS=$? + if [ ! -z $BUILD_STATUS ]; then + tail -20 build.log + exit 1 + fi + + strip nzbget + cmake --install . >/dev/null + cmake --build . --target install-conf + cd ../.. + + # fetch tools and root certificates + cd $NZBGET_PATH + mkdir -p $DAEMON_PATH/bin + rm -rf $DAEMON_PATH/etc + + # 7zip + URL_7Z=https://www.7-zip.org/a/7z$ZIP7_VERSION-mac.tar.xz + curl -o 7z.tar.xz $URL_7Z + mkdir -p 7z + tar xf 7z.tar.xz -C 7z + cp 7z/7zz $DAEMON_PATH/bin/7za + + # unrar + if [ "$ARCH" == "arm64" ]; then + UNRAR_ARCH="arm" + else + UNRAR_ARCH=$ARCH + fi + URL_UNRAR=https://www.rarlab.com/rar/rarmacos-$UNRAR_ARCH-$UNRAR_VERSION.tar.gz + curl -o unrar.tar.gz $URL_UNRAR + tar -xf unrar.tar.gz + cp rar/unrar $DAEMON_PATH/bin/unrar + + # root certificates + curl -o $DAEMON_PATH/bin/cacert.pem https://curl.se/ca/cacert.pem + + # adjust nzbget.conf + CONF_FILE=$DAEMON_PATH/share/nzbget/nzbget.conf + sed -i '' 's:^MainDir=.*:MainDir=~/Library/Application Support/NZBGet:' $CONF_FILE + sed -i '' 's:^DestDir=.*:DestDir=~/Downloads:' $CONF_FILE + sed -i '' 's:^InterDir=.*:InterDir=~/Downloads/Intermediate:' $CONF_FILE + sed -i '' 's:^WebDir=.*:# NOTE\: option WebDir cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE + sed -i '' 's:^LockFile=.*:# NOTE\: option LockFile cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE + sed -i '' 's:^LogFile=.*:LogFile=~/Library/Logs/NZBGet.log:' $CONF_FILE + sed -i '' '/# example configuration file (installed to/{N;s/.*/# example configuration file (installed to\n# \/usr\/local\/share\/nzbget\/nz bget.conf)./;}' $CONF_FILE + sed -i '' 's:^ConfigTemplate=.*:# NOTE\: option ConfigTemplate cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE + sed -i '' 's:^DaemonUsername=.*:# NOTE\: option DaemonUsername cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE + sed -i '' 's:^CertStore=.*:CertStore=${AppDir}/cacert.pem:' $CONF_FILE + sed -i '' 's:^CertCheck=.*:CertCheck=yes:' $CONF_FILE + sed -i '' 's:^AuthorizedIP=.*:AuthorizedIP=127.0.0.1:' $CONF_FILE + sed -i '' 's:^ArticleCache=.*:ArticleCache=700:' $CONF_FILE + sed -i '' 's:^DirectWrite=.*:DirectWrite=no:' $CONF_FILE + sed -i '' 's:^WriteBuffer=.*:WriteBuffer=1024:' $CONF_FILE + sed -i '' 's:^ParBuffer=.*:ParBuffer=500:' $CONF_FILE + sed -i '' 's:^DirectRename=.*:DirectRename=yes:' $CONF_FILE + sed -i '' 's:^DirectUnpack=.*:DirectUnpack=yes:' $CONF_FILE + sed -i '' 's:^UnrarCmd=.*:UnrarCmd=${AppDir}/unrar:' $CONF_FILE + sed -i '' 's:^SevenZipCmd=.*:SevenZipCmd=${AppDir}/7za:' $CONF_FILE + + # build macos frontend + BUILD_STATUS="" + xcodebuild -project osx/NZBGet.xcodeproj -configuration "Release" -destination "platform=macOS" build >build.log 2>&1 + if [ ! -z $BUILD_STATUS ]; then + tail -20 build.log + exit 1 + fi + + # create build archive + ARCHIVE_NAME=nzbget-$VERSION$VERSION_SUFFIX-bin-macos-$ARCH$SUFFIX.zip + (cd osx/build/Release/ && zip -r $ARCHIVE_NAME NZBGet.app >/dev/null) + mv osx/build/Release/$ARCHIVE_NAME .. + cd ../.. + done - # make static daemon binary - cd $BUILD_PATH - if [ "$ARCH" == "x64" ]; then - CMAKE_ARCH="x86_64" - else - CMAKE_ARCH=$ARCH - fi - - cmake ../.. \ - -DENABLE_STATIC=ON \ - -DCMAKE_INSTALL_PREFIX="$PWD/../../$NZBGET_PATH/$DAEMON_PATH" \ - -DCMAKE_SYSTEM_NAME="Darwin" \ - -DVERSION_SUFFIX="$VERSION_SUFFIX" \ - -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_ARCH \ - -DCMAKE_OSX_ARCHITECTURES=$CMAKE_ARCH - - BUILD_STATUS="" - cmake --build . -j $JOBS 2>build.log || BUILD_STATUS=$? - if [ ! -z $BUILD_STATUS ]; then - tail -20 build.log - exit 1 - fi - - strip nzbget - cmake --install . >/dev/null - cmake --build . --target install-conf - cd ../.. - - # fetch tools and root certificates - cd $NZBGET_PATH - mkdir -p $DAEMON_PATH/bin - rm -rf $DAEMON_PATH/etc - - # 7zip - URL_7Z=https://www.7-zip.org/a/7z$ZIP7_VERSION-mac.tar.xz - curl -o 7z.tar.xz $URL_7Z - mkdir -p 7z - tar xf 7z.tar.xz -C 7z - cp 7z/7zz $DAEMON_PATH/bin/7za - - # unrar - if [ "$ARCH" == "arm64" ]; then - UNRAR_ARCH="arm" - else - UNRAR_ARCH=$ARCH - fi - URL_UNRAR=https://www.rarlab.com/rar/rarmacos-$UNRAR_ARCH-$UNRAR_VERSION.tar.gz - curl -o unrar.tar.gz $URL_UNRAR - tar -xf unrar.tar.gz - cp rar/unrar $DAEMON_PATH/bin/unrar - - # root certificates - curl -o $DAEMON_PATH/bin/cacert.pem https://curl.se/ca/cacert.pem - - # adjust nzbget.conf - CONF_FILE=$DAEMON_PATH/share/nzbget/nzbget.conf - sed -i '' 's:^MainDir=.*:MainDir=~/Library/Application Support/NZBGet:' $CONF_FILE - sed -i '' 's:^DestDir=.*:DestDir=~/Downloads:' $CONF_FILE - sed -i '' 's:^InterDir=.*:InterDir=~/Downloads/Intermediate:' $CONF_FILE - sed -i '' 's:^WebDir=.*:# NOTE\: option WebDir cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE - sed -i '' 's:^LockFile=.*:# NOTE\: option LockFile cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE - sed -i '' 's:^LogFile=.*:LogFile=~/Library/Logs/NZBGet.log:' $CONF_FILE - sed -i '' '/# example configuration file (installed to/{N;s/.*/# example configuration file (installed to\n# \/usr\/local\/share\/nzbget\/nz bget.conf)./;}' $CONF_FILE - sed -i '' 's:^ConfigTemplate=.*:# NOTE\: option ConfigTemplate cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE - sed -i '' 's:^DaemonUsername=.*:# NOTE\: option DaemonUsername cannot be changed because it is hardcoded in OSX version.:' $CONF_FILE - sed -i '' 's:^CertStore=.*:CertStore=${AppDir}/cacert.pem:' $CONF_FILE - sed -i '' 's:^CertCheck=.*:CertCheck=yes:' $CONF_FILE - sed -i '' 's:^AuthorizedIP=.*:AuthorizedIP=127.0.0.1:' $CONF_FILE - sed -i '' 's:^ArticleCache=.*:ArticleCache=700:' $CONF_FILE - sed -i '' 's:^DirectWrite=.*:DirectWrite=no:' $CONF_FILE - sed -i '' 's:^WriteBuffer=.*:WriteBuffer=1024:' $CONF_FILE - sed -i '' 's:^ParBuffer=.*:ParBuffer=500:' $CONF_FILE - sed -i '' 's:^DirectRename=.*:DirectRename=yes:' $CONF_FILE - sed -i '' 's:^DirectUnpack=.*:DirectUnpack=yes:' $CONF_FILE - sed -i '' 's:^UnrarCmd=.*:UnrarCmd=${AppDir}/unrar:' $CONF_FILE - sed -i '' 's:^SevenZipCmd=.*:SevenZipCmd=${AppDir}/7za:' $CONF_FILE - - # build macos frontend - BUILD_STATUS="" - xcodebuild -project osx/NZBGet.xcodeproj -configuration "Release" -destination "platform=macOS" build >build.log 2>&1 - if [ ! -z $BUILD_STATUS ]; then - tail -20 build.log - exit 1 + # make universal daemon binary and universal archive + if [ "$UNIVERSAL" == "yes" ]; then + echo "Make universal nzbget package..." + cd build + for ARCH in $ALL_ARCHS; do + rm -rf NZBGet.app + unzip nzbget-$VERSION$VERSION_SUFFIX-bin-macos-$ARCH$SUFFIX.zip >/dev/null + mv NZBGet.app NZBGet.$ARCH.app + done + DAEMON_PATH=Contents/Resources/daemon/usr/local/bin/ + # nzbget universal binary + lipo -create NZBGet.x64.app/$DAEMON_PATH/nzbget NZBGet.arm64.app/$DAEMON_PATH/nzbget -output nzbget + # unrar universal binary + lipo -create NZBGet.x64.app/$DAEMON_PATH/unrar NZBGet.arm64.app/$DAEMON_PATH/unrar -output unrar + rm -rf NZBGet.x64.app + mv NZBGet.arm64.app NZBGet.app + mv nzbget NZBGet.app/$DAEMON_PATH/nzbget + mv unrar NZBGet.app/$DAEMON_PATH/unrar + zip -r nzbget-$VERSION$VERSION_SUFFIX-bin-macos-universal$SUFFIX.zip NZBGet.app >/dev/null fi - - # create build archive - ARCHIVE_NAME=nzbget-$VERSION$VERSION_SUFFIX-bin-macos-$ARCH.zip - (cd osx/build/Release/ && zip -r $ARCHIVE_NAME NZBGet.app >/dev/null) - mv osx/build/Release/$ARCHIVE_NAME .. - cd ../.. done -# make universal daemon binary and universal archive -if [ "$ARCH_PARAM" == "universal" ]; then - echo "Make universal nzbget package..." - cd build - for ARCH in $ALL_ARCHS; do - unzip nzbget-$VERSION$VERSION_SUFFIX-bin-macos-$ARCH.zip >/dev/null - mv NZBGet.app NZBGet.$ARCH.app - done - DAEMON_PATH=Contents/Resources/daemon/usr/local/bin/ - # nzbget universal binary - lipo -create NZBGet.x64.app/$DAEMON_PATH/nzbget NZBGet.arm64.app/$DAEMON_PATH/nzbget -output nzbget - # unrar universal binary - lipo -create NZBGet.x64.app/$DAEMON_PATH/unrar NZBGet.arm64.app/$DAEMON_PATH/unrar -output unrar - rm -rf NZBGet.x64.app - mv NZBGet.arm64.app NZBGet.app - mv nzbget NZBGet.app/$DAEMON_PATH/nzbget - mv unrar NZBGet.app/$DAEMON_PATH/unrar - zip -r nzbget-$VERSION$VERSION_SUFFIX-bin-macos-universal.zip NZBGet.app >/dev/null -fi - echo "Done."