diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c7d7ef2c..e92b523a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -30,6 +30,6 @@ jobs: #- name: ccache dump config # run: ccache -p - name: cmake build - run: cmake -S . -B build -DBOOST_ROOT=boost_1_75_0 -DCMAKE_BUILD_TYPE=Release -DWERROR=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_FLAGS="-I/usr/local/include" + run: cmake -S . -B build -DBOOST_ROOT=boost_1_75_0 -DCMAKE_BUILD_TYPE=Release -DWERROR=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }} -DCMAKE_CXX_FLAGS="-I/usr/local/include" - name: cmake make run: cmake --build build --parallel 3 diff --git a/.github/workflows/self-hosted.yml b/.github/workflows/self-hosted.yml index 3d090530..9656ebd0 100644 --- a/.github/workflows/self-hosted.yml +++ b/.github/workflows/self-hosted.yml @@ -12,16 +12,16 @@ jobs: run: rm -rf /home/pi/actions-runner/_work/snapcast/snap*_armhf.deb - uses: actions/checkout@v2 - name: cmake build - run: mkdir build && cd build && cmake -DBOOST_ROOT=/home/pi/Develop/boost_1_75_0 -DCMAKE_BUILD_TYPE=Release -DWERROR=ON -DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-psabi" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache .. && cd .. + run: mkdir build && cd build && cmake -DBOOST_ROOT=/home/pi/Develop/boost_1_75_0 -DCMAKE_BUILD_TYPE=Release -DWERROR=ON -DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-psabi" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }} .. && cd .. - name: cmake make run: cmake --build build -- -j 2 - name: debian package run: | - fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=/home/pi/Develop/boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_WITH_PULSE=OFF" binary + fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=/home/pi/Develop/boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }} -DBUILD_WITH_PULSE=OFF" binary rename 's/_armhf/_without-pulse_armhf/g' ../snapclient*_armhf.deb rm ../snapserver*_armhf.deb fakeroot make -f debian/rules clean - fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=/home/pi/Develop/boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" binary + fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=/home/pi/Develop/boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }}" binary - name: Archive artifacts uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 3689e418..bddd2e6b 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -31,16 +31,16 @@ jobs: #- name: ccache dump config # run: ccache -p - name: cmake build - run: cmake -S . -B build -DBOOST_ROOT=boost_1_75_0 -DCMAKE_BUILD_TYPE=Release -DWERROR=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + run: cmake -S . -B build -DBOOST_ROOT=boost_1_75_0 -DCMAKE_BUILD_TYPE=Release -DWERROR=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }} - name: cmake make run: cmake --build build --parallel 3 - name: debian package run: | - fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_WITH_PULSE=OFF" binary + fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }} -DBUILD_WITH_PULSE=OFF" binary rename 's/_amd64/_without-pulse_amd64/g' ../snapclient*_amd64.deb rm ../snapserver*_amd64.deb fakeroot make -f debian/rules clean - fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" binary + fakeroot make -f debian/rules CMAKEFLAGS="-DBOOST_ROOT=boost_1_75_0 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DREVISION=${{ github.sha }}" binary - name: Archive artifacts uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6c2f56cb..f4b1913a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -22,7 +22,7 @@ jobs: - name: cmake build run: | echo vcpkg installation root: ${env:VCPKG_INSTALLATION_ROOT} - cmake -S . -B build -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET="x64-windows" -DCMAKE_BUILD_TYPE="Release" -DWERROR=ON + cmake -S . -B build -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET="x64-windows" -DCMAKE_BUILD_TYPE="Release" -DREVISION="${{ github.sha }}" -DWERROR=ON - name: cmake make run: cmake --build build --config Release --parallel 3 --verbose - name: installer diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bbde276..337b9609 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,10 @@ option(UBSAN "Enable UndefinedBehaviorSanitizer" OFF) option(TIDY "Enable clang tidy" OFF) +IF (REVISION) + add_compile_definitions(REVISION=\"${REVISION}\") +ENDIF() + IF (TIDY) FIND_PROGRAM(CLANG_TIDY "clang-tidy") IF(CLANG_TIDY) diff --git a/client/snapclient.cpp b/client/snapclient.cpp index 00c123c4..fc508345 100644 --- a/client/snapclient.cpp +++ b/client/snapclient.cpp @@ -44,6 +44,7 @@ #include "common/snap_exception.hpp" #include "common/str_compat.hpp" #include "common/utils.hpp" +#include "common/version.hpp" #include "metadata.hpp" @@ -55,6 +56,7 @@ using namespace std::chrono_literals; static constexpr auto LOG_TAG = "Snapclient"; + PcmDevice getPcmDevice(const std::string& player, const std::string& parameter, const std::string& soundcard) { #if defined(HAS_ALSA) || defined(HAS_PULSE) || defined(HAS_WASAPI) @@ -195,7 +197,7 @@ int main(int argc, char** argv) if (versionSwitch->is_set()) { - cout << "snapclient v" << VERSION << "\n" + cout << "snapclient v" << version::code << (!version::rev().empty() ? (" (rev " + version::rev(8) + ")") : ("")) << "\n" << "Copyright (C) 2014-2021 BadAix (snapcast@badaix.de).\n" << "License GPLv3+: GNU GPL version 3 or later .\n" << "This is free software: you are free to change and redistribute it.\n" @@ -419,6 +421,8 @@ int main(int argc, char** argv) io_context.stop(); }); + LOG(INFO, LOG_TAG) << "Snapclient v" << version::code << (!version::rev().empty() ? (", revision " + version::rev(8)) : ("")) << " started\n"; + // Setup metadata handling auto meta(metaStderr ? std::make_unique() : std::make_unique()); auto controller = make_shared(io_context, settings, std::move(meta)); diff --git a/common/version.hpp b/common/version.hpp new file mode 100644 index 00000000..13210fd8 --- /dev/null +++ b/common/version.hpp @@ -0,0 +1,50 @@ +/*** + This file is part of snapcast + Copyright (C) 2014-2021 Johannes Pohl + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +***/ + +#ifndef VERSION_HPP +#define VERSION_HPP + +#include + +namespace version +{ + +#ifdef REVISION +static constexpr auto revision = REVISION; +#else +static constexpr auto revision = ""; +#endif + +#ifdef VERSION +static constexpr auto code = VERSION; +#else +static constexpr auto code = ""; +#endif + +static std::string rev(std::size_t len = 0) +{ + if (len == 0) + { + return revision; + } + return std::string(revision).substr(0, len); +} + +} // namespace version + +#endif diff --git a/server/snapserver.cpp b/server/snapserver.cpp index 925e4d16..8a25402a 100644 --- a/server/snapserver.cpp +++ b/server/snapserver.cpp @@ -28,6 +28,7 @@ #include "common/snap_exception.hpp" #include "common/time_defs.hpp" #include "common/utils/string_utils.hpp" +#include "common/version.hpp" #include "encoder/encoder_factory.hpp" #include "message/message.hpp" #include "server.hpp" @@ -42,6 +43,8 @@ using namespace std; using namespace popl; +static constexpr auto LOG_TAG = "Snapserver"; + int main(int argc, char* argv[]) { @@ -149,7 +152,7 @@ int main(int argc, char* argv[]) if (versionSwitch->is_set()) { - cout << "snapserver v" << VERSION << "\n" + cout << "snapserver v" << version::code << (!version::rev().empty() ? (" (rev " + version::rev(8) + ")") : ("")) << "\n" << "Copyright (C) 2014-2021 BadAix (snapcast@badaix.de).\n" << "License GPLv3+: GNU GPL version 3 or later .\n" << "This is free software: you are free to change and redistribute it.\n" @@ -223,17 +226,19 @@ int main(int argc, char* argv[]) else throw SnapException("Invalid log sink: " + settings.logging.sink); + LOG(INFO, LOG_TAG) << "Snapserver v" << version::code << (!version::rev().empty() ? (", revision " + version::rev(8)) : ("")) << " started\n"; + if (!streamValue->is_set() && !sourceValue->is_set()) settings.stream.sources.push_back(sourceValue->value()); for (size_t n = 0; n < streamValue->count(); ++n) { - LOG(INFO) << "Adding stream: " << streamValue->value(n) << "\n"; + LOG(INFO, LOG_TAG) << "Adding stream: " << streamValue->value(n) << "\n"; settings.stream.sources.push_back(streamValue->value(n)); } for (size_t n = 0; n < sourceValue->count(); ++n) { - LOG(INFO) << "Adding source: " << sourceValue->value(n) << "\n"; + LOG(INFO, LOG_TAG) << "Adding source: " << sourceValue->value(n) << "\n"; settings.stream.sources.push_back(sourceValue->value(n)); } @@ -252,9 +257,9 @@ int main(int argc, char* argv[]) processPriority = std::min(std::max(-20, processPriority), 19); if (processPriority != 0) setpriority(PRIO_PROCESS, 0, processPriority); - LOG(NOTICE) << "daemonizing" << std::endl; + LOG(NOTICE, LOG_TAG) << "daemonizing" << std::endl; daemon->daemonize(); - LOG(NOTICE) << "daemon started" << std::endl; + LOG(NOTICE, LOG_TAG) << "daemon started" << std::endl; } else Config::instance().init(settings.server.data_dir); @@ -281,13 +286,13 @@ int main(int argc, char* argv[]) #endif if (settings.stream.streamChunkMs < 10) { - LOG(WARNING) << "Stream read chunk size is less than 10ms, changing to 10ms\n"; + LOG(WARNING, LOG_TAG) << "Stream read chunk size is less than 10ms, changing to 10ms\n"; settings.stream.streamChunkMs = 10; } if (settings.stream.bufferMs < 400) { - LOG(WARNING) << "Buffer is less than 400ms, changing to 400ms\n"; + LOG(WARNING, LOG_TAG) << "Buffer is less than 400ms, changing to 400ms\n"; settings.stream.bufferMs = 400; } @@ -296,15 +301,15 @@ int main(int argc, char* argv[]) if (settings.server.threads < 0) settings.server.threads = std::max(2, std::min(4, static_cast(std::thread::hardware_concurrency()))); - LOG(INFO) << "number of threads: " << settings.server.threads << ", hw threads: " << std::thread::hardware_concurrency() << "\n"; + LOG(INFO, LOG_TAG) << "Number of threads: " << settings.server.threads << ", hw threads: " << std::thread::hardware_concurrency() << "\n"; // Construct a signal set registered for process termination. boost::asio::signal_set signals(io_context, SIGHUP, SIGINT, SIGTERM); signals.async_wait([&io_context](const boost::system::error_code& ec, int signal) { if (!ec) - LOG(INFO) << "Received signal " << signal << ": " << strsignal(signal) << "\n"; + LOG(INFO, LOG_TAG) << "Received signal " << signal << ": " << strsignal(signal) << "\n"; else - LOG(INFO) << "Failed to wait for signal, error: " << ec.message() << "\n"; + LOG(INFO, LOG_TAG) << "Failed to wait for signal, error: " << ec.message() << "\n"; io_context.stop(); }); @@ -317,16 +322,16 @@ int main(int argc, char* argv[]) for (auto& t : threads) t.join(); - LOG(INFO) << "Stopping streamServer" << endl; + LOG(INFO, LOG_TAG) << "Stopping streamServer" << endl; server->stop(); - LOG(INFO) << "done" << endl; + LOG(INFO, LOG_TAG) << "done" << endl; } catch (const std::exception& e) { - LOG(ERROR) << "Exception: " << e.what() << std::endl; + LOG(ERROR, LOG_TAG) << "Exception: " << e.what() << std::endl; exitcode = EXIT_FAILURE; } Config::instance().save(); - LOG(NOTICE) << "Snapserver terminated." << endl; + LOG(NOTICE, LOG_TAG) << "Snapserver terminated." << endl; exit(exitcode); }