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")

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

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