From d27be523712dcbbde7f279148f12258796b2053b Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Fri, 3 Feb 2017 23:25:30 -0800 Subject: Find WPT files in Firefox repository The Servo repository is now (mostly) vendored in the Firefox Mercurial repository. For size and duplication reasons, the tests/wpt directory is not included in the vendored copy. This causes problems when running `mach` from the Firefox repository because `mach` references pip requirements files and module search paths from WPT. This commit adds code to detect when Servo's mach is running from a Firefox source tree and to resolve WPT paths to the Firefox location if appropriate. This enables `mach` to "just work" when running from the servo/ directory in the Firefox repository. The file looked for to identify the Firefox repository is identical to what Firefox's `mach` script uses. A potential issue with using Firefox's WPT files is that they may be different from those in the Servo repository and this could lead to differences in behavior - possibly even an error when loading/running `mach`. However, the behavior before this commit was that Servo's `mach` never worked in the Firefox repository (due to missing WPT files). And post-commit it does. So this seems like a "perfect is the enemy of good" scenario. --- python/mach_bootstrap.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'python/mach_bootstrap.py') diff --git a/python/mach_bootstrap.py b/python/mach_bootstrap.py index fa612ddd868..f6f6b976f08 100644 --- a/python/mach_bootstrap.py +++ b/python/mach_bootstrap.py @@ -12,8 +12,11 @@ from subprocess import PIPE, Popen SEARCH_PATHS = [ os.path.join("python", "tidy"), - os.path.join("tests", "wpt"), - os.path.join("tests", "wpt", "harness"), +] + +WPT_SEARCH_PATHS = [ + ".", + "harness", ] # Individual files providing mach commands. @@ -103,7 +106,16 @@ def _get_virtualenv_script_dir(): return "bin" -def _activate_virtualenv(topdir): +def wpt_path(topdir, paths, is_firefox): + if is_firefox: + rel = os.path.join("..", "testing", "web-platform") + else: + rel = os.path.join("tests", "wpt") + + return os.path.join(topdir, rel, *paths) + + +def _activate_virtualenv(topdir, is_firefox): virtualenv_path = os.path.join(topdir, "python", "_virtualenv") check_exec_path = lambda path: path.startswith(virtualenv_path) python = _get_exec_path(PYTHON_NAMES) # If there was no python, mach wouldn't have run at all! @@ -145,9 +157,9 @@ def _activate_virtualenv(topdir): # and it will check for conflicts. requirements_paths = [ os.path.join("python", "requirements.txt"), - os.path.join("tests", "wpt", "harness", "requirements.txt"), - os.path.join("tests", "wpt", "harness", "requirements_firefox.txt"), - os.path.join("tests", "wpt", "harness", "requirements_servo.txt"), + wpt_path(topdir, ("harness", "requirements.txt"), is_firefox), + wpt_path(topdir, ("harness", "requirements_firefox.txt"), is_firefox), + wpt_path(topdir, ("harness", "requirements_servo.txt"), is_firefox), ] if need_pip_upgrade: @@ -239,7 +251,12 @@ def bootstrap(topdir): print('You are running Python', platform.python_version()) sys.exit(1) - _activate_virtualenv(topdir) + # See if we're inside a Firefox checkout. + parentdir = os.path.normpath(os.path.join(topdir, '..')) + is_firefox = os.path.isfile(os.path.join(parentdir, + 'build/mach_bootstrap.py')) + + _activate_virtualenv(topdir, is_firefox) def populate_context(context, key=None): if key is None: @@ -249,6 +266,8 @@ def bootstrap(topdir): raise AttributeError(key) sys.path[0:0] = [os.path.join(topdir, path) for path in SEARCH_PATHS] + sys.path[0:0] = [wpt_path(topdir, (path,), is_firefox) + for path in WPT_SEARCH_PATHS] import mach.main mach = mach.main.Mach(os.getcwd()) mach.populate_context_handler = populate_context -- cgit v1.2.3