docker_build_linux.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. # Validate the bld path input
  7. BUILD_FOLDER=${DOCKER_BUILD_PATH}
  8. if [ "${BUILD_FOLDER}" == "" ]
  9. then
  10. echo "Missing required build target folder environment"
  11. exit 1
  12. elif [ "${BUILD_FOLDER}" == "temp" ]
  13. then
  14. echo "Build target folder environment cannot be 'temp'"
  15. exit 1
  16. fi
  17. # Copy the source folder from the read-only $WORKSPACE/temp/src to $WORKSPACE/src
  18. # since the build process will write/modify the source path
  19. SRC_PATH=$WORKSPACE/src
  20. echo "Preparing source folder '${SRC_PATH}'"
  21. cp -r $WORKSPACE/temp/src ${SRC_PATH}
  22. # The dependent 'depends_on_packages' paths are architecture dependent
  23. if [ "$(uname -m)" = "x86_64" ]
  24. then
  25. O3DE_OPENSSL_PACKAGE=OpenSSL-1.1.1t-rev1-linux
  26. O3DE_SQLITE_PACKAGE=SQLite-3.37.2-rev1-linux
  27. else
  28. O3DE_OPENSSL_PACKAGE=OpenSSL-1.1.1t-rev1-linux-aarch64
  29. O3DE_SQLITE_PACKAGE=SQLite-3.37.2-rev1-linux-aarch64
  30. fi
  31. # Prepare the dependent O3DE package information for OpenSSL
  32. OPENSSL_BASE=$WORKSPACE/temp/${O3DE_OPENSSL_PACKAGE}/OpenSSL
  33. echo "Using O3DE OpenSSL package from ${O3DE_OPENSSL_PACKAGE}"
  34. # Prepare the dependent O3DE package information for SQLite
  35. SQLITE_BASE=$WORKSPACE/temp/${O3DE_SQLITE_PACKAGE}/SQLite
  36. echo "Using O3DE SQLite3 package from ${SQLITE_BASE}"
  37. # Prepare the dependent libffi package from github to use
  38. LIBFFI_VERSION="v3.4.2"
  39. LIBFFI_GIT_URL="https://github.com/libffi/libffi.git"
  40. LIBFFI_SRC=ffi_src
  41. LIBFFI_SRC_PATH=${WORKSPACE}/${LIBFFI_SRC}
  42. LIBFFI_LIB_PATH=${WORKSPACE}/ffi_lib
  43. echo "Clone and build libFFI statically from ${FFI_GIT_URL} / ${LIBFFI_VERSION}"
  44. CMD="git -C ${WORKSPACE} clone ${LIBFFI_GIT_URL} --branch ${LIBFFI_VERSION} --depth 1 ${LIBFFI_SRC}"
  45. echo $CMD
  46. eval $CMD
  47. if [ $? -ne 0 ]
  48. then
  49. echo "Failed cloning libffi from ${LIBFFI_GIT_URL}"
  50. exit 1
  51. fi
  52. pushd ${LIBFFI_SRC_PATH}
  53. CMD="./autogen.sh"
  54. echo $CMD
  55. eval $CMD
  56. if [ $? -ne 0 ]
  57. then
  58. echo "'autogen' failed for libffi at ${LIBFFI_SRC_PATH}"
  59. exit 1
  60. fi
  61. CMD="./configure --prefix=$LIBFFI_LIB --enable-shared=no CFLAGS='-fPIC' CPPFLAGS='-fPIC' "
  62. echo $CMD
  63. eval $CMD
  64. if [ $? -ne 0 ]
  65. then
  66. echo "'configure' failed for libffi at ${LIBFFI_SRC_PATH}"
  67. exit 1
  68. fi
  69. CMD="make install"
  70. echo $CMD
  71. eval $CMD
  72. if [ $? -ne 0 ]
  73. then
  74. echo "'configure' failed for libffi at ${LIBFFI_SRC_PATH}"
  75. exit 1
  76. fi
  77. popd
  78. # Build CPython from source
  79. echo "Building cpython from source ..."
  80. echo ""
  81. pushd ${SRC_PATH}
  82. # Build from the source with optimizations and shared libs enabled , and override the RPATH and bzip include/lib paths
  83. ./configure --prefix=${BUILD_FOLDER}/python\
  84. --enable-optimizations\
  85. --with-openssl=${OPENSSL_BASE}\
  86. --enable-shared LDFLAGS='-Wl,-rpath=\$$ORIGIN:\$$ORIGIN/../lib:\$$ORIGIN/../.. -L../ffi_lib/lib -L'${SQLITE_BASE}'/lib'\
  87. CPPFLAGS='-I../ffi_lib/include -I'${SQLITE_BASE}'' CFLAGS='-I../ffi_lib/include -I'${SQLITE_BASE}''
  88. if [ $? -ne 0 ]
  89. then
  90. echo "'configure' failed for cpython at ${SRC_PATH}"
  91. exit 1
  92. fi
  93. CMD="make"
  94. echo $CMD
  95. eval $CMD
  96. if [ $? -ne 0 ]
  97. then
  98. echo "'make' failed for cpython at ${SRC_PATH}"
  99. exit 1
  100. fi
  101. CMD="make install"
  102. echo $CMD
  103. eval $CMD
  104. if [ $? -ne 0 ]
  105. then
  106. echo "'make install' failed for cpython at ${SRC_PATH}"
  107. exit 1
  108. fi
  109. popd
  110. echo "Preparing additional python files"
  111. # Copy the python license
  112. cp ${SRC_PATH}/LICENSE ${BUILD_FOLDER}/python/LICENSE
  113. # Also copy the openssl license since its linked against the dependent O3DE OpenSSL static package
  114. cp ${OPENSSL_BASE}/LICENSE ${BUILD_FOLDER}/python/LICENSE.OPENSSL
  115. # Create a symlink from python -> python3
  116. pushd ${BUILD_FOLDER}/python/bin
  117. ln -s python3 python
  118. popd
  119. pushd ${BUILD_FOLDER}
  120. echo "Upgrading pip"
  121. # the pip that may come from the above repo can be broken, so we'll use get-pip
  122. # and then upgrade it.
  123. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  124. ./python/bin/python3 get-pip.py
  125. rm get-pip.py
  126. pushd python/bin
  127. PYTHONNOUSERSITE=1 ./python3 -m pip install --upgrade pip
  128. echo "Upgrading setup tools"
  129. # Update setup tools to resolve https://avd.aquasec.com/nvd/cve-2022-40897
  130. PYTHONNOUSERSITE=1 ./python3 -m pip install setuptools --upgrade setuptools
  131. # Update wheel to resolve https://avd.aquasec.com/nvd/2022/cve-2022-40898/
  132. PYTHONNOUSERSITE=1 ./python3 -m pip install wheel --upgrade wheel
  133. popd #python/bin
  134. # installing pip causes it to put absolute paths to python
  135. # in the pip files (in bin). For example, pip will have
  136. # a line at the top that starts with #!/full/path/to/python
  137. # so we fix those up too.
  138. # We want to change it from and absolute path to python
  139. # to a multi-line #! that runs python from the same folder as the file is being called from:
  140. #!/bin/sh
  141. #"exec" "`dirname $0`/python" "$0" "$@"
  142. sed -i "1s+.*+\#\!/bin/sh+" ./python/bin/pip*
  143. sed -i "2i\\
  144. \"exec\" \"\`dirname \$0\`/python\" \"\$0\" \"\$\@\" " ./python/bin/pip*
  145. popd # ${BUILD_FOLDER}
  146. echo ""
  147. echo "--------------- PYTHON WAS BUILT FROM SOURCE ---------------"
  148. echo ""
  149. exit 0