docker_build_linux.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. CMD="\
  84. ./configure --prefix=${BUILD_FOLDER}/python\
  85. --enable-optimizations\
  86. --with-openssl=${OPENSSL_BASE}\
  87. --enable-shared LDFLAGS='-Wl,-rpath=\$$ORIGIN:\$$ORIGIN/../lib:\$$ORIGIN/../.. -L../ffi_lib/lib -L'${SQLITE_BASE}'/lib'\
  88. CPPFLAGS='-I../ffi_lib/include -I'${SQLITE_BASE}'' CFLAGS='-I../ffi_lib/include -I'${SQLITE_BASE}''"
  89. echo $CMD
  90. eval $CMD
  91. if [ $? -ne 0 ]
  92. then
  93. echo "'configure' failed for cpython at ${SRC_PATH}"
  94. exit 1
  95. fi
  96. CMD="make"
  97. echo $CMD
  98. eval $CMD
  99. if [ $? -ne 0 ]
  100. then
  101. echo "'make' failed for cpython at ${SRC_PATH}"
  102. exit 1
  103. fi
  104. CMD="make install"
  105. echo $CMD
  106. eval $CMD
  107. if [ $? -ne 0 ]
  108. then
  109. echo "'make install' failed for cpython at ${SRC_PATH}"
  110. exit 1
  111. fi
  112. popd
  113. echo "Preparing additional python files"
  114. # Copy the python license
  115. cp ${SRC_PATH}/LICENSE ${BUILD_FOLDER}/python/LICENSE
  116. # Also copy the openssl license since its linked against the dependent O3DE OpenSSL static package
  117. cp ${OPENSSL_BASE}/LICENSE ${BUILD_FOLDER}/python/LICENSE.OPENSSL
  118. # Create a symlink from python -> python3
  119. pushd ${BUILD_FOLDER}/python/bin
  120. ln -s python3 python
  121. popd
  122. pushd ${BUILD_FOLDER}
  123. echo "Upgrading pip"
  124. # the pip that may come from the above repo can be broken, so we'll use get-pip
  125. # and then upgrade it.
  126. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  127. ./python/bin/python3 get-pip.py
  128. rm get-pip.py
  129. pushd python/bin
  130. PYTHONNOUSERSITE=1 ./python3 -m pip install --upgrade pip
  131. echo "Upgrading setup tools"
  132. # Update setup tools to resolve https://avd.aquasec.com/nvd/cve-2022-40897
  133. PYTHONNOUSERSITE=1 ./python3 -m pip install setuptools --upgrade setuptools
  134. # Update wheel to resolve https://avd.aquasec.com/nvd/2022/cve-2022-40898/
  135. PYTHONNOUSERSITE=1 ./python3 -m pip install wheel --upgrade wheel
  136. popd #python/bin
  137. # installing pip causes it to put absolute paths to python
  138. # in the pip files (in bin). For example, pip will have
  139. # a line at the top that starts with #!/full/path/to/python
  140. # so we fix those up too.
  141. # We want to change it from and absolute path to python
  142. # to a multi-line #! that runs python from the same folder as the file is being called from:
  143. #!/bin/sh
  144. #"exec" "`dirname $0`/python" "$0" "$@"
  145. sed -i "1s+.*+\#\!/bin/sh+" ./python/bin/pip*
  146. sed -i "2i\\
  147. \"exec\" \"\`dirname \$0\`/python\" \"\$0\" \"\$\@\" " ./python/bin/pip*
  148. popd # ${BUILD_FOLDER}
  149. echo ""
  150. echo "--------------- PYTHON WAS BUILT FROM SOURCE ---------------"
  151. echo ""
  152. exit 0