navid/veins / commit
5f489932bf8c
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: d14f484519f1
Browse files at this commit · Download source
--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -54,8 +54,7 @@ echo "export VERSION=$VERSION" >> "$BASH_ENV" cmake -S xveins -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Release \- -DVN_VERSION="$VERSION" \- -DVN_COMMIT="${CIRCLE_SHA1:0:12}"+ -DVN_VERSION="$VERSION" - run: name: Build command: cmake --build build -j "$(nproc)"@@ -98,6 +97,28 @@ steps: - build-and-package-linux: arch: aarch64++ build-linux-x86_64-asan:+ executor: linux-x86_64+ steps:+ - install-linux-deps+ - checkout+ - run:+ name: Configure with AddressSanitizer and UndefinedBehaviorSanitizer+ command: |+ cmake -S xveins -B build -G Ninja \+ -DCMAKE_BUILD_TYPE=Debug \+ -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \+ -DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \+ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined"+ - run:+ name: Build+ command: cmake --build build -j "$(nproc)"+ - run:+ name: Test+ command: |+ ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=halt_on_error=1 \+ ctest --test-dir build --output-on-failure build-windows-x86_64: executor: windows-x86_64@@ -119,12 +140,10 @@ shell: powershell command: | $version = if ($env:CIRCLE_TAG) { $env:CIRCLE_TAG -replace '^v', '' } else { '0.0.0-dev' }- $commit = if ($env:CIRCLE_SHA1) { $env:CIRCLE_SHA1.Substring(0, 12) } else { '' } "VERSION=$version" | Out-File -FilePath $env:BASH_ENV -Append -Encoding ascii cmake -S xveins -B build -G Ninja ` -DCMAKE_BUILD_TYPE=Release ` -DVN_VERSION="$version" `- -DVN_COMMIT="$commit" ` -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg-2026.10.16/scripts/buildsystems/vcpkg.cmake ` -DVCPKG_TARGET_TRIPLET=x64-windows-static - run:@@ -193,11 +212,13 @@ jobs: - build-linux-x86_64 - build-linux-aarch64+ - build-linux-x86_64-asan - build-windows-x86_64 - release-report: requires: - build-linux-x86_64 - build-linux-aarch64+ - build-linux-x86_64-asan - build-windows-x86_64 filters: branches:--- a/xveins/CMakeLists.txt+++ b/xveins/CMakeLists.txt@@ -21,9 +21,6 @@ set(BUILD_SHARED_LIBS OFF) -option(VN_COMMIT_FROM_GIT- "Read VN_COMMIT from git at configure time (off for reproducible/offline builds)"- OFF) option(VN_STRIP_RELEASE "Strip symbols and debug information from Release binaries" ON)@@ -175,22 +172,6 @@ check_cxx_compiler_flag(-Wconversion VN_HAS_WCONVERSION) set(VN_VERSION "${PROJECT_VERSION}" CACHE STRING "veins version")-set(VN_COMMIT "" CACHE STRING "veins source commit hash (empty: leave unset)")--set(_VN_COMMIT "${VN_COMMIT}")-if(NOT _VN_COMMIT AND VN_COMMIT_FROM_GIT)- execute_process(- COMMAND git rev-parse --short=12 HEAD- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"- OUTPUT_VARIABLE _VN_COMMIT- OUTPUT_STRIP_TRAILING_WHITESPACE- ERROR_QUIET- RESULT_VARIABLE _VN_COMMIT_RESULT- )- if(NOT _VN_COMMIT_RESULT EQUAL 0)- set(_VN_COMMIT "")- endif()-endif() function(vn_configure_target target) target_include_directories(${target} PRIVATE src)@@ -205,10 +186,6 @@ if(WIN32) target_link_libraries(${target} PRIVATE bcrypt ws2_32 crypt32) endif()- target_compile_definitions(${target} PRIVATE- VN_VERSION="${VN_VERSION}"- VN_COMMIT="${_VN_COMMIT}"- ) if(MSVC) target_compile_options(${target} PRIVATE /W4 /permissive- /EHsc /Zc:__cplusplus)@@ -253,10 +230,39 @@ add_library(vn_core STATIC ${VN_CORE_SOURCES}) vn_configure_target(vn_core)++set(VN_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")++add_executable(vn-bootstrap src/main.cpp src/version/version_bootstrap.cpp)+vn_configure_target(vn-bootstrap)+target_link_libraries(vn-bootstrap PRIVATE vn_core)+target_compile_definitions(vn-bootstrap PRIVATE VN_VERSION="${VN_VERSION}")+set_target_properties(vn-bootstrap PROPERTIES+ EXCLUDE_FROM_ALL TRUE+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bootstrap"+ OUTPUT_NAME "vn-bootstrap"+)++add_custom_target(vn-commit+ COMMAND ${CMAKE_COMMAND}+ "-DVN_BOOTSTRAP=$<TARGET_FILE:vn-bootstrap>"+ "-DVN_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"+ "-DVN_OUTPUT_DIR=${VN_GENERATED_DIR}/$<CONFIG>"+ -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_vn_commit.cmake"+ DEPENDS vn-bootstrap+ COMMENT "Generating vn revision header"+ VERBATIM+)++add_library(vn_version STATIC src/version/version.cpp)+vn_configure_target(vn_version)+target_include_directories(vn_version PRIVATE "${VN_GENERATED_DIR}/$<CONFIG>")+target_compile_definitions(vn_version PRIVATE VN_VERSION="${VN_VERSION}")+add_dependencies(vn_version vn-commit) add_executable(vn src/main.cpp) vn_configure_target(vn)-target_link_libraries(vn PRIVATE vn_core)+target_link_libraries(vn PRIVATE vn_core vn_version) set_target_properties(vn PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"@@ -267,12 +273,12 @@ if(BUILD_TESTING) add_executable(vn-unit-tests tests/unit_tests.cpp) vn_configure_target(vn-unit-tests)- target_link_libraries(vn-unit-tests PRIVATE vn_core)+ target_link_libraries(vn-unit-tests PRIVATE vn_core vn_version) add_test(NAME vn-unit-tests COMMAND vn-unit-tests) add_executable(vn-integration-tests tests/integration_tests.cpp) vn_configure_target(vn-integration-tests)- target_link_libraries(vn-integration-tests PRIVATE vn_core)+ target_link_libraries(vn-integration-tests PRIVATE vn_core vn_version) add_test(NAME vn-self-test COMMAND vn self-test) --- a/xveins/CMakePresets.json+++ b/xveins/CMakePresets.json@@ -12,8 +12,7 @@ "binaryDir": "${sourceDir}/build/dev", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug",- "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",- "VN_COMMIT_FROM_GIT": "ON"+ "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" } }, {@@ -23,7 +22,6 @@ "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",- "VN_COMMIT_FROM_GIT": "OFF", "VN_STRIP_RELEASE": "ON" } },--- /dev/null+++ b/xveins/cmake/generate_vn_commit.cmake@@ -0,0 +1,58 @@+# Compute the revision embedded in the vn binary. The bootstrap vn executable+# is preferred because it reports the current veins working-copy revision and+# works wherever the source tree is a veins checkout. Git is the fallback for+# git-based checkouts and source archives.++set(_commit "")++if(EXISTS "${VN_BOOTSTRAP}")+ execute_process(+ COMMAND "${VN_BOOTSTRAP}" hash -short+ WORKING_DIRECTORY "${VN_SOURCE_DIR}"+ OUTPUT_VARIABLE _output+ OUTPUT_STRIP_TRAILING_WHITESPACE+ ERROR_QUIET+ RESULT_VARIABLE _result+ TIMEOUT 120+ )+ if(_result EQUAL 0)+ string(STRIP "${_output}" _output)+ string(REPLACE "\r" "" _output "${_output}")+ if(_output MATCHES "^[0-9a-fA-F]+$")+ set(_commit "${_output}")+ endif()+ endif()+endif()++if(NOT _commit)+ execute_process(+ COMMAND git rev-parse --short=12 HEAD+ WORKING_DIRECTORY "${VN_SOURCE_DIR}"+ OUTPUT_VARIABLE _output+ OUTPUT_STRIP_TRAILING_WHITESPACE+ ERROR_QUIET+ RESULT_VARIABLE _result+ )+ if(_result EQUAL 0)+ string(STRIP "${_output}" _output)+ string(REPLACE "\r" "" _output "${_output}")+ if(_output MATCHES "^[0-9a-fA-F]+$")+ set(_commit "${_output}")+ endif()+ endif()+endif()++file(MAKE_DIRECTORY "${VN_OUTPUT_DIR}")+set(_header "// Generated at build time. Do not edit.\n")+string(APPEND _header "#define VN_COMMIT \"${_commit}\"\n")++set(_write TRUE)+if(EXISTS "${VN_OUTPUT_DIR}/vn_commit.h")+ file(READ "${VN_OUTPUT_DIR}/vn_commit.h" _existing)+ if(_existing STREQUAL _header)+ set(_write FALSE)+ endif()+endif()+if(_write)+ file(WRITE "${VN_OUTPUT_DIR}/vn_commit.h" "${_header}")+endif()--- a/xveins/src/cli/cli.cpp+++ b/xveins/src/cli/cli.cpp@@ -5,6 +5,7 @@ #include "merge/merge.h" #include "protocol/promisor.h" #include "store/store.h"+#include "version/version.h" #include "worktree/attributes.h" #include "worktree/pathspec.h" #include "worktree/worktree.h"@@ -20,10 +21,6 @@ #include <thread> #include <unordered_map> -#if !defined(VN_COMMIT)-#define VN_COMMIT ""-#endif- namespace vn { namespace {@@ -2892,9 +2889,9 @@ if (cmd == "self-test") return run_self_test(); if (cmd == "version" || cmd == "-version" || cmd == "-v") {- std::cout << "veins v" << VN_VERSION;- if (VN_COMMIT[0] != '\0')- std::cout << " " << VN_COMMIT;+ std::cout << "veins v" << vn_version();+ if (vn_commit()[0] != '\0')+ std::cout << " " << vn_commit(); std::cout << " (store v" << STORE_VERSION << ")\n"; return 0; }--- /dev/null+++ b/xveins/src/version/version.cpp@@ -0,0 +1,19 @@+#include "version/version.h"++#ifndef VN_VERSION+#define VN_VERSION ""+#endif++#include "vn_commit.h"++namespace vn {++const char* vn_version() {+ return VN_VERSION;+}++const char* vn_commit() {+ return VN_COMMIT;+}++} // namespace vn--- /dev/null+++ b/xveins/src/version/version.h@@ -0,0 +1,8 @@+#pragma once++namespace vn {++const char* vn_version();+const char* vn_commit();++} // namespace vn--- /dev/null+++ b/xveins/src/version/version_bootstrap.cpp@@ -0,0 +1,17 @@+#include "version/version.h"++#ifndef VN_VERSION+#define VN_VERSION ""+#endif++namespace vn {++const char* vn_version() {+ return VN_VERSION;+}++const char* vn_commit() {+ return "";+}++} // namespace vn--- a/xveins/src/worktree/attr.cpp+++ b/xveins/src/worktree/attr.cpp@@ -198,6 +198,8 @@ else out += line.eol; }+ if (!out.empty() && out.back() != '\n')+ out.push_back('\n'); return out; } --- a/xveins/tests/integration_tests.cpp+++ b/xveins/tests/integration_tests.cpp@@ -3,6 +3,7 @@ #include "cli/cli.h" #include "core/common.h" #include "store/store.h"+#include "version/version.h" #include <algorithm> #include <array>@@ -381,16 +382,19 @@ t.expect(fs::exists(f.repo / ".veins" / "format")); t.expect(fs::is_directory(f.repo / ".veins" / "op-heads")); const std::string version = f.vn({"version"}).out;- t.expect_contains(version, "veins v");+ t.expect_contains(version, "veins v" + std::string(vn_version())); t.expect_contains(version, "(store v" + std::to_string(STORE_VERSION) + ")");-#if defined(VN_COMMIT)- if (std::string_view(VN_COMMIT).size() > 0)- t.expect_contains(version, VN_COMMIT);-#endif+ t.expect_eq(f.vn({"-v"}).out, version);+ t.expect_eq(f.vn({"-version"}).out, version);+ const std::string commit = vn_commit();+ if (!commit.empty())+ t.expect_contains(version, commit); const std::string help_text = f.vn({"help"}).out;- t.expect_contains(help_text, "subcommands:");+ t.expect_contains(help_text, "commands:");+ t.expect_contains(help_text, "attr"); t.expect_contains(f.vn({"help", "log"}).out, "vn log"); t.expect_contains(f.vn({"help", "go"}).out, "aliases: commit");+ t.expect_contains(f.vn({"help", "attr"}).out, "vn attr rm"); } void core_outside_repository(test::Context& t) {@@ -726,9 +730,79 @@ t.expect_not_contains(after_remove, "*.c gen"); f.vn({"attr", "rm", "gen", "*.tmp"}); t.expect_not_contains(f.read(".vnattribs"), "-gen");++ VnFixture outside;+ outside.failed({"attr", "gen", "*.c"}, "not a veins repository");+}++void worktree_attributes_command_edges(test::Context& t) {+ VnFixture f;+ f.init();++ t.expect_eq(f.vn({"attr", "ls"}).out, "");+ t.expect_contains(f.vn({"attr", "rm", "gen", "*.c"}).out, "no matching attribute rules");+ t.expect(!f.exists(".vnattribs"));++ f.write(".vnattribs", "# leading comment\r\n\r\n*.c gen\r\n*.c txt\r\n*.cmd txt eol:crlf\r\n");+ t.expect_eq(f.vn({"attr", "ls"}).out, "*.c gen\n*.c txt\n*.cmd txt eol:crlf\n");+ f.vn({"attr", "bin", "*.c"});+ t.expect_eq(f.read(".vnattribs"),+ "# leading comment\r\n\r\n*.c gen\r\n*.c bin\r\n*.cmd txt eol:crlf\r\n");+ f.vn({"attr", "rm", "gen", "*.c"});+ t.expect_eq(f.read(".vnattribs"), "# leading comment\r\n\r\n*.c bin\r\n*.cmd txt eol:crlf\r\n");+ f.vn({"attr", "rm", "bin", "*.c"});+ t.expect_eq(f.read(".vnattribs"), "# leading comment\r\n\r\n*.cmd txt eol:crlf\r\n");++ f.write(".vnattribs", "*.c future eol:cr -gen\n*.d -bin\n*.e -txt\n*.f txt -eol\n");+ f.vn({"attr", "txt", "*.c"});+ t.expect_eq(f.read(".vnattribs"),+ "*.c future eol:cr -gen txt\n*.d -bin\n*.e -txt\n*.f txt -eol\n");+ f.vn({"attr", "gen", "*.c"});+ t.expect_eq(f.read(".vnattribs"),+ "*.c future eol:cr txt gen\n*.d -bin\n*.e -txt\n*.f txt -eol\n");+ f.vn({"attr", "crlf", "*.c"});+ t.expect_eq(f.read(".vnattribs"),+ "*.c future txt gen eol:crlf\n*.d -bin\n*.e -txt\n*.f txt -eol\n");+ f.vn({"attr", "rm", "bin", "*.d"});+ f.vn({"attr", "rm", "txt", "*.e"});+ f.vn({"attr", "lf", "*.f"});+ t.expect_eq(f.read(".vnattribs"), "*.c future txt gen eol:crlf\n*.f txt eol:lf\n");++ f.write(".vnattribs", "*.c txt");+ f.vn({"attr", "gen", "*.c"});+ t.expect_eq(f.read(".vnattribs"), "*.c txt gen\n");+ f.write(".vnattribs", "*.tmp gen");+ f.vn({"attr", "gen", "*.new"});+ t.expect_eq(f.read(".vnattribs"), "*.tmp gen\n*.new gen\n");++ f.write(".vnattribs", "*.c txt\n");+ const std::string unchanged = f.read(".vnattribs");+ t.expect_contains(f.vn({"attr", "rm", "gen", "*.c"}).out, "no matching attribute rules");+ t.expect_eq(f.read(".vnattribs"), unchanged);+ t.expect_eq(f.vn({"attr", "ls", "--"}).out, "*.c txt\n");++ f.failed({"attr", "gen", "bad pattern"}, "not a valid attribute pattern");+ f.failed({"attr", "gen", "#comment"}, "not a valid attribute pattern");+ f.failed({"attr", "gen", ""}, "not a valid attribute pattern");+ t.expect_eq(f.read(".vnattribs"), unchanged);++ f.failed({"attr"}, "requires a subcommand");+ f.failed({"attr", "gen"}, "requires at least one glob");+ f.failed({"attr", "rm"}, "usage: vn attr rm");+ f.failed({"attr", "rm", "gen"}, "usage: vn attr rm");+ f.failed({"attr", "wat", "*.c"}, "unknown attr subcommand");+ f.failed({"attr", "rm", "eol", "*.c"}, "unknown attribute");+ f.failed({"attr", "gen", "-x"}, "unknown flag");+ f.failed({"attr", "ls", "extra"}, "usage: vn attr ls");++ f.write(".vnattribs", "");+ f.vn({"attr", "gen", "--", "*.c"});+ t.expect_eq(f.read(".vnattribs"), "*.c gen\n"); VnFixture outside;+ outside.failed({"attr", "ls"}, "not a veins repository"); outside.failed({"attr", "gen", "*.c"}, "not a veins repository");+ outside.failed({"attr", "rm", "gen", "*.c"}, "not a veins repository"); } void history_log_is_topological(test::Context& t) {@@ -1407,6 +1481,7 @@ {"attributes_eol", worktree_attributes_eol}, {"inf_generated", worktree_inf_generated}, {"attributes_command", worktree_attributes_command},+ {"attributes_command_edges", worktree_attributes_command_edges}, {"editor", worktree_editor}, }}, {"history",--- a/xveins/tests/unit_tests.cpp+++ b/xveins/tests/unit_tests.cpp@@ -441,13 +441,12 @@ void test_attributes(test::Context& t) { const TempDir temp;- const std::string rules_text =- "*.c txt eol:lf\n"- "*.cmd txt eol:crlf\n"- "*.ssa gen\n"- "**/generated/* gen\n"- "*.bin gen bin\n"- "special.bin -gen\n";+ const std::string rules_text = "*.c txt eol:lf\n"+ "*.cmd txt eol:crlf\n"+ "*.ssa gen\n"+ "**/generated/* gen\n"+ "*.bin gen bin\n"+ "special.bin -gen\n"; t.expect(write_file(temp.path / ".vnattribs", bytes_of(rules_text))); const AttributeRules rules = AttributeRules::load(temp.path); @@ -482,6 +481,39 @@ t.expect_eq(to_string(bytes_of(crlf)), "a\r\nb\r\nc\r\n"); const auto cr = normalize_eol(bytes_of("a\nb\r\nc\r"), AttributeEol::Cr); t.expect_eq(to_string(bytes_of(cr)), "a\rb\rc\r");+}++void test_attributes_edges(test::Context& t) {+ const TempDir temp;+ const std::string rules_text = "# leading comment\r\n"+ "\r\n"+ "*.c gen\r\n"+ "*.c -gen\r\n"+ "*.h txt\r\n"+ "*.h -bin\r\n"+ "*.log eol:crlf\r\n"+ "*.log -eol\r\n"+ "*.mac eol:cr\r\n"+ "src/*.c gen\r\n"+ "*.dat unknown-token bin\r\n";+ t.expect(write_file(temp.path / ".vnattribs", bytes_of(rules_text)));+ const AttributeRules rules = AttributeRules::load(temp.path);++ t.expect(!rules.lookup("a.c").generated);+ t.expect(rules.lookup("deep/a.c").generated == false);+ t.expect(rules.lookup("a.h").text == AttributeText::Auto);+ t.expect(rules.lookup("a.log").eol == AttributeEol::None);+ t.expect(rules.lookup("a.mac").eol == AttributeEol::Cr);+ t.expect(rules.lookup("src/main.c").generated);+ t.expect(!rules.lookup("nested/src/main.c").generated);+ t.expect(rules.lookup("assets/blob.dat").text == AttributeText::Binary);++ const TempDir empty;+ const AttributeRules none = AttributeRules::load(empty.path);+ const auto plain = none.lookup("anything");+ t.expect(!plain.generated);+ t.expect(plain.text == AttributeText::Auto);+ t.expect(plain.eol == AttributeEol::None); } void test_file_helpers(test::Context& t) {@@ -528,6 +560,7 @@ {"pathspecs", test_pathspecs}, {"ignore_rules", test_ignore_rules}, {"attributes", test_attributes},+ {"attributes_edges", test_attributes_edges}, {"file_helpers", test_file_helpers}, }}, };