Bug 1392886 - Ignore missing mach_commands.py when checkout is sparse; r=mshal

Sparse checkouts may not have all mach_commands.py files.

mach raises an error when a mach_commands.py file is missing.

So, we teach the mach driver to ignore missing file errors when
a sparse checkout is present.

The added code is optimized to avoid an import of mozversioncontrol
and some I/O as part of resolving the repo and VCS binaries because
this file is in the critical path of all mach commands and avoiding
I/O is worthwhile. Since we aren't using sparse checkouts in the
common case, this effectively makes the new code 0 cost.

MozReview-Commit-ID: C6itJga31t5

--HG--
extra : rebase_source : 4b2c18d30ff8b923a940c80ac81372a4076b8fdc
This commit is contained in:
Gregory Szorc 2017-08-23 08:41:01 -07:00
Родитель 3088419b32
Коммит c024875c88
1 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -154,12 +154,28 @@ def bootstrap(topsrcdir, mozilla_dir=None):
sys.path[0:0] = [os.path.join(mozilla_dir, path)
for path in search_path(mozilla_dir,
'build/virtualenv_packages.txt')]
import mach.base
import mach.main
from mozboot.util import get_state_dir
from mozbuild.util import patch_main
patch_main()
def resolve_repository():
import mozversioncontrol
try:
# This API doesn't respect the vcs binary choices from configure.
# If we ever need to use the VCS binary here, consider something
# more robust.
return mozversioncontrol.get_repository_object(path=mozilla_dir)
except mozversioncontrol.InvalidRepoPath:
return None
# This is mainly to catch failures resolving the VCS binary path.
# TODO Change mozversioncontrol to raise non-generic exception.
except Exception:
return None
def telemetry_handler(context, data):
# We have not opted-in to telemetry
if 'BUILD_SYSTEM_TELEMETRY' not in os.environ:
@ -282,6 +298,9 @@ def bootstrap(topsrcdir, mozilla_dir=None):
if key == 'post_dispatch_handler':
return post_dispatch_handler
if key == 'repository':
return resolve_repository()
raise AttributeError(key)
driver = mach.main.Mach(os.getcwd())
@ -297,8 +316,16 @@ def bootstrap(topsrcdir, mozilla_dir=None):
driver.define_category(category, meta['short'], meta['long'],
meta['priority'])
repo = resolve_repository()
for path in MACH_MODULES:
# Sparse checkouts may not have all mach_commands.py files. Ignore
# errors from missing files.
try:
driver.load_commands_from_file(os.path.join(mozilla_dir, path))
except mach.base.MissingFileError:
if not repo or not repo.sparse_checkout_present():
raise
return driver