Mentions légales du service

Skip to content
Snippets Groups Projects
Forked from aevol / aevol
3056 commits behind the upstream repository.
  • Théotime Grohens's avatar
    ee8f2200
    [aevol] Print compile commit branch, hash and date · ee8f2200
    Théotime Grohens authored
    This commit adds the ability to get the branch, date and hash of the
    commit that was used to compile Aevol from within the C++ source of Aevol.
    
    This is useful because it allows us to print it (for example) at the
    beginning of the execution of one of the Aevol programs, making it
    easier to see whether we're running the right version.
    
    In order to do this, a special file `aevol_version.cpp.in` is introduced.
    This file is modified by CMake a first time at configure time, replacing
    a placeholder with the value of the PROJECT_VERSION CMake variable, and
    a second time at compile time, replacing a placeholder with a custom
    CMake variable that holds the branch, hash and date.
    
    This turns the file into a regular C++ source file, that is then compiled
    and linked with the rest of Aevol through the `aevol_version.h` header.
    
    Finally, we print this string in the two most commonly used Aevol
    executables, `aevol_create` and `aevol_run`.
    ee8f2200
    History
    [aevol] Print compile commit branch, hash and date
    Théotime Grohens authored
    This commit adds the ability to get the branch, date and hash of the
    commit that was used to compile Aevol from within the C++ source of Aevol.
    
    This is useful because it allows us to print it (for example) at the
    beginning of the execution of one of the Aevol programs, making it
    easier to see whether we're running the right version.
    
    In order to do this, a special file `aevol_version.cpp.in` is introduced.
    This file is modified by CMake a first time at configure time, replacing
    a placeholder with the value of the PROJECT_VERSION CMake variable, and
    a second time at compile time, replacing a placeholder with a custom
    CMake variable that holds the branch, hash and date.
    
    This turns the file into a regular C++ source file, that is then compiled
    and linked with the rest of Aevol through the `aevol_version.h` header.
    
    Finally, we print this string in the two most commonly used Aevol
    executables, `aevol_create` and `aevol_run`.
aevol_version.cmake 1.40 KiB
set(AEVOL_REVISION "unknown")

if(EXISTS ${AEVOL_SOURCE_DIR}/.git)
    execute_process(COMMAND git rev-parse --short HEAD
        WORKING_DIRECTORY ${AEVOL_SOURCE_DIR}
        OUTPUT_VARIABLE AEVOL_REVISION_HASH
        OUTPUT_STRIP_TRAILING_WHITESPACE)

    execute_process(COMMAND
        git status -s ${AEVOL_SOURCE_DIR}
        WORKING_DIRECTORY ${AEVOL_SOURCE_DIR}
        OUTPUT_VARIABLE AEVOL_SOURCE_MODIFIED
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(NOT AEVOL_SOURCE_MODIFIED STREQUAL "")
        set(AEVOL_REVISION_HASH "${AEVOL_REVISION_HASH}-dirty")
    endif()

    execute_process(COMMAND git rev-parse --abbrev-ref HEAD
        WORKING_DIRECTORY ${AEVOL_SOURCE_DIR}
        OUTPUT_VARIABLE AEVOL_BRANCH_NAME
        OUTPUT_STRIP_TRAILING_WHITESPACE)

    execute_process(COMMAND git log -n 1 --pretty=%cD #--date=short
        WORKING_DIRECTORY ${AEVOL_SOURCE_DIR}
        OUTPUT_VARIABLE AEVOL_REVISION_DATE
        OUTPUT_STRIP_TRAILING_WHITESPACE)

    # If we wanted to use the compile date instead
    # However, this makes the build non-reproducible
    #string(TIMESTAMP AEVOL_COMPILE_DATE "%Y-%m-%d %H:%M:%S")

    set(AEVOL_REVISION "${AEVOL_BRANCH_NAME}, ${AEVOL_REVISION_HASH}, ${AEVOL_REVISION_DATE}")

endif()

if(NOT "${AEVOL_BINARY_DIR}" STREQUAL "")
    configure_file(${AEVOL_BINARY_DIR}/src/libaevol/aevol_version.cpp.in
        ${AEVOL_BINARY_DIR}/src/libaevol/aevol_version.cpp)
endif()