build_package_image.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  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. #
  8. # this script builds python for linux and darwin_x64
  9. # and places the result in linux_x64/package or darwin_x64/package
  10. import subprocess
  11. import sys
  12. import os
  13. import platform
  14. folder_names = { # subfolder interpreter build script
  15. 'darwin' : ('darwin_x64' , 'Python.framework/Versions/3.10/bin/python3', 'make-python.sh'),
  16. 'linux' : ('linux_x64' , 'python/bin/python', 'make-python.sh'),
  17. 'windows' : ('win_x64' , 'python/python.exe', 'build_python.bat')
  18. }
  19. platformsys = platform.system().lower()
  20. # For linux, we may support aarch64 architecture as well as the default x86_64
  21. if platformsys == 'linux' and platform.machine() == 'aarch64':
  22. print("Linux aarch64 builds not supported by this script")
  23. sys.exit(1)
  24. # intentionally generate a keyerror if its not a good platform:
  25. subfolder_name, binary_relpath, build_script = folder_names[platformsys]
  26. script_dir = os.path.dirname(os.path.realpath(__file__))
  27. build_script_dir = os.path.join(script_dir, subfolder_name)
  28. test_script_name = os.path.join(script_dir, 'quick_validate_python.py')
  29. build_script_name = os.path.join(build_script_dir, build_script)
  30. # the built python is expected to be in build script dir/package/...
  31. python_dir = os.path.join(build_script_dir, 'package' )
  32. python_executable = os.path.join(python_dir, binary_relpath)
  33. # build python using the build script
  34. result_value = subprocess.run([build_script_name], shell=True, cwd=build_script_dir)
  35. if result_value.returncode != 0:
  36. sys.exit(result_value.returncode)
  37. # test out the freshly created python executable:
  38. result_value = subprocess.run([python_executable, test_script_name], cwd=python_dir)
  39. sys.exit(result_value.returncode)