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..a8fab737156a742703175a624d233fed618aedab 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,52 @@ 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 " 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: |
+ pass |
+ |
+ 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('win'): |
+ print textwrap.dedent(""" |
+ I see that you\'re running Windows. Please install coverage by running |
+ this executable from the internet: |
Vadim Sh.
2014/04/04 19:47:09
:D
Maybe just link to PyPI page?
|
+ https://pypi.python.org/packages/2.7/c/coverage/coverage-3.7.1.win32-py2.7.exe#md5=fd290395319e4a7277cbcc086b7bba95 |
+ """) |
+ sys.exit(1) |
+ |
+ sys.path.insert(0, cov_egg) |
+ |
+ensure_coverage_importable() |
from common import find_depot_tools # pylint: disable=W0611 |