Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ project(ArgumentManagerProject VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(${CMAKE_SOURCE_DIR}/cmake/CoreTraceVersion.cmake)
coretrace_resolve_version(CTRACE_VERSION_STRING CTRACE_VERSION_SOURCE)

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/generated/include/App")
configure_file(${CMAKE_SOURCE_DIR}/include/App/Version.hpp.in
${CMAKE_BINARY_DIR}/generated/include/App/Version.hpp
@ONLY)

include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/external)
include_directories(${CMAKE_BINARY_DIR}/generated/include)

message(STATUS "CoreTrace version: ${CTRACE_VERSION_STRING} (${CTRACE_VERSION_SOURCE})")

set(PARSER_TYPE "CLI11" CACHE STRING "Type of parser to use (Getopt or CLI11)")
set_property(CACHE PARSER_TYPE PROPERTY STRINGS "Getopt" "CLI11")
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.release-binaries
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ WORKDIR /repo
FROM base AS builder

ARG LLVM_VERSION=20
ARG VERSION=dev

COPY . /repo

Expand All @@ -46,9 +47,11 @@ RUN cmake -S . -B build -G Ninja \
-DUSE_THREAD_SANITIZER=OFF \
-DUSE_ADDRESS_SANITIZER=OFF \
-DCLANG_LINK_CLANG_DYLIB=ON \
-DCORETRACE_VERSION_OVERRIDE="${VERSION}" \
-DLLVM_DIR=/usr/lib/llvm-${LLVM_VERSION}/lib/cmake/llvm \
-DClang_DIR=/usr/lib/llvm-${LLVM_VERSION}/lib/cmake/clang \
&& cmake --build build -j"$(nproc)" \
&& ./build/ctrace --version >/dev/null \
&& ./build/ctrace -h >/dev/null

FROM builder AS packager
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ or
### ARGUMENT

```bash
./ctrace [-h|--help]
./ctrace [--help|--version]
ctrace - Static & Dynamic C/C++ Code Analysis Tool

Usage:
ctrace [options]

Options:
--help Displays this help message.
--version Displays build version information.
--verbose Enables detailed (verbose) output.
--quiet Suppresses non-essential output.
--sarif-format Generates a report in SARIF format.
Expand Down Expand Up @@ -97,6 +98,24 @@ Description:
and memory misuse.
```

### VERSION

```bash
./ctrace --version
```

Version resolution is centralized at configure time:

- release builds pass an explicit version string from CI, so published binaries print the exact GitHub release tag
- local Git builds resolve the version from `git describe --tags --dirty --always --match 'v*'`
- if Git metadata is unavailable, the build falls back to `dev`

You can also override the embedded version manually:

```bash
cmake .. -DCORETRACE_VERSION_OVERRIDE=v0.74.0
```

### CONFIGURATION

- Canonical default config: `config/tool-config.json`
Expand Down
36 changes: 36 additions & 0 deletions cmake/CoreTraceVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
set(CORETRACE_VERSION_OVERRIDE "" CACHE STRING
"Explicit CoreTrace version string embedded in the binary")

set(CORETRACE_FALLBACK_VERSION "dev" CACHE STRING
"Fallback CoreTrace version string when Git metadata is unavailable")

function(coretrace_resolve_version out_var out_source_var)
if(CORETRACE_VERSION_OVERRIDE)
set(_coretrace_version "${CORETRACE_VERSION_OVERRIDE}")
set(_coretrace_version_source "override")
else()
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_SOURCE_DIR}"
describe --tags --dirty --always --match "v*"
RESULT_VARIABLE _coretrace_git_result
OUTPUT_VARIABLE _coretrace_git_describe
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()

if(DEFINED _coretrace_git_result AND _coretrace_git_result EQUAL 0
AND NOT _coretrace_git_describe STREQUAL "")
set(_coretrace_version "${_coretrace_git_describe}")
set(_coretrace_version_source "git-describe")
else()
set(_coretrace_version "${CORETRACE_FALLBACK_VERSION}")
set(_coretrace_version_source "fallback")
endif()
endif()

set(${out_var} "${_coretrace_version}" PARENT_SCOPE)
set(${out_source_var} "${_coretrace_version_source}" PARENT_SCOPE)
endfunction()
13 changes: 13 additions & 0 deletions include/App/Version.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <string_view>

namespace ctrace::build
{
inline constexpr std::string_view kVersion = "@CTRACE_VERSION_STRING@";

[[nodiscard]] constexpr std::string_view version() noexcept
{
return kVersion;
}
} // namespace ctrace::build
12 changes: 7 additions & 5 deletions include/Config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ArgumentParser/ArgumentManager.hpp"
#include "ArgumentParser/ArgumentParserFactory.hpp"
#include "App/SupportedTools.hpp"
#include "App/Version.hpp"
#include "ctrace_tools/strings.hpp"
#include "ctrace_defs/types.hpp"

Expand All @@ -27,6 +28,7 @@ static void printHelp(void)

Options:
--help Displays this help message.
--version Displays build version information.
--verbose Enables detailed (verbose) output.
--sarif-format Generates a report in SARIF format.
--report-file <path> Specifies the path to the report file (default: ctrace-report.txt).
Expand Down Expand Up @@ -72,6 +74,11 @@ static void printHelp(void)
)" << std::endl;
}

static void printVersion(void)
{
std::cout << "ctrace " << ctrace::build::version() << std::endl;
}

namespace ctrace
{
/**
Expand Down Expand Up @@ -218,11 +225,6 @@ namespace ctrace
ConfigProcessor(ProgramConfig& cfg) : config(cfg)
{
// Initialize command mappings.
commands["--help"] = [this](const std::string&)
{
printHelp();
std::exit(0);
};
commands["--verbose"] = [this](const std::string&) { config.global.verbose = true; };
commands["--quiet"] = [this](const std::string&) { config.global.quiet = true; };
commands["--demangle"] = [this](const std::string&) { config.global.demangle = true; };
Expand Down
24 changes: 19 additions & 5 deletions src/App/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace ctrace
// TODO : lvl verbosity
argManager.addOption("--verbose", false, 'v');
argManager.addFlag("--help", 'h');
argManager.addFlag("--version", 'V');
argManager.addFlag("--quiet", 'q');
argManager.addOption("--output-file", true, 'o');
argManager.addOption("--invoke", true, 'i');
Expand Down Expand Up @@ -55,6 +56,24 @@ namespace ctrace
// Parsing des arguments
argManager.parse(argc, argv);

if (argManager.hasNoOption())
{
printHelp();
std::exit(0);
}

if (argManager.hasOption("--help"))
{
printHelp();
std::exit(0);
}

if (argManager.hasOption("--version"))
{
printVersion();
std::exit(0);
}

// Traitement avec Command
ConfigProcessor processor(config);
if (argManager.hasOption("--config"))
Expand All @@ -71,11 +90,6 @@ namespace ctrace
processor.process(argManager);
// processor.execute(argManager);

if (argManager.hasNoOption())
{
processor.execute("--help", "");
std::exit(0);
}
if (!(argManager.getOptionValue("--ipc") == "serve") &&
(argManager.hasOption("--serve-host") || argManager.hasOption("--serve-port")))
{
Expand Down
Loading