Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cable: external git info #1067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Documentation of all notable changes to the **evmone** project.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## [0.14.0] — 2024-XX-XX

### Added

- cable: external git info
[#1067](https://github.com/ethereum/evmone/pull/1067)

## [0.13.0] — 2024-09-23

This release adds BLS precompiles and a system contract for [Prague]
Expand Down
15 changes: 13 additions & 2 deletions cmake/cable/CableBuildInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ include(GNUInstallDirs)
set(cable_buildinfo_template_dir ${CMAKE_CURRENT_LIST_DIR}/buildinfo)

function(cable_add_buildinfo_library)

cmake_parse_arguments("" "" PROJECT_NAME;EXPORT "" ${ARGN})
set(
ARG_NAMES
PROJECT_NAME
EXPORT
GIT_DESCRIBE
GIT_BRANCH
GIT_ORIGIN_URL
)
cmake_parse_arguments(PARSE_ARGV 0 "" "" "${ARG_NAMES}" "")

if(NOT _PROJECT_NAME)
message(FATAL_ERROR "The PROJECT_NAME argument missing")
Expand Down Expand Up @@ -55,10 +62,14 @@ function(cable_add_buildinfo_library)
${name}-git
COMMAND ${CMAKE_COMMAND}
-DGIT=${GIT_EXECUTABLE}
-DGIT_DESCRIBE=${_GIT_DESCRIBE}
-DGIT_BRANCH=${_GIT_BRANCH}
-DGIT_ORIGIN_URL=${_GIT_ORIGIN_URL}
-DSOURCE_DIR=${PROJECT_SOURCE_DIR}
-DOUTPUT_DIR=${output_dir}
-P ${cable_buildinfo_template_dir}/gitinfo.cmake
BYPRODUCTS ${output_dir}/gitinfo.txt
COMMENT "CableBuildInfo: updating gitinfo.txt"
)

add_custom_command(
Expand Down
74 changes: 42 additions & 32 deletions cmake/cable/buildinfo/gitinfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,55 @@

# Execute git only if the tool is available.
if(GIT)
execute_process(
COMMAND ${GIT} describe --always --long --tags --first-parent --match=v* --abbrev=40 --dirty
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitinfo
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
if (GIT_DESCRIBE)
set(gitdescribe "${GIT_DESCRIBE}")
else()
execute_process(
COMMAND ${GIT} describe --always --long --tags --first-parent --match=v* --abbrev=40 --dirty
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitdescribe
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
endif()
endif()

execute_process(
COMMAND ${GIT} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitbranch
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
if (GIT_BRANCH)
set(gitbranch "${GIT_BRANCH}")
else()
set(gitinfo "${gitinfo}\n${gitbranch}")
execute_process(
COMMAND ${GIT} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitbranch
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
endif()
endif()

execute_process(
COMMAND ${GIT} config --get remote.origin.url
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitorigin
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
if (GIT_ORIGIN_URL)
set(gitorigin "${GIT_ORIGIN_URL}")
else()
set(gitinfo "${gitinfo}\n${gitorigin}\n")
execute_process(
COMMAND ${GIT} config --get remote.origin.url
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE gitorigin
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE error
ERROR_STRIP_TRAILING_WHITESPACE
)
if(error)
message(WARNING "Git ${error}")
endif()
endif()

set(gitinfo "${gitdescribe}\n${gitbranch}\n${gitorigin}\n")
endif()

set(gitinfo_file ${OUTPUT_DIR}/gitinfo.txt)
Expand Down