From 477b71f9c08afefe8a87eee7195a3abe4cb4096c Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Sun, 10 Dec 2023 23:13:29 +0100 Subject: [PATCH] Re-add s2p_version.cpp, renaming --- .github/workflows/analyze.yml | 36 +++++------------ .github/workflows/analyze_k8s.yml | 53 ------------------------- cpp/shared/s2p_util.cpp | 4 +- cpp/shared/s2p_version.cpp | 14 +++++++ cpp/shared/s2p_version.h | 11 ++--- cpp/shared_command/command_response.cpp | 4 +- cpp/test/command_response_test.cpp | 5 ++- 7 files changed, 36 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/analyze_k8s.yml create mode 100644 cpp/shared/s2p_version.cpp diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 08b4232e..10979137 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -10,14 +10,13 @@ on: jobs: code_analysis: - runs-on: ubuntu-latest + runs-on: [k8s] defaults: run: working-directory: cpp env: - PACKAGES: protobuf-compiler libspdlog-dev libpcap-dev libgmock-dev BUILD_WRAPPER_OUT_DIR: ".build_wrapper_out" SONAR_SERVER_URL: "https://sonarcloud.io" SONAR_PROJECT_KEY: "uweseimet_scsi2pi" @@ -32,24 +31,10 @@ jobs: # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 - - name: Install additional packages - run: sudo apt install --yes $PACKAGES - - - name: Set up Python for gcovr - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - - name: Install gcovr - run: pip install gcovr==5.0 # 5.1 is not supported - - - name: Install sonar-scanner and build-wrapper - uses: SonarSource/sonarcloud-github-c-cpp@v2 - - name: Run build-wrapper run: | build-wrapper-linux-x86-64 --out-dir $BUILD_WRAPPER_OUT_DIR \ - make -j $(nproc) coverage DEBUG=1 + make -j2 coverage DEBUG=1 - name: Generate coverage data run: gcovr --sonarqube > coverage.xml @@ -57,11 +42,12 @@ jobs: - name: Run sonar-scanner run: | sonar-scanner \ - --define sonar.host.url=$SONAR_SERVER_URL \ - --define sonar.projectKey=$SONAR_PROJECT_KEY \ - --define sonar.organization=$SONAR_ORGANIZATION \ - --define sonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR \ - --define sonar.coverageReportPaths=coverage.xml \ - --define sonar.exclusions="obj/**,lib/**,bin/**,generated/**" \ - --define sonar.coverage.exclusions="test/**" \ - --define sonar.cpd.exclusions="test/**" + --define sonar.host.url=$SONAR_SERVER_URL \ + --define sonar.projectKey=$SONAR_PROJECT_KEY \ + --define sonar.organization=$SONAR_ORGANIZATION \ + --define sonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR \ + --define sonar.coverageReportPaths=coverage.xml \ + --define sonar.branch.name=${{ inputs.branch }} \ + --define sonar.exclusions="obj/**,lib/**,bin/**,generated/**" \ + --define sonar.coverage.exclusions="test/**" \ + --define sonar.cpd.exclusions="test/**" diff --git a/.github/workflows/analyze_k8s.yml b/.github/workflows/analyze_k8s.yml deleted file mode 100644 index 6e6357cb..00000000 --- a/.github/workflows/analyze_k8s.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Run Sonar analysis (k8s) - -on: - workflow_dispatch: - inputs: - branch: - required: true - type: string - description: Branch to analyze - -jobs: - code_analysis: - runs-on: [k8s] - - defaults: - run: - working-directory: cpp - - env: - BUILD_WRAPPER_OUT_DIR: ".build_wrapper_out" - SONAR_SERVER_URL: "https://sonarcloud.io" - SONAR_PROJECT_KEY: "uweseimet_scsi2pi" - SONAR_ORGANIZATION: ${{ secrets.SONAR_ORGANIZATION }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ inputs.branch }} - # Shallow clones should be disabled for a better relevancy of analysis - fetch-depth: 0 - - - name: Run build-wrapper - run: | - build-wrapper-linux-x86-64 --out-dir $BUILD_WRAPPER_OUT_DIR \ - make -j2 coverage DEBUG=1 - - - name: Generate coverage data - run: gcovr --sonarqube > coverage.xml - - - name: Run sonar-scanner - run: | - sonar-scanner \ - --define sonar.host.url=$SONAR_SERVER_URL \ - --define sonar.projectKey=$SONAR_PROJECT_KEY \ - --define sonar.organization=$SONAR_ORGANIZATION \ - --define sonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR \ - --define sonar.coverageReportPaths=coverage.xml \ - --define sonar.branch.name=${{ inputs.branch }} \ - --define sonar.exclusions="obj/**,lib/**,bin/**,generated/**" \ - --define sonar.coverage.exclusions="test/**" \ - --define sonar.cpd.exclusions="test/**" diff --git a/cpp/shared/s2p_util.cpp b/cpp/shared/s2p_util.cpp index 29b7317e..5f246e85 100644 --- a/cpp/shared/s2p_util.cpp +++ b/cpp/shared/s2p_util.cpp @@ -22,7 +22,7 @@ using namespace filesystem; string s2p_util::GetVersionString() { return fmt::format("{0}.{1}{2}{3}", s2p_major_version, s2p_minor_version, - s2p_patch_version <= 0 ? "" : "." + to_string(s2p_patch_version), s2p_version_suffix); + s2p_revision <= 0 ? "" : "." + to_string(s2p_revision), s2p_suffix); } vector s2p_util::Split(const string& s, char separator, int limit) @@ -112,7 +112,7 @@ string s2p_util::Banner(string_view app) s << "SCSI Target Emulator and SCSI Initiator Tools SCSI2Pi " << app << "\n" << "Version " << GetVersionString(); - if (!s2p_version_suffix.empty()) { + if (!s2p_suffix.empty()) { s << " (" << __DATE__ << ' ' << __TIME__ << ")"; } s << "\nCopyright (C) 2016-2020 GIMONS\n" diff --git a/cpp/shared/s2p_version.cpp b/cpp/shared/s2p_version.cpp new file mode 100644 index 00000000..0898960c --- /dev/null +++ b/cpp/shared/s2p_version.cpp @@ -0,0 +1,14 @@ +//--------------------------------------------------------------------------- +// +// SCSI target emulator and SCSI initiator tools for the Raspberry Pi +// +// Copyright (C) 2023 Uwe Seimet +// +//--------------------------------------------------------------------------- + +#include "s2p_version.h" + +const int s2p_major_version = 0; +const int s2p_minor_version = 9; +const int s2p_revision = 0; +const std::string s2p_suffix = "-devel"; diff --git a/cpp/shared/s2p_version.h b/cpp/shared/s2p_version.h index 0df93a6b..7a21563c 100644 --- a/cpp/shared/s2p_version.h +++ b/cpp/shared/s2p_version.h @@ -10,11 +10,8 @@ #include -inline const int s2p_major_version = 0; - -inline const int s2p_minor_version = 9; - -inline const int s2p_patch_version = 0; - +extern const int s2p_major_version; +extern const int s2p_minor_version; +extern const int s2p_revision; // Version suffix, usually indicating a development version -inline const std::string s2p_version_suffix = "-devel"; +extern const std::string s2p_suffix; diff --git a/cpp/shared_command/command_response.cpp b/cpp/shared_command/command_response.cpp index f051f876..c46bac6d 100644 --- a/cpp/shared_command/command_response.cpp +++ b/cpp/shared_command/command_response.cpp @@ -297,8 +297,8 @@ void CommandResponse::GetVersionInfo(PbVersionInfo& version_info) const { version_info.set_major_version(s2p_major_version); version_info.set_minor_version(s2p_minor_version); - version_info.set_patch_version(s2p_patch_version); - version_info.set_suffix(s2p_version_suffix); + version_info.set_patch_version(s2p_revision); + version_info.set_suffix(s2p_suffix); version_info.set_identifier("SCSI2Pi"); } diff --git a/cpp/test/command_response_test.cpp b/cpp/test/command_response_test.cpp index c9ef6efb..3210d83a 100644 --- a/cpp/test/command_response_test.cpp +++ b/cpp/test/command_response_test.cpp @@ -194,7 +194,7 @@ TEST(CommandResponseTest, GetServerInfo) EXPECT_EQ(s2p_major_version, info1.version_info().major_version()); EXPECT_EQ(s2p_minor_version, info1.version_info().minor_version()); - EXPECT_EQ(s2p_patch_version, info1.version_info().patch_version()); + EXPECT_EQ(s2p_revision, info1.version_info().patch_version()); EXPECT_EQ(level::level_string_views[get_level()], info1.log_level_info().current_log_level()); EXPECT_EQ("default_folder", info1.image_files_info().default_image_folder()); EXPECT_EQ(1234, info1.image_files_info().depth()); @@ -223,7 +223,8 @@ TEST(CommandResponseTest, GetVersionInfo) response.GetVersionInfo(info); EXPECT_EQ(s2p_major_version, info.major_version()); EXPECT_EQ(s2p_minor_version, info.minor_version()); - EXPECT_EQ(s2p_patch_version, info.patch_version()); + EXPECT_EQ(s2p_revision, info.patch_version()); + EXPECT_EQ(s2p_suffix, info.suffix()); } TEST(CommandResponseTest, GetLogLevelInfo)