From b3543377200d2179cd6d74659d744347de0497ed Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 10 Mar 2023 00:23:22 -0600 Subject: [PATCH] ci: check for clang tidy errors in libtransmission (#5188) --- .github/workflows/actions.yml | 53 +++++++++++++++++++++++++++++++++++ libtransmission/rpcimpl.cc | 2 +- libtransmission/torrent.cc | 4 +-- libtransmission/torrent.h | 2 +- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 8fff7e29d..e28086469 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -65,6 +65,7 @@ jobs: get_changes tests CMakeLists.txt cmake third-party libtransmission utils tests get_changes utils CMakeLists.txt cmake third-party libtransmission utils get_changes web CMakeLists.txt cmake third-party libtransmission web + cat "$GITHUB_OUTPUT" code-style: runs-on: ubuntu-22.04 @@ -174,6 +175,58 @@ jobs: - name: Test with sanitizers run: cmake -E chdir obj ctest -j $(nproc) --build-config Debug --output-on-failure + clang-tidy-libtransmission: + runs-on: ubuntu-22.04 + needs: [ what-to-make ] + if: ${{ needs.what-to-make.outputs.test-style == 'true' }} + steps: + - name: Show Configuration + run: | + echo '${{ toJSON(needs) }}' + echo '${{ toJSON(runner) }}' + cat /etc/os-release + - name: Get Dependencies + run: | + set -ex + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + ca-certificates \ + clang \ + clang-tidy \ + cmake \ + gettext \ + libcurl4-openssl-dev \ + libdeflate-dev \ + libevent-dev \ + libfmt-dev \ + libminiupnpc-dev \ + libnatpmp-dev \ + libpsl-dev \ + libssl-dev \ + ninja-build \ + npm + - name: Get Source + uses: actions/checkout@v3 + with: + submodules: recursive + path: src + - name: Configure + run: | + cmake \ + -S src \ + -B obj \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_COMPILER='clang++' \ + -DCMAKE_C_COMPILER='clang' \ + -DCMAKE_INSTALL_PREFIX=pfx \ + -DRUN_CLANG_TIDY=ON + - name: Make + run: cmake --build obj --config Debug --target libtransmission.a 2>&1 | tee makelog + - name: Test for warnings + run: | + if grep 'warning:' makelog; then exit 1; fi + macos-11: runs-on: macos-11 needs: [ what-to-make ] diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index 1fa698579..1ba8c13bd 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -853,7 +853,7 @@ void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* tr_variantInitList(initme, n); for (tr_file_index_t i = 0; i < n; ++i) { - tr_variantListAddInt(initme, tr_torrentFile(tor, i).wanted); + tr_variantListAddInt(initme, tr_torrentFile(tor, i).wanted ? 1 : 0); } } break; diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 9610362bd..b5d86a14a 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -2429,14 +2429,14 @@ size_t tr_torrentFindFileToBuf(tr_torrent const* tor, tr_file_index_t file_num, return tr_strvToBuf(tr_torrentFindFile(tor, file_num), buf, buflen); } -void tr_torrent::setDownloadDir(std::string_view path, bool isNewTorrent) +void tr_torrent::setDownloadDir(std::string_view path, bool is_new_torrent) { download_dir = path; markEdited(); setDirty(); refreshCurrentDir(); - if (isNewTorrent) + if (is_new_torrent) { if (session->shouldFullyVerifyAddedTorrents() || !torrent_init_helpers::isNewTorrentASeed(this)) { diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index d5bb2e2cf..126bf9a40 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -582,7 +582,7 @@ public: this->error_string = errmsg; } - void setDownloadDir(std::string_view path, bool isNewTorrent = false); + void setDownloadDir(std::string_view path, bool is_new_torrent = false); void refreshCurrentDir();