From f693582ba92e6280ed159c8895b8ac8406e71138 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 13 May 2017 15:02:47 +0200 Subject: [PATCH] Add 'mach check' and 'mach check-geckolib' --- README.md | 15 ++++++- python/servo/devenv_commands.py | 70 ++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7f3c982e168..84683bd106e 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,6 @@ Mach tools to orchestrate the build and other tasks. ### Normal build - To build Servo in development mode. This is useful for development, but the resulting binary is very slow. @@ -159,6 +158,20 @@ real-world use, add the `--release` flag to create an optimized build: ./mach run --release tests/html/about-mozilla.html ``` +### Checking for build errors, without building + +If you’re making changes to one crate that cause build errors in another crate, +consider this instead of a full build: + +```sh +./mach check +``` + +It will run `cargo check`, which runs the analysis phase of the compiler +(and so shows build errors if any) but skips the code generation phase. +This can be a lot faster than a full build, +though of course it doesn’t produce a binary you can run. + ### Building for Android target ``` sh diff --git a/python/servo/devenv_commands.py b/python/servo/devenv_commands.py index f7df09ce754..ff70769771a 100644 --- a/python/servo/devenv_commands.py +++ b/python/servo/devenv_commands.py @@ -9,6 +9,7 @@ from __future__ import print_function, unicode_literals from os import path, getcwd, listdir +from time import time import sys import urllib2 @@ -21,10 +22,43 @@ from mach.decorators import ( ) from servo.command_base import CommandBase, cd, call +from servo.build_commands import notify_build_done @CommandProvider class MachCommands(CommandBase): + def run_cargo(self, params, geckolib=False, check=False): + if geckolib: + self.set_use_stable_rust() + crate_dir = path.join('ports', 'geckolib') + else: + crate_dir = path.join('components', 'servo') + + self.ensure_bootstrapped() + self.ensure_clobbered() + env = self.build_env(geckolib=geckolib) + + if not params: + params = [] + + if check: + params = ['check'] + params + + build_start = time() + if self.context.topdir == getcwd(): + with cd(crate_dir): + status = call(['cargo'] + params, env=env) + else: + status = call(['cargo'] + params, env=env) + elapsed = time() - build_start + + notify_build_done(self.config, elapsed, status == 0) + + if check and status == 0: + print('Finished checking, binary NOT updated. Consider ./mach build before ./mach run') + + return status + @Command('cargo', description='Run Cargo', category='devenv') @@ -32,15 +66,7 @@ class MachCommands(CommandBase): 'params', default=None, nargs='...', help="Command-line arguments to be passed through to Cargo") def cargo(self, params): - if not params: - params = [] - - self.ensure_bootstrapped() - - if self.context.topdir == getcwd(): - with cd(path.join('components', 'servo')): - return call(["cargo"] + params, env=self.build_env()) - return call(['cargo'] + params, env=self.build_env()) + return self.run_cargo(params) @Command('cargo-geckolib', description='Run Cargo with the same compiler version and root crate as build-geckolib', @@ -49,17 +75,25 @@ class MachCommands(CommandBase): 'params', default=None, nargs='...', help="Command-line arguments to be passed through to Cargo") def cargo_geckolib(self, params): - if not params: - params = [] + return self.run_cargo(params, geckolib=True) - self.set_use_stable_rust() - self.ensure_bootstrapped() - env = self.build_env(geckolib=True) + @Command('check', + description='Run "cargo check"', + category='devenv') + @CommandArgument( + 'params', default=None, nargs='...', + help="Command-line arguments to be passed through to cargo check") + def check(self, params): + return self.run_cargo(params, check=True) - if self.context.topdir == getcwd(): - with cd(path.join('ports', 'geckolib')): - return call(["cargo"] + params, env=env) - return call(['cargo'] + params, env=env) + @Command('check-geckolib', + description='Run "cargo check" with the same compiler version and root crate as build-geckolib', + category='devenv') + @CommandArgument( + 'params', default=None, nargs='...', + help="Command-line arguments to be passed through to cargo check") + def check_geckolib(self, params): + return self.run_cargo(params, check=True, geckolib=True) @Command('cargo-update', description='Same as update-cargo',