diff --git a/cmake/version.cmake b/cmake/version.cmake index cde650128a068faf32f4abfff5cdfdeb656d8577..96f2eff6cbfb0b18cbdbbc982583d5b9c71fc25a 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -1,16 +1,21 @@ # Get the latest git tag. set(PADDLE_VERSION $ENV{PADDLE_VERSION}) set(tmp_version "HEAD") +set(TAG_VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?") +set(COMMIT_VERSION_REGEX "[0-9a-f]{5,40}") while ("${PADDLE_VERSION}" STREQUAL "") execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 ${tmp_version} + COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --always ${tmp_version} WORKING_DIRECTORY ${PADDLE_SOURCE_DIR} OUTPUT_VARIABLE GIT_TAG_NAME RESULT_VARIABLE GIT_RESULT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if (NOT ${GIT_RESULT}) # Check the tag is a correct version - if (${GIT_TAG_NAME} MATCHES "v[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?") + if (${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}") + # if no tag was found, set PADDLE_VERSION to latest + set(PADDLE_VERSION "latest") + elseif (${GIT_TAG_NAME} MATCHES "v${VERSION_REGEX}") string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME}) else() # otherwise, get the previous git tag name. set(tmp_version "${GIT_TAG_NAME}~1") diff --git a/python/setup.py.in b/python/setup.py.in index db4c7f044d64980eeac4bde130c2f8ed04459fde..8ea828ce65df64dccd86dcfe5904726c719e5c09 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -23,34 +23,22 @@ def _get_version_detail(idx): assert idx < 3, "vesion info consists of %(major)d.%(minor)d.%(patch)d, \ so detail index must less than 3" - version_details = '@PADDLE_VERSION@'.split('.') - if len(version_details) == 3: - detail = version_details[idx] - if re.match('[0-9]+', detail): - return int(detail) + if re.match('@TAG_VERSION_REGEX@', '@PADDLE_VERSION@'): + version_details = '@PADDLE_VERSION@'.split('.') - return None - -def get_major(): - major = _get_version_detail(0) - if major is not None: - return major + if len(version_details) == 3: + return version_details[idx] return 'UNKNOWN' -def get_minor(): - minor = _get_version_detail(1) - if minor is not None: - return minor +def get_major(): + return _get_version_detail(0) - return 'UNKNOWN' +def get_minor(): + return _get_version_detail(1) def get_patch(): - patch = _get_version_detail(2) - if patch is not None: - return patch - - return 'UNKNOWN' + return _get_version_detail(2) def is_taged(): try: