-
Notifications
You must be signed in to change notification settings - Fork 79
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
Populate the version based on Git Describe #15400
Open
afuller-TT
wants to merge
2
commits into
main
Choose a base branch
from
afuller/versioning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−3
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
/cmake/version.cmake export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# SPDX-FileCopyrightText: © 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# May be called prior to project() | ||
function(ParseGitDescribe) | ||
set(version "") | ||
# These will be filled in by `git archive`. | ||
# Building the source outside of git from something that was not exported via `git archive` | ||
# is left as an exercise to whoever is wanting to do that. | ||
set(fallbackVersion "$Format:%(describe)$") | ||
set(fallbackHash "$Format:%h$") | ||
|
||
find_package(Git) | ||
if(Git_FOUND) | ||
execute_process( | ||
COMMAND | ||
${GIT_EXECUTABLE} describe --abbrev=10 --first-parent --dirty=-dirty | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE version | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
execute_process( | ||
COMMAND | ||
${GIT_EXECUTABLE} rev-parse --short=10 HEAD | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE VERSION_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
) | ||
endif() | ||
if(NOT version) | ||
set(version ${fallbackVersion}) | ||
set(VERSION_HASH ${fallbackHash}) | ||
endif() | ||
|
||
# Local modifications (dirty), or not | ||
set(dirtyFlagRegex "\\-dirty") | ||
set(VERSION_DIRTY FALSE) | ||
if("${version}" MATCHES "${dirtyFlagRegex}$") | ||
set(VERSION_DIRTY TRUE) | ||
string(REGEX REPLACE "^(.*)${dirtyFlagRegex}$" "\\1" version "${version}") | ||
endif() | ||
|
||
# On a Tagged commit, or not | ||
set(untaggedRegex "^(.*)\\-([0-9]+)\\-g([0-9a-f]+)$") # tag-count-ghash | ||
if("${version}" MATCHES "${untaggedRegex}") | ||
set(VERSION_TAGGED FALSE) | ||
string(REGEX REPLACE "${untaggedRegex}" "\\1" tagname "${version}") | ||
string(REGEX REPLACE "${untaggedRegex}" "\\2" VERSION_COMMIT_COUNT "${version}") | ||
else() | ||
set(VERSION_TAGGED TRUE) | ||
set(tagname "${version}") | ||
endif() | ||
|
||
set(major "([0-9]+)") | ||
set(segment "\\.[0-9]+") | ||
set(status "\\-([a-zA-Z]+[0-9]+)") # eg: alpha, beta, RC | ||
set(tagRegex "^[^0-9]*(${major}(${segment}(${segment}(${segment})?)?)?)(${status})?$") | ||
if(NOT "${tagname}" MATCHES "${tagRegex}") | ||
message(WARNING "Cannot parse tag ${tagname}") | ||
return() | ||
endif() | ||
|
||
# Major[.Minor[.Patch[.Tweak]]] suitable for CMake | ||
string(REGEX REPLACE "${tagRegex}" "\\1" VERSION_NUMERIC "${tagname}") | ||
|
||
# Build a new regex because we cannot access a capture group that was not matched. | ||
# And also only the first 9 capture groups are referencable. | ||
set(statusRegex ".*(${status})$") | ||
if("${tagname}" MATCHES "${statusRegex}") | ||
string(REGEX REPLACE "${statusRegex}" "\\2" VERSION_STATUS "${tagname}") | ||
endif() | ||
|
||
set(VERSION_FULL "${VERSION_NUMERIC}") | ||
if(VERSION_STATUS) | ||
string(APPEND VERSION_FULL "-${VERSION_STATUS}") | ||
endif() | ||
if(VERSION_COMMIT_COUNT) | ||
string(APPEND VERSION_FULL "+${VERSION_COMMIT_COUNT}.${VERSION_HASH}") | ||
endif() | ||
if(VERSION_DIRTY) | ||
string(APPEND VERSION_FULL "+m") | ||
endif() | ||
|
||
message(STATUS "Version: ${VERSION_FULL}") | ||
|
||
# Output variables | ||
set(VERSION_FULL "${VERSION_FULL}" PARENT_SCOPE) | ||
set(VERSION_NUMERIC "${VERSION_NUMERIC}" PARENT_SCOPE) | ||
endfunction() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's what this file looks like after it get tarball'd: