servo/mach
Michael Mc Donnell 3fa1d3d9cf
Check maximum Python version in mach (#34490)
Mach is currently failing bootstrap and building if the Python version
is greater than 3.12. This is because wpt does not support 3.13 yet.
This causes confusion for people running recent distros that ship 3.13
by default.

I changed the logic so that mach checks both the minimum and the maximum
supported versions of Python instead of just checking the minimum. It
will now also tell you which maximum version is supported.

I also updated the README.md to specify the supported Python versions
so that people don't accidentally install the wrong version.

Signed-off-by: Michael Mc Donnell <michael@mcdonnell.dk>
2024-12-05 21:15:02 +00:00

52 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# The beginning of this script is both valid shell and valid python,
# such that the script starts with the shell and is reexecuted with
# the right python.
''':' && if [ ! -z "$MSYSTEM" ] ; then exec python "$0" "$@" ; else which python3 > /dev/null 2> /dev/null && exec python3 "$0" "$@" || exec python "$0" "$@" ; fi
'''
import os
import sys
# Destructure because version_info > max_ver is true when running the same version.
ver = (sys.version_info[0], sys.version_info[1])
min_ver = (3, 10)
max_ver = (3, 12) # WPT does not support Python 3.13. See issue #34095.
if ver < min_ver or ver > max_ver:
print("mach does not support python {0}.{1}, please install 3.{2} <= python <= 3.{3}" \
.format(ver[0], ver[1], min_ver[1], max_ver[1]))
sys.exit(1)
def main(args):
topdir = os.path.abspath(os.path.dirname(sys.argv[0]))
sys.path.insert(0, os.path.join(topdir, "python"))
import mach_bootstrap
if len(sys.argv) > 1 and sys.argv[1] == "bootstrap":
sys.exit(mach_bootstrap.bootstrap_command_only(topdir))
else:
mach = mach_bootstrap.bootstrap(topdir)
sys.exit(mach.run(sys.argv[1:]))
if __name__ == '__main__':
sys.dont_write_bytecode = True
need_nix_shell = os.path.exists('/etc/NIXOS') or 'MACH_USE_NIX' in os.environ
if need_nix_shell and not 'IN_NIX_SHELL' in os.environ:
import subprocess
from shlex import quote
mach_dir = os.path.abspath(os.path.dirname(__file__))
build_android_args = ['--arg', 'buildAndroid', 'true'] if 'SERVO_ANDROID_BUILD' in os.environ else []
print(f'NOTE: Entering nix-shell {mach_dir}/shell.nix')
try:
# sys argv already contains the ./mach part, so we just need to pass it as-is
result = subprocess.run(['nix-shell', f'{mach_dir}/shell.nix'] + build_android_args + ['--run', ' '.join(map(quote, sys.argv))])
sys.exit(result.returncode)
except KeyboardInterrupt:
sys.exit(0)
else:
main(sys.argv)