servo: Merge #20227 - Fix `mach build` for Servo in Firefox tree (from upsuper:in-firefox-build); r=jdm
authorXidorn Quan <me@upsuper.org>
Wed, 07 Mar 2018 09:19:25 -0500
changeset 461993 d61e72a8a9745ca3a8f617b22c676bd781646209
parent 461992 c5bcdb85fb8dbc3a2c5d920a65435594a5a840b5
child 461994 9e8108c83a684ca15b416d0152f75c0a4822bbff
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs20227
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #20227 - Fix `mach build` for Servo in Firefox tree (from upsuper:in-firefox-build); r=jdm Running `mach build` in servo directory in Firefox tree currently doesn't work due to several errors when importing modules. First error: ```text Traceback (most recent call last): File "mach", line 93, in <module> main(sys.argv) File "mach", line 23, in main mach = mach_bootstrap.bootstrap(topdir) File "servo/python/mach_bootstrap.py", line 280, in bootstrap mach.load_commands_from_file(os.path.join(topdir, path)) File "servo/python/_virtualenv/Lib/site-packages/mach/main.py", line 265, in load_commands_from_file imp.load_source(module_name, path) File "servo/python/servo/testing_commands.py", line 42, in <module> from update import updatecommandline File "servo/../testing/web-platform/update/__init__.py", line 17, in <module> from wptrunner.update import setup_logging, WPTUpdate File "servo/../testing/web-platform/tests/tools/wptrunner/wptrunner/update/__init__.py", line 8, in <module> from update import WPTUpdate File "servo/../testing/web-platform/tests/tools/wptrunner/wptrunner/update/update.py", line 8, in <module> from .. import environment as env File "servo/../testing/web-platform/tests/tools/wptrunner/wptrunner/environment.py", line 12, in <module> from wptserve.handlers import StringHandler ImportError: No module named wptserve.handlers ``` Second error: ```text Traceback (most recent call last): File "mach", line 93, in <module> main(sys.argv) File "mach", line 23, in main mach = mach_bootstrap.bootstrap(topdir) File "servo/python/mach_bootstrap.py", line 291, in bootstrap mach.load_commands_from_file(os.path.join(topdir, path)) File "servo/python/_virtualenv/Lib/site-packages/mach/main.py", line 265, in load_commands_from_file imp.load_source(module_name, path) File "servo/python/servo/testing_commands.py", line 43, in <module> from servo_tidy import tidy File "servo/python/tidy/servo_tidy/tidy.py", line 34, in <module> from wptmanifest import parser, node ImportError: No module named wptmanifest ``` The two commits fix these two errors respectively. Source-Repo: https://github.com/servo/servo Source-Revision: 4e2f8ec8e162fe707240eff223ec225790bf29fd
servo/python/mach_bootstrap.py
servo/python/tidy/servo_tidy/tidy.py
--- a/servo/python/mach_bootstrap.py
+++ b/servo/python/mach_bootstrap.py
@@ -126,26 +126,36 @@ def wpt_path(is_firefox, topdir, *paths)
     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 wpt_harness_path(is_firefox, topdir, *paths):
+def wptrunner_path(is_firefox, topdir, *paths):
     wpt_root = wpt_path(is_firefox, topdir)
     if is_firefox:
         rel = os.path.join(wpt_root, "tests", "tools", "wptrunner")
     else:
         rel = os.path.join(wpt_root, "web-platform-tests", "tools", "wptrunner")
 
     return os.path.join(topdir, rel, *paths)
 
 
+def wptserve_path(is_firefox, topdir, *paths):
+    wpt_root = wpt_path(is_firefox, topdir)
+    if is_firefox:
+        rel = os.path.join(wpt_root, "tests", "tools", "wptserve")
+    else:
+        rel = os.path.join(wpt_root, "web-platform-tests", "tools", "wptserve")
+
+    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!
     if not python:
         sys.exit('Failed to find python executable for starting virtualenv.')
 
     script_dir = _get_virtualenv_script_dir()
@@ -170,19 +180,19 @@ def _activate_virtualenv(topdir, is_fire
     # TODO: Right now, we iteratively install all the requirements by invoking
     # `pip install` each time. If it were the case that there were conflicting
     # requirements, we wouldn't know about them. Once
     # https://github.com/pypa/pip/issues/988 is addressed, then we can just
     # chain each of the requirements files into the same `pip install` call
     # and it will check for conflicts.
     requirements_paths = [
         os.path.join("python", "requirements.txt"),
-        wpt_harness_path(is_firefox, topdir, "requirements.txt",),
-        wpt_harness_path(is_firefox, topdir, "requirements_firefox.txt"),
-        wpt_harness_path(is_firefox, topdir, "requirements_servo.txt"),
+        wptrunner_path(is_firefox, topdir, "requirements.txt",),
+        wptrunner_path(is_firefox, topdir, "requirements_firefox.txt"),
+        wptrunner_path(is_firefox, topdir, "requirements_servo.txt"),
     ]
 
     if need_pip_upgrade:
         # Upgrade pip when virtualenv is created to fix the issue
         # https://github.com/servo/servo/issues/11074
         pip = _get_exec_path(PIP_NAMES, is_valid_path=check_exec_path)
         if not pip:
             sys.exit("Python pip is either not installed or not found in virtualenv.")
@@ -262,17 +272,18 @@ def bootstrap(topdir):
             return
         if key == 'topdir':
             return topdir
         raise AttributeError(key)
 
     sys.path[0:0] = [os.path.join(topdir, path) for path in SEARCH_PATHS]
 
     sys.path[0:0] = [wpt_path(is_firefox, topdir),
-                     wpt_harness_path(is_firefox, topdir)]
+                     wptrunner_path(is_firefox, topdir),
+                     wptserve_path(is_firefox, topdir)]
 
     import mach.main
     mach = mach.main.Mach(os.getcwd())
     mach.populate_context_handler = populate_context
 
     for category, meta in CATEGORIES.items():
         mach.define_category(category, meta['short'], meta['long'], meta['priority'])
 
--- a/servo/python/tidy/servo_tidy/tidy.py
+++ b/servo/python/tidy/servo_tidy/tidy.py
@@ -25,22 +25,25 @@ import yaml
 from licenseck import MPL, APACHE, COPYRIGHT, licenses_toml, licenses_dep_toml
 topdir = os.path.abspath(os.path.dirname(sys.argv[0]))
 wpt = os.path.join(topdir, "tests", "wpt")
 
 
 def wpt_path(*args):
     return os.path.join(wpt, *args)
 
-sys.path.append(wpt_path("web-platform-tests", "tools", "wptrunner", "wptrunner"))
-from wptmanifest import parser, node
-
 CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml")
 WPT_MANIFEST_PATH = wpt_path("include.ini")
 
+# Import wptmanifest only when we do have wpt in tree, i.e. we're not
+# inside a Firefox checkout.
+if os.path.isfile(WPT_MANIFEST_PATH):
+    sys.path.append(wpt_path("web-platform-tests", "tools", "wptrunner", "wptrunner"))
+    from wptmanifest import parser, node
+
 # Default configs
 config = {
     "skip-check-length": False,
     "skip-check-licenses": False,
     "check-alphabetical-order": True,
     "check-ordered-json-keys": [],
     "lint-scripts": [],
     "blocked-packages": {},
@@ -1161,17 +1164,20 @@ def run_lint_scripts(only_changed_files=
         for error in runner.check():
             yield error
 
 
 def scan(only_changed_files=False, progress=True, stylo=False):
     # check config file for errors
     config_errors = check_config_file(CONFIG_FILE_PATH)
     # check ini directories exist
-    manifest_errors = check_manifest_dirs(WPT_MANIFEST_PATH)
+    if os.path.isfile(WPT_MANIFEST_PATH):
+        manifest_errors = check_manifest_dirs(WPT_MANIFEST_PATH)
+    else:
+        manifest_errors = ()
     # check directories contain expected files
     directory_errors = check_directory_files(config['check_ext'])
     # standard checks
     files_to_check = filter_files('.', only_changed_files and not stylo, progress)
     checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json, check_yaml)
     line_checking_functions = (check_license, check_by_line, check_toml, check_shell,
                                check_rust, check_spec, check_modeline)
     file_errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)