Bug 1451065 - Require Python 3.5+ to build; r?Build draft
authorGregory Szorc <gps@mozilla.com>
Tue, 03 Apr 2018 11:00:00 -0700
changeset 784787 03cdb1453f35d485dd04bda7b82bc49de56bc601
parent 784786 4d12cbb6ea1801f2bc52838c0a8f79935ccff6e0
push id107028
push userbmo:gps@mozilla.com
push dateThu, 19 Apr 2018 00:46:23 +0000
reviewersBuild
bugs1451065
milestone61.0a1
Bug 1451065 - Require Python 3.5+ to build; r?Build But only if we are: a) not running in CI b) running in CI on Linux We will ideally make the requirement global. But Python 3.5 is not yet available in CI on macOS. And we're not finding the MozillaBuild copy in configure. This was previously announced in November at https://groups.google.com/d/msg/mozilla.dev.platform/rJrPh1QYXrQ/hqRrQsJ_BgAJ. MozReview-Commit-ID: IyPCAcL3gop
build/moz.configure/init.configure
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -363,23 +363,24 @@ def shell(value, mozillabuild):
 
 
 # Python 3
 # ========
 
 option(env='PYTHON3', nargs=1, help='Python 3 interpreter (3.5 or later)')
 
 
-@depends('PYTHON3')
+@depends('PYTHON3', 'MOZ_AUTOMATION')
 @checking('for Python 3',
           callback=lambda x: '%s (%s)' % (x.path, x.str_version) if x else 'no')
 @imports(_from='__builtin__', _import='Exception')
+@imports('platform')
 @imports(_from='mozbuild.pythonutil', _import='find_python3_executable')
 @imports(_from='mozbuild.pythonutil', _import='python_executable_version')
-def python3(env_python):
+def python3(env_python, automation):
     python = env_python[0] if env_python else None
 
     # If Python given by environment variable, it must work.
     if python:
         try:
             version = python_executable_version(python).version
         except Exception as e:
             raise FatalCheckError('could not determine version of PYTHON '
@@ -387,21 +388,32 @@ def python3(env_python):
 
         if version < (3, 5, 0):
             raise FatalCheckError('PYTHON3 must point to Python 3.5 or newer; '
                                   '%d.%d found' % (version[0], version[1]))
     else:
         # Fall back to the search routine.
         python, version = find_python3_executable(min_version='3.5.0')
 
-        if not python:
+        # The API returns a bytes whereas everything in configure is unicode.
+        if python:
+            python = python.decode('utf-8')
+
+    # Outside of automation, require Python 3.5.
+    # In automation, only require where it is known to be installed.
+    require = not automation or platform.system() == 'Linux'
+
+    if not python:
+        if not require:
             return None
 
-        # The API returns a bytes whereas everything in configure is unicode.
-        python = python.decode('utf-8')
+        raise FatalCheckError('Python 3.5 or newer is required to build. '
+                              'Ensure a `python3.x` executable is in your '
+                              'PATH or define PYTHON3 to point to a Python '
+                              '3.5 executable.')
 
     return namespace(
         path=python,
         version=version,
         str_version='.'.join(str(v) for v in version),
     )