You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.sh 6.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/env bash
  2. set -e
  3. OS=$(uname -s)
  4. docker_file=""
  5. function config_docker_file() {
  6. case $(uname -m) in
  7. x86_64) docker_file=Dockerfile ;;
  8. aarch64) docker_file=Dockerfile_aarch64 ;;
  9. *) echo "nonsupport env!!!";exit -1 ;;
  10. esac
  11. }
  12. function ninja_dry_run_and_check_increment() {
  13. echo "into ninja_dry_run_and_check_increment"
  14. if [ $# -eq 3 ]; then
  15. _BUILD_SHELL=$1
  16. _BUILD_FLAGS="$2 -n"
  17. _INCREMENT_KEY_WORDS=$3
  18. else
  19. echo "err call ninja_dry_run_and_check_increment"
  20. exit -1
  21. fi
  22. bash ${_BUILD_SHELL} ${_BUILD_FLAGS} 2>&1 | tee dry_run.log
  23. DIRTY_LOG=`cat dry_run.log`
  24. if [[ "${DIRTY_LOG}" =~ ${_INCREMENT_KEY_WORDS} ]]; then
  25. echo "DIRTY_LOG is:"
  26. echo ${DIRTY_LOG}
  27. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  28. echo "python3 switch increment build failed, some MR make a wrong CMakeLists.txt depends"
  29. echo "or build env can not find default python3 in PATH env"
  30. echo "please refs for PYTHON3_EXECUTABLE_WITHOUT_VERSION define at SRC_ROOT/CMakeLists.txt"
  31. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  32. exit -1
  33. fi
  34. CHECK_NINJA_DRY_ISSUE_KEY_WORDS="VerifyGlobs"
  35. if [[ "${DIRTY_LOG}" =~ ${CHECK_NINJA_DRY_ISSUE_KEY_WORDS} ]]; then
  36. echo "DIRTY_LOG is:"
  37. echo ${DIRTY_LOG}
  38. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  39. echo "python3 switch increment build failed, some MR make a wrong CMakeLists.txt"
  40. echo "for example use GLOB with CONFIGURE_DEPENDS flag may lead to ninja dry run failed"
  41. echo "about CONFIGURE_DEPENDS (please do not use it):"
  42. echo "a: we use scripts/cmake-build/*.sh to trigger rerun cmake, so no need CONFIGURE_DEPENDS"
  43. echo "b: as https://cmake.org/cmake/help/latest/command/file.html Note"
  44. echo " CONFIGURE_DEPENDS do not support for all generators"
  45. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  46. exit -1
  47. fi
  48. # as python3 change, imperative src need rebuild, force check it!
  49. MUST_INCLUDE_KEY_WORDS="imperative"
  50. if [[ "${DIRTY_LOG}" =~ ${MUST_INCLUDE_KEY_WORDS} ]]; then
  51. echo "valid increment dry run log"
  52. else
  53. echo "DIRTY_LOG is:"
  54. echo ${DIRTY_LOG}
  55. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  56. echo "python3 switch increment build failed, some MR make a wrong CMakeLists.txt depends"
  57. echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  58. exit -1
  59. fi
  60. }
  61. PYTHON_API_INCLUDES=""
  62. function check_build_ninja_python_api() {
  63. INCLUDE_KEYWORD=""
  64. IS_MINOR_HIT=FALSE
  65. if [ $# -eq 1 ]; then
  66. ver=$1
  67. echo "org args: ${ver}"
  68. if [[ $OS =~ "NT" ]]; then
  69. INCLUDE_KEYWORD="${ver}\\\\include"
  70. PYTHON_API_INCLUDES="3.6.8\\\\include 3.7.7\\\\include 3.8.3\\\\include 3.9.4\\\\include 3.10.1\\\\include"
  71. elif [[ $OS =~ "Linux" ]]; then
  72. ver=`echo $ver | tr -d m`
  73. INCLUDE_KEYWORD="include/python3.${ver:1}" # like 39/310
  74. info=`command -v termux-info || true`
  75. if [[ "${info}" =~ "com.termux" ]]; then
  76. echo "find termux-info at: ${info}"
  77. is_punctuation=${ver:4:1}
  78. INCLUDE_KEYWORD="include/python3.${ver:2:1}"
  79. if [ ${is_punctuation} = "." ]; then
  80. INCLUDE_KEYWORD="include/python3.${ver:2:2}"
  81. fi
  82. fi
  83. PYTHON_API_INCLUDES="include/python3.5 include/python3.6 include/python3.7 include/python3.8 include/python3.9 include/python3.10"
  84. elif [[ $OS =~ "Darwin" ]]; then
  85. is_punctuation=${ver:4:1}
  86. INCLUDE_KEYWORD="include/python3.${ver:2:1}"
  87. if [ ${is_punctuation} = "." ]; then
  88. INCLUDE_KEYWORD="include/python3.${ver:2:2}"
  89. fi
  90. PYTHON_API_INCLUDES="include/python3.5 include/python3.6 include/python3.7 include/python3.8 include/python3.9 include/python3.10"
  91. else
  92. echo "unknown OS: ${OS}"
  93. exit -1
  94. fi
  95. else
  96. echo "err call check_build_ninja_python_api"
  97. exit -1
  98. fi
  99. echo "try check python INCLUDE_KEYWORD: ${INCLUDE_KEYWORD} is invalid in ninja.build or not"
  100. NINJA_BUILD=`cat build.ninja`
  101. for PYTHON_API_INCLUDE in ${PYTHON_API_INCLUDES}
  102. do
  103. echo "check PYTHON_API_INCLUDE vs INCLUDE_KEYWORD : (${PYTHON_API_INCLUDE} : ${INCLUDE_KEYWORD})"
  104. if [ ${PYTHON_API_INCLUDE} = ${INCLUDE_KEYWORD} ]; then
  105. if [[ "${NINJA_BUILD}" =~ ${PYTHON_API_INCLUDE} ]]; then
  106. echo "hit INCLUDE_KEYWORD: ${INCLUDE_KEYWORD} in build.ninja"
  107. IS_MINOR_HIT="TRUE"
  108. else
  109. echo "Err happened can not find INCLUDE_KEYWORD: ${INCLUDE_KEYWORD} in build.ninja"
  110. exit -1
  111. fi
  112. else
  113. if [[ "${NINJA_BUILD}" =~ ${PYTHON_API_INCLUDE} ]]; then
  114. echo "Err happened: find PYTHON_API_INCLUDE: ${PYTHON_API_INCLUDE} in build.ninja"
  115. echo "But now INCLUDE_KEYWORD: ${INCLUDE_KEYWORD}"
  116. exit -1
  117. fi
  118. fi
  119. done
  120. if [ ${IS_MINOR_HIT} = "FALSE" ]; then
  121. echo "Err happened, can not hit any MINOR api in ninja.build"
  122. exit -1
  123. fi
  124. }
  125. function check_python_version_is_valid() {
  126. want_build_version=$1
  127. support_version=$2
  128. if [ $# -eq 2 ]; then
  129. ver=$1
  130. else
  131. echo "err call check_python_version_is_valid"
  132. exit -1
  133. fi
  134. for i_want_build_version in ${want_build_version}
  135. do
  136. is_valid="false"
  137. for i_support_version in ${support_version}
  138. do
  139. if [ ${i_want_build_version} == ${i_support_version} ];then
  140. is_valid="true"
  141. fi
  142. done
  143. if [ ${is_valid} == "false" ];then
  144. echo "invalid build python version : \"${want_build_version}\", now support party of \"${support_version}\""
  145. exit -1
  146. fi
  147. done
  148. }