build_linux.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) Contributors to the Open 3D Engine Project.
  4. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. #
  6. # SPDX-License-Identifier: Apache-2.0 OR MIT
  7. #
  8. #
  9. set -o errexit # exit on the first failure encountered
  10. BASEDIR=$(dirname "$0")
  11. source $BASEDIR/env_linux.sh
  12. mkdir -p ${OUTPUT_DIRECTORY}
  13. SOURCE_DIRECTORY=${PWD}
  14. pushd $OUTPUT_DIRECTORY
  15. LAST_CONFIGURE_CMD_FILE=ci_last_configure_cmd.txt
  16. CONFIGURE_CMD="cmake '${SOURCE_DIRECTORY}' ${CMAKE_OPTIONS} ${EXTRA_CMAKE_OPTIONS}"
  17. if [[ -n "$CMAKE_LY_PROJECTS" ]]; then
  18. CONFIGURE_CMD="${CONFIGURE_CMD} -DLY_PROJECTS='${CMAKE_LY_PROJECTS}'"
  19. fi
  20. if [[ ! -e "CMakeCache.txt" ]]; then
  21. echo [ci_build] First run, generating
  22. RUN_CONFIGURE=1
  23. elif [[ ! -e ${LAST_CONFIGURE_CMD_FILE} ]]; then
  24. echo [ci_build] Last run command not found, generating
  25. RUN_CONFIGURE=1
  26. else
  27. # Detect if the input has changed
  28. LAST_CMD=$(<${LAST_CONFIGURE_CMD_FILE})
  29. if [[ "${LAST_CMD}" != "${CONFIGURE_CMD}" ]]; then
  30. echo [ci_build] Last run command different, generating
  31. RUN_CONFIGURE=1
  32. fi
  33. fi
  34. if [[ ! -z "$RUN_CONFIGURE" ]]; then
  35. # have to use eval since $CMAKE_OPTIONS (${EXTRA_CMAKE_OPTIONS}) contains quotes that need to be processed
  36. eval echo [ci_build] ${CONFIGURE_CMD}
  37. eval ${CONFIGURE_CMD}
  38. # Save the run only if success
  39. echo "${CONFIGURE_CMD}" > ${LAST_CONFIGURE_CMD_FILE}
  40. fi
  41. TOTAL_MEMORY=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
  42. TOTAL_CORE_COUNT=$(grep -c processor /proc/cpuinfo)
  43. echo "Total Memory : $TOTAL_MEMORY kB"
  44. echo "Total Cores : $TOTAL_CORE_COUNT"
  45. # For machines that has a core to memory ratio that could cause running out of resources,
  46. # we will check for an environment variable LY_MIN_MEMORY_PER_CORE to restrict the number
  47. # of cores that we will allow. If set, it will use this as the minimum anticipated memory
  48. # that all cores will need in order to no fall below that number.
  49. #
  50. # This is based on the value the total memory (in kB) divided by the LY_MIN_MEMORY_PER_CORE
  51. # (in kB, e.g. 2 GB = 2097152 kB)
  52. if [[ "${LY_MIN_MEMORY_PER_CORE:-0}" -gt 0 ]]; then
  53. MIN_MEMORY_PER_CORE=${LY_MIN_MEMORY_PER_CORE}
  54. CALCULATED_MAX_CORE_USAGE=$(expr $TOTAL_MEMORY / $MIN_MEMORY_PER_CORE - 1)
  55. CORE_COUNT=$((CALCULATED_MAX_CORE_USAGE > TOTAL_CORE_COUNT ? TOTAL_CORE_COUNT : CALCULATED_MAX_CORE_USAGE))
  56. echo "Max Usable Cores : $CORE_COUNT"
  57. else
  58. CORE_COUNT=$TOTAL_CORE_COUNT
  59. fi
  60. # Split the configuration on semi-colon and use the cmake --build wrapper to run the underlying build command for each
  61. for config in $(echo $CONFIGURATION | sed "s/;/ /g")
  62. do
  63. eval echo [ci_build] cmake --build . --target ${CMAKE_TARGET} --config ${config} -j $CORE_COUNT -- ${CMAKE_NATIVE_BUILD_ARGS}
  64. eval cmake --build . --target ${CMAKE_TARGET} --config ${config} -j $CORE_COUNT -- ${CMAKE_NATIVE_BUILD_ARGS}
  65. done
  66. popd