Skip to content

Commit

Permalink
Merge pull request #456 from eseiler/infra/codechecker
Browse files Browse the repository at this point in the history
[INFRA] Codechecker
  • Loading branch information
eseiler authored Nov 27, 2024
2 parents 01d063a + 2fc4472 commit 57f3187
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 26 deletions.
14 changes: 14 additions & 0 deletions .github/config/REUSE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

version = 1
SPDX-PackageName = "Raptor"
SPDX-PackageDownloadLocation = "https://github.com/seqan/raptor/"

[[annotations]]
path = "cppcheck"
precedence = "aggregate"
SPDX-FileCopyrightText = ["2006-2024, Knut Reinert & Freie Universität Berlin", "2016-2024, Knut Reinert & MPI für molekulare Genetik"]
SPDX-License-Identifier = "CC0-1.0"

6 changes: 6 additions & 0 deletions .github/config/codechecker.skip
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

+${GITHUB_WORKSPACE}/*
-*
21 changes: 21 additions & 0 deletions .github/config/codechecker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

analyze:
- --enable=performance
- --cppcheckargs=${GITHUB_WORKSPACE}/.github/config/cppcheck
- --enable=bugprone
- --disable=bugprone-easily-swappable-parameters
- --disable=bugprone-narrowing-conversions
- --disable=clang-diagnostic-implicit-int-float-conversion
- --disable=clang-diagnostic-float-conversion
- --disable=clang-diagnostic-implicit-int-conversion
- --skip=${GITHUB_WORKSPACE}/.github/config/codechecker.skip
- --clean

parse:
- --export=html
- --output=./html
- --skip=${GITHUB_WORKSPACE}/.github/config/codechecker.skip
- --trim-path-prefix=${GITHUB_WORKSPACE}/
1 change: 1 addition & 0 deletions .github/config/cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--check-level=exhaustive
35 changes: 35 additions & 0 deletions .github/workflows/ci_codechecker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC0-1.0

name: CodeChecker

on:
schedule:
- cron: "0 4 * * THU"
workflow_dispatch:

env:
TZ: Europe/Berlin

defaults:
run:
shell: bash -Eexuo pipefail {0}

jobs:
build:
name: CodeChecker
runs-on: ubuntu-latest
if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch'
container:
image: ghcr.io/seqan/clang-19
volumes:
- /home/runner:/home/runner
steps:
- name: Run CodeChecker
uses: seqan/actions/codechecker@main
with:
deploy_host: ${{ secrets.DEPLOY_HOST }}
deploy_user: ${{ secrets.DEPLOY_USER }}
deploy_ssh_key: ${{ secrets.DEPLOY_SSH_KEY }}
deploy_path: ${{ secrets.DEPLOY_CODECHECKER_PATH }}
4 changes: 2 additions & 2 deletions include/raptor/argument_parsing/formatted_bytes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace raptor
decimal >>= (iterations - 1u) * 10u; // Shift to next smallest unit, e.g. 800MiB
decimal = decimal * 1000u / 1024u; // Account for using decimal system, i.e. 800MiB != 0.8GiB
size_t const diff{decimal - (decimal / 100u) * 100u}; // We want to round up to 1 decimal position
uint32_t const round_up{diff >= 50u};
decimal += round_up * 100u - diff;
bool const round_up{diff >= 50u};
decimal += static_cast<size_t>(round_up * 100u) - diff;
decimal /= 100u;
return decimal;
};
Expand Down
4 changes: 2 additions & 2 deletions include/raptor/argument_parsing/formatted_index_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace raptor
{

[[nodiscard]] inline size_t index_size_in_KiB(std::filesystem::path index_path, uint8_t const parts)
[[nodiscard]] inline size_t index_size_in_KiB(std::filesystem::path const & index_path, uint8_t const parts)
{
size_t index_size_in_bytes{};
if (parts == 1u)
Expand All @@ -37,7 +37,7 @@ namespace raptor
return index_size_in_bytes >> 10;
}

[[nodiscard]] inline std::string formatted_index_size(std::filesystem::path index_path, uint8_t const parts)
[[nodiscard]] inline std::string formatted_index_size(std::filesystem::path const & index_path, uint8_t const parts)
{
return formatted_bytes(index_size_in_KiB(index_path, parts) << 10);
}
Expand Down
6 changes: 5 additions & 1 deletion include/raptor/argument_parsing/validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ static inline std::vector<std::string> combined_extensions{
{
result.push_back(sequence_extension);
for (auto && compression_extension : compression_extensions)
result.push_back(sequence_extension + std::string{'.'} + compression_extension);
{
result.push_back(sequence_extension);
result.back() += '.';
result.back() += compression_extension;
}
}
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion include/raptor/file_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace raptor
{

enum class file_types
enum class file_types : uint8_t
{
sequence,
minimiser
Expand Down
24 changes: 14 additions & 10 deletions include/raptor/prepare/cutoff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ class cutoff
{
case cutoff_kinds::filesize_dependent:
return impl(filename);
default:
{
assert(cutoff_kind == cutoff_kinds::fixed);
case cutoff_kinds::fixed:
return fixed_cutoff;
}
default: // GCOVR_EXCL_LINE
#ifndef NDEBUG
assert(false); // GCOVR_EXCL_LINE
#else
__builtin_unreachable();
#endif
}
}

static inline bool file_is_compressed(std::filesystem::path const & filepath)
static inline bool file_is_compressed(std::filesystem::path const & filepath) noexcept
{
std::filesystem::path const extension = filepath.extension();
return extension == ".gz" || extension == ".bgzf" || extension == ".bz2";
}

private:
enum class cutoff_kinds
enum class cutoff_kinds : uint8_t
{
fixed,
filesize_dependent
Expand All @@ -80,7 +83,7 @@ class cutoff
1'073'741'824ULL,
3'221'225'472ULL};

uint8_t impl(std::filesystem::path const & filename) const
uint8_t impl(std::filesystem::path const & filename) const noexcept
{
bool const is_compressed = file_is_compressed(filename);
bool const is_fasta = check_for_fasta_format(filename);
Expand All @@ -103,9 +106,10 @@ class cutoff
return cutoff;
}

static inline bool
check_for_fasta_format(std::filesystem::path const & filepath,
std::vector<std::string> const & valid_extensions = seqan3::format_fasta::file_extensions)
// NOLINTNEXTLINE(bugprone-exception-escape)
static inline bool check_for_fasta_format(
std::filesystem::path const & filepath,
std::vector<std::string> const & valid_extensions = seqan3::format_fasta::file_extensions) noexcept
{
std::string const extension = file_is_compressed(filepath) ? filepath.stem() : filepath.extension();

Expand Down
4 changes: 2 additions & 2 deletions include/raptor/threshold/logspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace raptor::logspace
{

constexpr double ln_2{0.693147180559945309417232121458176568L};
constexpr double ln_2{0.693147180559945};
constexpr double negative_inf{-std::numeric_limits<double>::infinity()};

//!\brief The log of a sum of two log terms.
Expand All @@ -31,7 +31,7 @@ constexpr double negative_inf{-std::numeric_limits<double>::infinity()};
template <typename... types>
[[nodiscard]] double add(double const log_x, double const log_y, types... logs) noexcept
{
return add(add(log_y, log_x), logs...);
return add(add(log_x, log_y), logs...);
}

//!\brief The log of a difference of two log terms. (log_x - log_y)
Expand Down
2 changes: 1 addition & 1 deletion include/raptor/threshold/threshold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class threshold
size_t get(size_t const minimiser_count) const noexcept;

private:
enum class threshold_kinds
enum class threshold_kinds : uint8_t
{
probabilistic,
lemma,
Expand Down
6 changes: 3 additions & 3 deletions src/argument_parsing/compute_bin_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ size_t kmer_count_from_minimiser_files(std::vector<std::vector<std::string>> con
size_t max_filesize{};
std::filesystem::path biggest_file{};

auto callback = [&callback_mutex, &biggest_file, &max_filesize](std::filesystem::path const path, size_t const size)
auto callback = [&callback_mutex, &biggest_file, &max_filesize](std::filesystem::path path, size_t const size)
{
std::lock_guard<std::mutex> guard{callback_mutex};
if (size > max_filesize)
{
max_filesize = size;
biggest_file = path;
biggest_file = std::move(path);
}
};

Expand All @@ -61,7 +61,7 @@ size_t kmer_count_from_minimiser_files(std::vector<std::vector<std::string>> con
}
}

callback(biggest_file, max_filesize);
callback(std::move(biggest_file), max_filesize);
};

call_parallel_on_bins(worker, bin_path, threads);
Expand Down
2 changes: 1 addition & 1 deletion src/raptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char ** argv)
if (sub_parser.info.app_name == std::string_view{"Raptor-upgrade"})
raptor::upgrade_parsing(sub_parser);
}
catch (sharg::parser_error const & ext)
catch (std::exception const & ext)
{
std::cerr << "[Error] " << ext.what() << '\n';
std::exit(-1);
Expand Down
11 changes: 8 additions & 3 deletions src/threshold/threshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace raptor::threshold

threshold::threshold(threshold_parameters const & arguments)
{
uint8_t const kmer_size{arguments.shape.size()};
size_t const kmer_size{arguments.shape.size()};
size_t const kmers_per_window = arguments.window_size - kmer_size + 1;

if (!std::isnan(arguments.percentage))
Expand Down Expand Up @@ -48,13 +48,18 @@ size_t threshold::get(size_t const minimiser_count) const noexcept
return kmer_lemma;
case threshold_kinds::percentage:
return std::max<size_t>(1u, minimiser_count * threshold_percentage);
default:
case threshold_kinds::probabilistic:
{
assert(threshold_kind == threshold_kinds::probabilistic);
size_t const index = std::clamp(minimiser_count, minimal_number_of_minimizers, maximal_number_of_minimizers)
- minimal_number_of_minimizers;
return std::max<size_t>(1u, precomp_thresholds[index] + precomp_correction[index]);
}
default: // GCOVR_EXCL_LINE
#ifndef NDEBUG
assert(false); // GCOVR_EXCL_LINE
#else
__builtin_unreachable();
#endif
}
}

Expand Down

0 comments on commit 57f3187

Please sign in to comment.