diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-04 13:52:55 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-07 17:51:22 +0200 |
commit | 6d484db9b293aac4b8bd790eb7aead3a806f8c7b (patch) | |
tree | c7a93cef8a95006f217d557300151ce5e8735437 /src | |
parent | 0fc0d9118b5e525fa582de0286c8e83bb0da4e16 (diff) | |
download | justbuild-6d484db9b293aac4b8bd790eb7aead3a806f8c7b.tar.gz |
Enable cppcoreguidelines-* checks.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/artifact.hpp | 10 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/bytestream_utils.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/execution_api/execution_service/bytestream_server.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/execution_service/execution_server.cpp | 20 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bytestream_client.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/file_system/file_system_manager.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/file_system/git_context.cpp | 1 | ||||
-rw-r--r-- | src/buildtool/logging/logger.hpp | 12 | ||||
-rw-r--r-- | src/buildtool/storage/compactification_task.hpp | 8 | ||||
-rw-r--r-- | src/buildtool/system/system_command.hpp | 4 | ||||
-rw-r--r-- | src/other_tools/utils/curl_context.cpp | 5 |
11 files changed, 34 insertions, 40 deletions
diff --git a/src/buildtool/common/artifact.hpp b/src/buildtool/common/artifact.hpp index 07c508c2..6fcde282 100644 --- a/src/buildtool/common/artifact.hpp +++ b/src/buildtool/common/artifact.hpp @@ -114,16 +114,6 @@ class Artifact { explicit Artifact(ArtifactIdentifier id) noexcept : id_{std::move(id)} {} - Artifact(Artifact const& other) noexcept - : id_{other.id_}, file_path_{other.file_path_}, repo_{other.repo_} { - object_info_ = other.object_info_; - } - - Artifact(Artifact&&) noexcept = default; - ~Artifact() noexcept = default; - auto operator=(Artifact const&) noexcept -> Artifact& = delete; - auto operator=(Artifact&&) noexcept -> Artifact& = default; - [[nodiscard]] auto Id() const& noexcept -> ArtifactIdentifier const& { return id_; } diff --git a/src/buildtool/execution_api/common/bytestream_utils.cpp b/src/buildtool/execution_api/common/bytestream_utils.cpp index f1b53f05..de66d58e 100644 --- a/src/buildtool/execution_api/common/bytestream_utils.cpp +++ b/src/buildtool/execution_api/common/bytestream_utils.cpp @@ -33,14 +33,14 @@ namespace { for (std::size_t length = 0; shift + length < request.size(); ++length) { if (request.at(shift + length) == '/') { - parts.emplace_back(request.data() + shift, length); + parts.emplace_back(&request.at(shift), length); shift += length + 1; length = 0; } } if (shift < request.size()) { - parts.emplace_back(request.data() + shift, request.size() - shift); + parts.emplace_back(&request.at(shift), request.size() - shift); } } catch (...) { return {}; diff --git a/src/buildtool/execution_api/execution_service/bytestream_server.cpp b/src/buildtool/execution_api/execution_service/bytestream_server.cpp index 1740c1f1..7d2bd48a 100644 --- a/src/buildtool/execution_api/execution_service/bytestream_server.cpp +++ b/src/buildtool/execution_api/execution_service/bytestream_server.cpp @@ -138,7 +138,7 @@ auto BytestreamServiceImpl::Write( auto tmp = tmp_dir->GetPath() / write_digest->hash(); { std::ofstream stream{tmp, std::ios::binary}; - do { + do { // NOLINT(cppcoreguidelines-avoid-do-while) if (not stream.good()) { auto const str = fmt::format("Failed to write data for {}", write_digest->hash()); diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp index cbf61edd..6f77ba3f 100644 --- a/src/buildtool/execution_api/execution_service/execution_server.cpp +++ b/src/buildtool/execution_api/execution_service/execution_server.cpp @@ -262,17 +262,17 @@ auto ExecutionServiceImpl::WaitExecution( return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, str}; } logger_.Emit(LogLevel::Trace, "WaitExecution: {}", hash); - std::optional<::google::longrunning::Operation> op; - do { - op = op_cache_.Query(hash); - if (not op) { - auto const str = fmt::format( - "Executing action {} not found in internal cache.", hash); - logger_.Emit(LogLevel::Error, "{}", str); - return ::grpc::Status{grpc::StatusCode::INTERNAL, str}; - } + auto op = op_cache_.Query(hash); + while (op and not op->done()) { std::this_thread::sleep_for(std::chrono::seconds(1)); - } while (not op->done()); + op = op_cache_.Query(hash); + } + if (not op) { + auto const str = fmt::format( + "Executing action {} not found in internal cache.", hash); + logger_.Emit(LogLevel::Error, "{}", str); + return ::grpc::Status{grpc::StatusCode::INTERNAL, str}; + } writer->Write(*op); logger_.Emit(LogLevel::Trace, "Finished WaitExecution {}", hash); return ::grpc::Status::OK; diff --git a/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp b/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp index a67fd904..dca8d59a 100644 --- a/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp +++ b/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp @@ -117,8 +117,8 @@ class ByteStreamClient { request.set_resource_name(std::move(write_request).ToString()); request.mutable_data()->resize(ByteStreamUtils::kChunkSize, '\0'); - std::size_t pos{}; - do { + std::size_t pos = 0; + do { // NOLINT(cppcoreguidelines-avoid-do-while) auto const size = std::min(data.size() - pos, ByteStreamUtils::kChunkSize); request.mutable_data()->resize(size); diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp index ad3e4773..9dc16592 100644 --- a/src/buildtool/file_system/file_system_manager.hpp +++ b/src/buildtool/file_system/file_system_manager.hpp @@ -703,7 +703,7 @@ class FileSystemManager { std::ifstream file_reader(file.string(), std::ios::binary); if (file_reader.is_open()) { auto ssize = gsl::narrow<std::streamsize>(chunk.size()); - do { + while (file_reader.good()) { file_reader.read(chunk.data(), ssize); auto count = file_reader.gcount(); if (count == ssize) { @@ -713,7 +713,7 @@ class FileSystemManager { content += chunk.substr(0, gsl::narrow<std::size_t>(count)); } - } while (file_reader.good()); + } file_reader.close(); return content; } diff --git a/src/buildtool/file_system/git_context.cpp b/src/buildtool/file_system/git_context.cpp index 4fc613a3..f6f83c0d 100644 --- a/src/buildtool/file_system/git_context.cpp +++ b/src/buildtool/file_system/git_context.cpp @@ -24,6 +24,7 @@ extern "C" { GitContext::GitContext() noexcept { #ifndef BOOTSTRAP_BUILD_TOOL + // NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer) initialized_ = git_libgit2_init() >= 0; if (not initialized_) { Logger::Log(LogLevel::Error, "initializing libgit2 failed"); diff --git a/src/buildtool/logging/logger.hpp b/src/buildtool/logging/logger.hpp index 32fd9fb0..f224edd8 100644 --- a/src/buildtool/logging/logger.hpp +++ b/src/buildtool/logging/logger.hpp @@ -154,11 +154,13 @@ class Logger { /// \brief Format message and forward to sinks. template <class... T_Args> - static void FormatAndForward(Logger const* logger, - std::vector<ILogSink::Ptr> const& sinks, - LogLevel level, - std::string const& msg, - T_Args&&... args) noexcept { + static void FormatAndForward( + Logger const* logger, + std::vector<ILogSink::Ptr> const& sinks, + LogLevel level, + std::string const& msg, + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + T_Args&&... args) noexcept { if constexpr (sizeof...(T_Args) == 0) { // forward to sinks std::for_each(sinks.cbegin(), sinks.cend(), [&](auto& sink) { diff --git a/src/buildtool/storage/compactification_task.hpp b/src/buildtool/storage/compactification_task.hpp index e0f7e492..dee2ee2c 100644 --- a/src/buildtool/storage/compactification_task.hpp +++ b/src/buildtool/storage/compactification_task.hpp @@ -76,9 +76,11 @@ struct CompactificationTask final { CompactificationTask const& task) noexcept -> bool; template <typename... Args> -void CompactificationTask::Log(LogLevel level, - std::string const& message, - Args&&... args) const noexcept { +void CompactificationTask::Log( + LogLevel level, + std::string const& message, + // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) + Args&&... args) const noexcept { if (not logger) { ::Logger::Log(LogLevel::Error, "Logger is missing."); return; diff --git a/src/buildtool/system/system_command.hpp b/src/buildtool/system/system_command.hpp index ade2f54b..909c047a 100644 --- a/src/buildtool/system/system_command.hpp +++ b/src/buildtool/system/system_command.hpp @@ -201,7 +201,7 @@ class SystemCommand { // wait for child to finish and obtain return value int status{}; std::optional<int> retval{std::nullopt}; - do { + while (not retval) { if (::waitpid(pid, &status, 0) == -1) { // this should never happen logger_.Emit(LogLevel::Error, @@ -221,7 +221,7 @@ class SystemCommand { LogLevel::Debug, "Child got killed by signal {}", sig); } // continue waitpid() in case we got STOPSIG from child - } while (not retval); + } return retval; } diff --git a/src/other_tools/utils/curl_context.cpp b/src/other_tools/utils/curl_context.cpp index 3e0b514e..7006d727 100644 --- a/src/other_tools/utils/curl_context.cpp +++ b/src/other_tools/utils/curl_context.cpp @@ -21,9 +21,8 @@ extern "C" { #include <curl/curl.h> } -CurlContext::CurlContext() noexcept { - // NOLINTNEXTLINE(hicpp-signed-bitwise) - initialized_ = curl_global_init(CURL_GLOBAL_DEFAULT) >= 0; +CurlContext::CurlContext() noexcept + : initialized_{curl_global_init(CURL_GLOBAL_DEFAULT) >= 0} { if (not initialized_) { Logger::Log(LogLevel::Error, "initializing libcurl failed"); } |