From 3ba2a507edf819b8fe495eb84daf84ff01beb5b8 Mon Sep 17 00:00:00 2001 From: Sebastian Kreutzer Date: Fri, 22 Aug 2025 17:00:07 +0200 Subject: [PATCH 1/3] Add metacg-config binary --- .github/workflows/mcg-ci.yml | 10 +++++-- CMakeLists.txt | 2 ++ cmake/ToolchainOptions.cmake | 8 +----- config/CMakeLists.txt | 6 ++++ config/MCGConfig.cpp | 55 ++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 config/CMakeLists.txt create mode 100644 config/MCGConfig.cpp diff --git a/.github/workflows/mcg-ci.yml b/.github/workflows/mcg-ci.yml index a325822e..0bcdc225 100644 --- a/.github/workflows/mcg-ci.yml +++ b/.github/workflows/mcg-ci.yml @@ -45,12 +45,12 @@ jobs: steps: - uses: actions/checkout@v4 - name: cmake - run: cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -B build -S . + run: cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_INSTALL_PREFIX="$(pwd)/install" -B build -S . - name: build run: cmake --build build --parallel - name: install run: | - cmake --install build --prefix install + cmake --install build --prefix install stat install/lib/libmetacg.so stat install/include/metadata/CustomMD.h stat install/lib/cmake/metacg/metacgConfig.cmake @@ -58,6 +58,12 @@ jobs: run: | CMAKE_PREFIX_PATH=install/lib/cmake/metacg cmake -S graph/test/install -B build-install-test cmake --build build-install-test + - name: metacg-config-test + run: | + MCG_CFG=install/bin/metacg-config + stat $MCG_CFG + [[ "$($MCG_CFG --prefix)" == "$(cd install; pwd)" ]] || exit 1 + [[ "$($MCG_CFG --revision)" == "$(git rev-parse HEAD)" ]] || exit 1 build-container: runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index e43a59d2..88fb56af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,3 +191,5 @@ option( if(METACG_BUILD_PYMETACG) add_subdirectory(pymetacg) endif() + +add_subdirectory(config) diff --git a/cmake/ToolchainOptions.cmake b/cmake/ToolchainOptions.cmake index a6226108..48cde7be 100644 --- a/cmake/ToolchainOptions.cmake +++ b/cmake/ToolchainOptions.cmake @@ -1,12 +1,6 @@ include(json) include(spdlog) - -if(METACG_BUILD_GRAPH_TOOLS - OR METACG_BUILD_CGCOLLECTOR - OR METACG_BUILD_PGIS -) - include(cxxopts-lib) -endif() +include(cxxopts-lib) # Internal dependencies function(add_metacg target) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 00000000..ccf3f1b6 --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(metacg-config MCGConfig.cpp) +add_config_include(metacg-config) +target_compile_definitions(metacg-config PRIVATE INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") +add_cxxopts(metacg-config) + +install(TARGETS metacg-config DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/config/MCGConfig.cpp b/config/MCGConfig.cpp new file mode 100644 index 00000000..05030f99 --- /dev/null +++ b/config/MCGConfig.cpp @@ -0,0 +1,55 @@ +/** + * File: MCGConfig.cpp + * License: Part of the MetaCG project. Licensed under BSD 3 clause license. See LICENSE.txt file at + * https://github.com/tudasc/metacg/LICENSE.txt + */ +#include "config.h" + +#include + +#include "cxxopts.hpp" + +int main(int argc, char** argv) { + cxxopts::Options options("metacg-config", "MetaCG configuration tool"); + options.add_options("commands")("v,version", "Prints the version of this MetaCG installation")( + "revision", "Prints the revision hash of this MetaCG installation")( + "prefix", "Prints the installation prefix of this MetaCG installation.")("h,help", "Print help"); + + const cxxopts::ParseResult result = options.parse(argc, argv); + + if (result.contains("help")) { + std::cout << options.help() << std::endl; + return EXIT_SUCCESS; + } + + // Exactly one of these is allowed at the same time + int optCount = result.count("version") + result.count("revision") + result.count("prefix"); + if (optCount == 0) { + std::cerr << "Error: No command specified.\n"; + return EXIT_FAILURE; + } else if (optCount > 1) { + std::cerr << "Warning: Multiple mutually exclusive commands specified. Only one of them will be processed.\n"; + } + + if (result.contains("version")) { + std::cout << MetaCG_VERSION_MAJOR << "." << MetaCG_VERSION_MINOR; + return EXIT_SUCCESS; + } + + if (result.contains("revision")) { + std::cout << MetaCG_GIT_SHA; + return EXIT_SUCCESS; + } + + if (result.contains("version")) { + std::cout << MetaCG_VERSION_MAJOR << "." << MetaCG_VERSION_MINOR; + return EXIT_SUCCESS; + } + + if (result.contains("prefix")) { + std::cout << INSTALL_PREFIX; + return EXIT_SUCCESS; + } + + return EXIT_SUCCESS; +} \ No newline at end of file From 4fef6ee9570772467392fceae6473a10847eb24a Mon Sep 17 00:00:00 2001 From: Sebastian Kreutzer Date: Mon, 25 Aug 2025 10:48:55 +0200 Subject: [PATCH 2/3] fixup! Add metacg-config binary --- .github/workflows/mcg-ci.yml | 2 +- config/MCGConfig.cpp | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/mcg-ci.yml b/.github/workflows/mcg-ci.yml index 0bcdc225..109d9bea 100644 --- a/.github/workflows/mcg-ci.yml +++ b/.github/workflows/mcg-ci.yml @@ -50,7 +50,7 @@ jobs: run: cmake --build build --parallel - name: install run: | - cmake --install build --prefix install + cmake --install build --prefix install stat install/lib/libmetacg.so stat install/include/metadata/CustomMD.h stat install/lib/cmake/metacg/metacgConfig.cmake diff --git a/config/MCGConfig.cpp b/config/MCGConfig.cpp index 05030f99..fddb16d1 100644 --- a/config/MCGConfig.cpp +++ b/config/MCGConfig.cpp @@ -41,15 +41,10 @@ int main(int argc, char** argv) { return EXIT_SUCCESS; } - if (result.contains("version")) { - std::cout << MetaCG_VERSION_MAJOR << "." << MetaCG_VERSION_MINOR; - return EXIT_SUCCESS; - } - if (result.contains("prefix")) { std::cout << INSTALL_PREFIX; return EXIT_SUCCESS; } return EXIT_SUCCESS; -} \ No newline at end of file +} From 15d02cf4b031287b77f2cc5e32c74e85e8862f42 Mon Sep 17 00:00:00 2001 From: Sebastian Kreutzer Date: Mon, 25 Aug 2025 15:12:16 +0200 Subject: [PATCH 3/3] Move TargetCollector.py and metacg-config into new utils folder --- CMakeLists.txt | 2 +- graph/test/integration/TargetCollector/TestRunner.sh | 2 +- utils/CMakeLists.txt | 1 + TargetCollector.py => utils/TargetCollector.py | 0 {config => utils/config}/CMakeLists.txt | 0 {config => utils/config}/MCGConfig.cpp | 0 6 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 utils/CMakeLists.txt rename TargetCollector.py => utils/TargetCollector.py (100%) rename {config => utils/config}/CMakeLists.txt (100%) rename {config => utils/config}/MCGConfig.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88fb56af..75f7289f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,4 +192,4 @@ if(METACG_BUILD_PYMETACG) add_subdirectory(pymetacg) endif() -add_subdirectory(config) +add_subdirectory(utils) diff --git a/graph/test/integration/TargetCollector/TestRunner.sh b/graph/test/integration/TargetCollector/TestRunner.sh index 89aee4cb..9150b825 100755 --- a/graph/test/integration/TargetCollector/TestRunner.sh +++ b/graph/test/integration/TargetCollector/TestRunner.sh @@ -27,7 +27,7 @@ done echo "Running integration test for TargetCollector script" echo "{}" > src/wholeProgramCG-${CI_CONCURRENT_ID}.ipcg -test_command=(python3 ../../../../TargetCollector.py \ +test_command=(python3 ../../../../utils/TargetCollector.py \ -a=".." \ -g=both \ -b=build-${CI_CONCURRENT_ID} \ diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 00000000..9040988f --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(config) diff --git a/TargetCollector.py b/utils/TargetCollector.py similarity index 100% rename from TargetCollector.py rename to utils/TargetCollector.py diff --git a/config/CMakeLists.txt b/utils/config/CMakeLists.txt similarity index 100% rename from config/CMakeLists.txt rename to utils/config/CMakeLists.txt diff --git a/config/MCGConfig.cpp b/utils/config/MCGConfig.cpp similarity index 100% rename from config/MCGConfig.cpp rename to utils/config/MCGConfig.cpp