get_python.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. SOURCE="${BASH_SOURCE[0]}"
  8. # While $SOURCE is a symlink, resolve it
  9. while [ -h "$SOURCE" ]; do
  10. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  11. SOURCE="$( readlink "$SOURCE" )"
  12. # If $SOURCE was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory
  13. [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
  14. done
  15. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  16. cd $DIR
  17. install_dependencies () {
  18. echo installing via pip...
  19. $DIR/pip.sh install -r $DIR/requirements.txt --disable-pip-version-check --no-warn-script-location
  20. retVal=$?
  21. if [ $retVal -ne 0 ]; then
  22. echo "Failed to install the packages listed in $DIR/requirements.txt. Check the log above!"
  23. return $retVal
  24. fi
  25. # If we're building a container app, create a package from o3de then install that to remove absolute paths to o3de scripts
  26. if [ "$O3DE_PACKAGE_TYPE" == "SNAP" ]; then
  27. pushd $DIR/../scripts/o3de/
  28. $DIR/python.sh setup.py sdist
  29. popd
  30. fi
  31. # If the dist package is detected (result of a built container app), run the install of the o3de script library from the
  32. # dist package so that the egg-link file will not be created inside the o3de script folder
  33. if [ -f $DIR/../scripts/o3de/dist/o3de-1.0.0.tar.gz ]; then
  34. $DIR/pip.sh install $DIR/../scripts/o3de/dist/o3de-1.0.0.tar.gz --no-deps --disable-pip-version-check --no-cache
  35. else
  36. $DIR/pip.sh install -e $DIR/../scripts/o3de --no-deps --disable-pip-version-check --no-warn-script-location
  37. fi
  38. retVal=$?
  39. if [ $retVal -ne 0 ]; then
  40. echo "Failed to install $DIR/../scripts/o3de into python. Check the log above!"
  41. return $retVal
  42. fi
  43. }
  44. # Overall strategy: Run python with --version to see if its already there
  45. # otherwise, use cmake and the new package system to download it.
  46. # To find cmake, search the path for cmake. If not found, try a fixed known location.
  47. # the version number below is only used if cmake isn't already on your path.
  48. # if you update this version number, remember to update the one(s) in the other platform
  49. # files, as well as in scripts/build/...
  50. ./python.sh --version > /dev/null
  51. python_exitcode=$?
  52. if [ $python_exitcode == 0 ]; then
  53. echo get_python.sh: Python is already downloaded: $(./python.sh --version)
  54. install_dependencies
  55. exit $?
  56. fi
  57. if [[ "$OSTYPE" = *"darwin"* ]];
  58. then
  59. PAL=Mac
  60. CMAKE_FOLDER_RELATIVE_TO_ROOT=CMake.app/Contents/bin
  61. else
  62. PAL=Linux
  63. CMAKE_FOLDER_RELATIVE_TO_ROOT=bin
  64. LINUX_HOST_ARCHITECTURE=$( uname -m )
  65. if [[ "$LINUX_HOST_ARCHITECTURE" == "aarch64" ]]; then
  66. PAL_ARCH="_aarch64"
  67. elif [[ "$LINUX_HOST_ARCHITECTURE" == "x86_64" ]]; then
  68. PAL_ARCH="_x86_64"
  69. else
  70. echo "Linux host architecture ${LINUX_HOST_ARCHITECTURE} not supported."
  71. exit 1
  72. fi
  73. fi
  74. if ! [ -x "$(command -v cmake)" ]; then
  75. if [ -z ${LY_CMAKE_PATH} ]; then
  76. echo "ERROR: Could not find cmake on the PATH and LY_CMAKE_PATH is not defined, cannot continue."
  77. echo "Please add cmake to your PATH, or define LY_CMAKE_PATH"
  78. exit 1
  79. fi
  80. export PATH=$LY_CMAKE_PATH:$PATH
  81. if ! [ -x "$(command -v cmake)" ]; then
  82. echo "ERROR: Could not find cmake on the PATH or at the known location: $LY_CMAKE_PATH"
  83. echo "Please add cmake to the environment PATH or place it at the above known location."
  84. exit 1
  85. fi
  86. fi
  87. echo Using cmake located at: $(which cmake)
  88. echo $(cmake --version)
  89. cd ..
  90. if [ "$LY_3RDPARTY_PATH" == "" ]
  91. then
  92. LY_3RDPARTY_PATH=$HOME/.o3de/3rdParty
  93. fi
  94. LY_ROOT_FOLDER=$DIR/..
  95. cmake -DPAL_PLATFORM_NAME:string=$PAL -DLY_3RDPARTY_PATH:string=$LY_3RDPARTY_PATH -DLY_ROOT_FOLDER="$LY_ROOT_FOLDER" -DLY_HOST_ARCHITECTURE_NAME_EXTENSION=$PAL_ARCH -P $DIR/get_python.cmake
  96. retVal=$?
  97. if [ $retVal -ne 0 ]; then
  98. echo Unable to fetch python using cmake.
  99. echo - Is LY_PACKAGE_SERVER_URLS set?
  100. echo - Do you have permission to access the packages?
  101. exit $retVal
  102. fi
  103. install_dependencies
  104. exit $?