Index: scripts/slave/unittests/test_env.py
|
diff --git a/scripts/slave/unittests/test_env.py b/scripts/slave/unittests/test_env.py
|
index f299b6f780c55ff28d36a3a6fe0f07718975122c..26caf90ffa01bd1e194769634f575355be080346 100644
|
--- a/scripts/slave/unittests/test_env.py
|
+++ b/scripts/slave/unittests/test_env.py
|
@@ -10,6 +10,7 @@ directories.
|
|
import os
|
import sys
|
+import textwrap
|
|
RUNTESTS_DIR = os.path.dirname(os.path.abspath(__file__))
|
DATA_PATH = os.path.join(RUNTESTS_DIR, 'data')
|
@@ -22,22 +23,81 @@ sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'buildbot_slave_8_4'))
|
sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'twisted_10_2'))
|
sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'mock-1.0.1'))
|
|
-try:
|
- # The C-compiled coverage engine is WAY faster than the pure python version.
|
- # If we have it, then don't bother with the pure python one.
|
- import coverage
|
-except ImportError:
|
- sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'coverage-3.6'))
|
- import coverage
|
-
|
-def print_coverage_warning():
|
- if not hasattr(coverage.collector, 'CTracer'):
|
- print "WARNING: Using the pure-python coverage module."
|
- print " Install the native python coverage module to speed recipe"
|
- print " training up by an order of magnitude."
|
- print
|
- print " pip install coverage"
|
- print " OR"
|
- print " easy_install coverage"
|
+def ensure_coverage_importable():
|
+ try:
|
+ from distutils.version import StrictVersion
|
+ import coverage
|
+ if (StrictVersion(coverage.__version__) < StrictVersion('3.7') or
|
+ not coverage.collector.CTracer):
|
+ del sys.modules['coverage']
|
+ del coverage
|
+ else:
|
+ return
|
+ except ImportError:
|
+ if sys.platform.startswith('win'):
|
+ print textwrap.dedent("""
|
+ Please install coverage by running the appropriate installer from:
|
+ https://pypi.python.org/pypi/coverage/3.7.1
|
+ """)
|
+ sys.exit(1)
|
+
|
+ try:
|
+ import setuptools # pylint: disable=W0612
|
+ except ImportError:
|
+ print textwrap.dedent("""
|
+ No compatible system-wide python-coverage package installed, and
|
+ setuptools is not installed either. Please obtain setuptools by:
|
+
|
+ Debian/Ubuntu:
|
+ sudo apt-get install python-setuptools python-dev
|
+
|
+ OS X:
|
+ https://pypi.python.org/pypi/setuptools#unix-including-mac-os-x-curl
|
+
|
+ Other:
|
+ https://pypi.python.org/pypi/setuptools#installation-instructions
|
+ """)
|
+ sys.exit(1)
|
+
|
+ from pkg_resources import get_build_platform
|
+ try:
|
+ # Python 2.7 or >= 3.2
|
+ from sysconfig import get_python_version
|
+ except ImportError:
|
+ from distutils.sysconfig import get_python_version
|
+
|
+ cov_dir = os.path.join(BASE_DIR, 'third_party', 'coverage-3.7.1')
|
+ cov_egg = os.path.join(cov_dir, 'dist', 'coverage-3.7.1-py%s-%s.egg' % (
|
+ get_python_version(), get_build_platform()))
|
+
|
+ # The C-compiled coverage engine is WAY faster (and less buggy) than the pure
|
+ # python version, so we build the dist_egg if necessary.
|
+ if not os.path.exists(cov_egg):
|
+ import subprocess
|
+ print 'Building Coverage 3.7.1'
|
+ p = subprocess.Popen([sys.executable, 'setup.py', 'bdist_egg'], cwd=cov_dir,
|
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
+ stdout, stderr = p.communicate()
|
+ if p.returncode != 0:
|
+ print 'Error while building :('
|
+ print stdout
|
+ print stderr
|
+ if sys.platform.startswith('linux'):
|
+ print textwrap.dedent("""
|
+ You probably don't have the 'python-dev' package installed. Install
|
+ it by running:
|
+ sudo apt-get install python-dev
|
+ """)
|
+ else:
|
+ print textwrap.dedent("""
|
+ I'm not sure what's wrong, but your system seems incapable of building
|
+ python extensions. Please fix that by installing a Python with headers
|
+ and the approprite command-line build tools for your platform.
|
+ """)
|
+ sys.exit(1)
|
+
|
+ sys.path.insert(0, cov_egg)
|
+
|
+ensure_coverage_importable()
|
|
from common import find_depot_tools # pylint: disable=W0611
|
|