mach install now builds servo if it hasn't been built before

This commit is contained in:
Adrian Utrilla 2016-04-14 21:37:44 +02:00
parent 415fd93a50
commit 739410e52d
No known key found for this signature in database
GPG key ID: 0B30B0FE149E7525
2 changed files with 27 additions and 8 deletions

View file

@ -103,6 +103,14 @@ def check_call(*args, **kwargs):
return subprocess.check_call(*args, shell=sys.platform == 'win32', **kwargs) return subprocess.check_call(*args, shell=sys.platform == 'win32', **kwargs)
class BuildNotFound(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return self.message
class CommandBase(object): class CommandBase(object):
"""Base class for mach command providers. """Base class for mach command providers.
@ -203,6 +211,8 @@ class CommandBase(object):
return path.join(self.context.topdir, "target") return path.join(self.context.topdir, "target")
def get_binary_path(self, release, dev, android=False): def get_binary_path(self, release, dev, android=False):
# TODO(autrilla): this function could still use work - it shouldn't
# handle quitting, or printing. It should return the path, or an error.
base_path = self.get_target_dir() base_path = self.get_target_dir()
if android: if android:
@ -220,8 +230,8 @@ class CommandBase(object):
dev_exists = path.exists(dev_path) dev_exists = path.exists(dev_path)
if not release_exists and not dev_exists: if not release_exists and not dev_exists:
print("No Servo binary found. Please run './mach build' and try again.") raise BuildNotFound('No Servo binary found.'
sys.exit() ' Perhaps you forgot to run `./mach build`?')
if release and release_exists: if release and release_exists:
return release_path return release_path

View file

@ -23,7 +23,7 @@ from mach.decorators import (
Command, Command,
) )
from servo.command_base import CommandBase, cd, call, check_call from servo.command_base import CommandBase, cd, call, check_call, BuildNotFound
def read_file(filename, if_exists=False): def read_file(filename, if_exists=False):
@ -263,10 +263,19 @@ class PostBuildCommands(CommandBase):
@CommandArgument('--dev', '-d', action='store_true', @CommandArgument('--dev', '-d', action='store_true',
help='Package the dev build') help='Package the dev build')
def install(self, release=False, dev=False): def install(self, release=False, dev=False):
try:
binary_path = self.get_binary_path(release, dev, android=True) binary_path = self.get_binary_path(release, dev, android=True)
if not path.exists(binary_path): except BuildNotFound:
# TODO: Run the build command automatically? print("Servo build not found. Building servo...")
print("Servo build not found. Please run `./mach build` to compile Servo.") result = Registrar.dispatch(
"build", context=self.context, release=release, dev=dev
)
if result:
return result
try:
binary_path = self.get_binary_path(release, dev, android=True)
except BuildNotFound:
print("Rebuilding Servo did not solve the missing build problem.")
return 1 return 1
apk_path = binary_path + ".apk" apk_path = binary_path + ".apk"