mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
653eddd3d8
This fixes https://github.com/servo/servo/issues/861. @askeing, I've copied your work from https://github.com/askeing/servo_tidy and attributed the commit to you. My commit in this PR is Git housekeeping to preserve `tidy`'s history. If you'd like to make additional changes, I've given you and @shinglyu push access to my fork of Servo. Apologies if this is already familiar, but the workflow for pushing to my branch is: ``` $ git remote add edunham git@github.com:edunham/servo.git $ git checkout -b package-tidy $ git pull edunham package-tidy $ git push edunham package-tidy ``` Once this lands, I'll look at how to publish it to PyPI and automate that process. Please don't merge this yet; we still need to discuss how the change should work around https://github.com/servo/servo/blob/master/python/servo/testing_commands.py#L33 , as I've yet to figure out how to get the egg to actually expose its tests. Source-Repo: https://github.com/servo/servo Source-Revision: bfe54539d290cb287e59e8ba106a54a3fab6201a --HG-- rename : servo/python/tidy_self_test/__init__.py => servo/python/tidy/servo_tidy/__init__.py rename : servo/python/licenseck.py => servo/python/tidy/servo_tidy/licenseck.py rename : servo/python/tidy.py => servo/python/tidy/servo_tidy/tidy.py rename : servo/python/servo/__init__.py => servo/python/tidy/servo_tidy_tests/__init__.py rename : servo/python/tidy_self_test/incorrect_license.rs => servo/python/tidy/servo_tidy_tests/incorrect_license.rs rename : servo/python/tidy_self_test/long_line.rs => servo/python/tidy/servo_tidy_tests/long_line.rs rename : servo/python/tidy_self_test/rust_tidy.rs => servo/python/tidy/servo_tidy_tests/rust_tidy.rs rename : servo/python/tidy_self_test/spec.webidl => servo/python/tidy/servo_tidy_tests/spec.webidl rename : servo/python/tidy_self_test/speclink.rs => servo/python/tidy/servo_tidy_tests/speclink.rs rename : servo/python/tidy_self_test/test.toml => servo/python/tidy/servo_tidy_tests/test.toml rename : servo/python/tidy_self_test/tidy_self_test.py => servo/python/tidy/servo_tidy_tests/test_tidy.py rename : servo/python/tidy_self_test/tidy_self_test.py => servo/python/tidy/servo_tidy_tests/tidy_self_test.py rename : servo/python/tidy_self_test/whatwg_link.rs => servo/python/tidy/servo_tidy_tests/whatwg_link.rs rename : servo/python/tidy_self_test/wrong_space.rs => servo/python/tidy/servo_tidy_tests/wrong_space.rs
199 lines
6.7 KiB
Python
199 lines
6.7 KiB
Python
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
import os
|
|
import platform
|
|
import subprocess
|
|
import sys
|
|
from distutils.spawn import find_executable
|
|
from pipes import quote
|
|
|
|
SEARCH_PATHS = [
|
|
os.path.join("python", "mach"),
|
|
os.path.join("python", "tidy"),
|
|
os.path.join("tests", "wpt"),
|
|
os.path.join("tests", "wpt", "harness"),
|
|
]
|
|
|
|
# Individual files providing mach commands.
|
|
MACH_MODULES = [
|
|
os.path.join('python', 'servo', 'bootstrap_commands.py'),
|
|
os.path.join('python', 'servo', 'build_commands.py'),
|
|
os.path.join('python', 'servo', 'testing_commands.py'),
|
|
os.path.join('python', 'servo', 'post_build_commands.py'),
|
|
os.path.join('python', 'servo', 'devenv_commands.py'),
|
|
]
|
|
|
|
|
|
CATEGORIES = {
|
|
'bootstrap': {
|
|
'short': 'Bootstrap Commands',
|
|
'long': 'Bootstrap the build system',
|
|
'priority': 90,
|
|
},
|
|
'build': {
|
|
'short': 'Build Commands',
|
|
'long': 'Interact with the build system',
|
|
'priority': 80,
|
|
},
|
|
'post-build': {
|
|
'short': 'Post-build Commands',
|
|
'long': 'Common actions performed after completing a build.',
|
|
'priority': 70,
|
|
},
|
|
'testing': {
|
|
'short': 'Testing',
|
|
'long': 'Run tests.',
|
|
'priority': 60,
|
|
},
|
|
'devenv': {
|
|
'short': 'Development Environment',
|
|
'long': 'Set up and configure your development environment.',
|
|
'priority': 50,
|
|
},
|
|
'build-dev': {
|
|
'short': 'Low-level Build System Interaction',
|
|
'long': 'Interact with specific parts of the build system.',
|
|
'priority': 20,
|
|
},
|
|
'misc': {
|
|
'short': 'Potpourri',
|
|
'long': 'Potent potables and assorted snacks.',
|
|
'priority': 10,
|
|
},
|
|
'disabled': {
|
|
'short': 'Disabled',
|
|
'long': 'The disabled commands are hidden by default. Use -v to display them. These commands are unavailable '
|
|
'for your current context, run "mach <command>" to see why.',
|
|
'priority': 0,
|
|
}
|
|
}
|
|
|
|
|
|
def _get_exec(*names):
|
|
for name in names:
|
|
path = find_executable(name)
|
|
if path is not None:
|
|
return path
|
|
return None
|
|
|
|
|
|
def _get_virtualenv_script_dir():
|
|
# Virtualenv calls its scripts folder "bin" on linux/OSX/MSYS64 but "Scripts" on Windows
|
|
if os.name == "nt" and os.path.sep != "/":
|
|
return "Scripts"
|
|
return "bin"
|
|
|
|
|
|
# Possible names of executables, sorted from most to least specific
|
|
PYTHON_NAMES = ["python-2.7", "python2.7", "python2", "python"]
|
|
VIRTUALENV_NAMES = ["virtualenv-2.7", "virtualenv2.7", "virtualenv2", "virtualenv"]
|
|
PIP_NAMES = ["pip-2.7", "pip2.7", "pip2", "pip"]
|
|
|
|
|
|
def _activate_virtualenv(topdir):
|
|
virtualenv_path = os.path.join(topdir, "python", "_virtualenv")
|
|
python = _get_exec(*PYTHON_NAMES)
|
|
if python is None:
|
|
sys.exit("Python is not installed. Please install it prior to running mach.")
|
|
|
|
script_dir = _get_virtualenv_script_dir()
|
|
activate_path = os.path.join(virtualenv_path, script_dir, "activate_this.py")
|
|
if not (os.path.exists(virtualenv_path) and os.path.exists(activate_path)):
|
|
virtualenv = _get_exec(*VIRTUALENV_NAMES)
|
|
if virtualenv is None:
|
|
sys.exit("Python virtualenv is not installed. Please install it prior to running mach.")
|
|
|
|
try:
|
|
subprocess.check_call([virtualenv, "-p", python, virtualenv_path])
|
|
except (subprocess.CalledProcessError, OSError):
|
|
sys.exit("Python virtualenv failed to execute properly.")
|
|
|
|
execfile(activate_path, dict(__file__=quote(activate_path)))
|
|
|
|
# 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"),
|
|
os.path.join("tests", "wpt", "harness", "requirements.txt"),
|
|
os.path.join("tests", "wpt", "harness", "requirements_servo.txt"),
|
|
]
|
|
for req_rel_path in requirements_paths:
|
|
req_path = os.path.join(topdir, req_rel_path)
|
|
marker_file = req_rel_path.replace(os.path.sep, '-')
|
|
marker_path = os.path.join(virtualenv_path, marker_file)
|
|
try:
|
|
if os.path.getmtime(req_path) + 10 < os.path.getmtime(marker_path):
|
|
continue
|
|
except OSError:
|
|
pass
|
|
|
|
pip = _get_exec(*PIP_NAMES)
|
|
if pip is None:
|
|
sys.exit("Python pip is not installed. Please install it prior to running mach.")
|
|
|
|
try:
|
|
subprocess.check_call([pip, "install", "-q", "-r", req_path])
|
|
except (subprocess.CalledProcessError, OSError):
|
|
sys.exit("Pip failed to execute properly.")
|
|
|
|
open(marker_path, 'w').close()
|
|
|
|
|
|
def bootstrap(topdir):
|
|
topdir = os.path.abspath(topdir)
|
|
|
|
# We don't support paths with Unicode characters for now
|
|
# https://github.com/servo/servo/issues/10002
|
|
try:
|
|
topdir.decode('ascii')
|
|
except UnicodeDecodeError:
|
|
print('Cannot run mach in a path with Unicode characters.')
|
|
print('Current path:', topdir)
|
|
sys.exit(1)
|
|
|
|
# We don't support paths with spaces for now
|
|
# https://github.com/servo/servo/issues/9442
|
|
if ' ' in topdir:
|
|
print('Cannot run mach in a path with spaces.')
|
|
print('Current path:', topdir)
|
|
sys.exit(1)
|
|
|
|
# Ensure we are running Python 2.7+. We put this check here so we generate a
|
|
# user-friendly error message rather than a cryptic stack trace on module
|
|
# import.
|
|
if not (3, 0) > sys.version_info >= (2, 7):
|
|
print('Python 2.7 or above (but not Python 3) is required to run mach.')
|
|
print('You are running Python', platform.python_version())
|
|
sys.exit(1)
|
|
|
|
_activate_virtualenv(topdir)
|
|
|
|
def populate_context(context, key=None):
|
|
if key is None:
|
|
return
|
|
if key == 'topdir':
|
|
return topdir
|
|
raise AttributeError(key)
|
|
|
|
sys.path[0:0] = [os.path.join(topdir, path) for path in SEARCH_PATHS]
|
|
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'])
|
|
|
|
for path in MACH_MODULES:
|
|
mach.load_commands_from_file(os.path.join(topdir, path))
|
|
|
|
return mach
|