version.cmake 2.7 KB
Newer Older
Y
Yu Yang 已提交
1 2 3
# Get the latest git tag.
set(PADDLE_VERSION $ENV{PADDLE_VERSION})
set(tmp_version "HEAD")
M
minqiyang 已提交
4
set(TAG_VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
5
set(COMMIT_VERSION_REGEX "[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+")
6 7
# set(LATEST_PADDLE_VERSION "latest")
set(LATEST_PADDLE_VERSION "0.0.0")
8

Y
Yu Yang 已提交
9
while ("${PADDLE_VERSION}" STREQUAL "")
10
  # Check current branch name
Y
Yu Yang 已提交
11
  execute_process(
12
    COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref ${tmp_version}
13
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
14 15
    OUTPUT_VARIABLE GIT_BRANCH_NAME
    RESULT_VARIABLE GIT_BRANCH_RESULT
Y
Yu Yang 已提交
16
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
17 18 19 20 21 22 23 24 25 26 27 28
  if (NOT ${GIT_BRANCH_RESULT})
    execute_process(
      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 if current branch is release branch
      if (${GIT_BRANCH_NAME} MATCHES "release/${TAG_VERSION_REGEX}")
        # Check the tag is a correct version
        if (${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}")
29 30
          # if no tag was found, set PADDLE_VERSION to "latest"
          set(PADDLE_VERSION "${LATEST_PADDLE_VERSION}")
31 32 33 34 35
        elseif (${GIT_TAG_NAME} MATCHES "v${TAG_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")
        endif()
M
minqiyang 已提交
36
      else()
37 38 39 40 41 42 43 44 45 46 47
        execute_process(
          COMMAND ${GIT_EXECUTABLE} describe --exact-match --tags ${tmp_version}
          WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
          OUTPUT_VARIABLE GIT_EXACT_TAG_NAME
          RESULT_VARIABLE GIT_EXACT_TAG_RESULT
          ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
        if (NOT ${GIT_EXACT_TAG_NAME})
          # Check if current branch is tag branch
          if (${GIT_EXACT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
            string(REPLACE "v" "" PADDLE_VERSION ${GIT_EXACT_TAG_NAME})
          else()
48
            set(PADDLE_VERSION "${LATEST_PADDLE_VERSION}")
49 50
          endif()
        else()
51 52
          # otherwise, we always set PADDLE_VERSION to "latest"
          set(PADDLE_VERSION "${LATEST_PADDLE_VERSION}")
53
        endif()
54 55
      endif()
    else()
56
      set(PADDLE_VERSION "${LATEST_PADDLE_VERSION}")
57
      message(WARNING "Cannot add paddle version from git tag")
Y
Yu Yang 已提交
58 59
    endif()
  else()
60
    set(PADDLE_VERSION "${LATEST_PADDLE_VERSION}")
61
    message(WARNING "Cannot add paddle version for wrong git branch result")
Y
Yu Yang 已提交
62 63 64
  endif()
endwhile()

65
add_definitions(-DPADDLE_VERSION=${PADDLE_VERSION})
Y
Yu Yang 已提交
66
message(STATUS "Paddle version is ${PADDLE_VERSION}")