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.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. INCLUDE_KEYWORD="include/python3.${ver:1:1}"
  73. info=`command -v termux-info || true`
  74. if [[ "${info}" =~ "com.termux" ]]; then
  75. echo "find termux-info at: ${info}"
  76. is_punctuation=${ver:4:1}
  77. INCLUDE_KEYWORD="include/python3.${ver:2:1}"
  78. if [ ${is_punctuation} = "." ]; then
  79. INCLUDE_KEYWORD="include/python3.${ver:2:2}"
  80. fi
  81. fi
  82. PYTHON_API_INCLUDES="include/python3.5 include/python3.6 include/python3.7 include/python3.8 include/python3.9 include/python3.10"
  83. elif [[ $OS =~ "Darwin" ]]; then
  84. is_punctuation=${ver:4:1}
  85. INCLUDE_KEYWORD="include/python3.${ver:2:1}"
  86. if [ ${is_punctuation} = "." ]; then
  87. INCLUDE_KEYWORD="include/python3.${ver:2:2}"
  88. fi
  89. PYTHON_API_INCLUDES="include/python3.5 include/python3.6 include/python3.7 include/python3.8 include/python3.9 include/python3.10"
  90. else
  91. echo "unknown OS: ${OS}"
  92. exit -1
  93. fi
  94. else
  95. echo "err call check_build_ninja_python_api"
  96. exit -1
  97. fi
  98. echo "try check python INCLUDE_KEYWORD: ${INCLUDE_KEYWORD} is invalid in ninja.build or not"
  99. NINJA_BUILD=`cat build.ninja`
  100. for PYTHON_API_INCLUDE in ${PYTHON_API_INCLUDES}
  101. do
  102. echo "check PYTHON_API_INCLUDE vs INCLUDE_KEYWORD : (${PYTHON_API_INCLUDE} : ${INCLUDE_KEYWORD})"
  103. if [ ${PYTHON_API_INCLUDE} = ${INCLUDE_KEYWORD} ]; then
  104. if [[ "${NINJA_BUILD}" =~ ${PYTHON_API_INCLUDE} ]]; then
  105. echo "hit INCLUDE_KEYWORD: ${INCLUDE_KEYWORD} in build.ninja"
  106. IS_MINOR_HIT="TRUE"
  107. else
  108. echo "Err happened can not find INCLUDE_KEYWORD: ${INCLUDE_KEYWORD} in build.ninja"
  109. exit -1
  110. fi
  111. else
  112. if [[ "${NINJA_BUILD}" =~ ${PYTHON_API_INCLUDE} ]]; then
  113. echo "Err happened: find PYTHON_API_INCLUDE: ${PYTHON_API_INCLUDE} in build.ninja"
  114. echo "But now INCLUDE_KEYWORD: ${INCLUDE_KEYWORD}"
  115. exit -1
  116. fi
  117. fi
  118. done
  119. if [ ${IS_MINOR_HIT} = "FALSE" ]; then
  120. echo "Err happened, can not hit any MINOR api in ninja.build"
  121. exit -1
  122. fi
  123. }
  124. function check_python_version_is_valid() {
  125. want_build_version=$1
  126. support_version=$2
  127. if [ $# -eq 2 ]; then
  128. ver=$1
  129. else
  130. echo "err call check_python_version_is_valid"
  131. exit -1
  132. fi
  133. for i_want_build_version in ${want_build_version}
  134. do
  135. is_valid="false"
  136. for i_support_version in ${support_version}
  137. do
  138. if [ ${i_want_build_version} == ${i_support_version} ];then
  139. is_valid="true"
  140. fi
  141. done
  142. if [ ${is_valid} == "false" ];then
  143. echo "invalid build python version : \"${want_build_version}\", now support party of \"${support_version}\""
  144. exit -1
  145. fi
  146. done
  147. }