Skip to content

Commit

Permalink
Bug 1630317 - Add a warning if there is an attempt to mach bootstrap …
Browse files Browse the repository at this point in the history
…from an "old commit" r=nalexander

Differential Revision: https://phabricator.services.mozilla.com/D71076
  • Loading branch information
Ricky Stewart committed Apr 15, 2020
1 parent e8cd4d1 commit b1e8759
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
26 changes: 25 additions & 1 deletion python/mozboot/mozboot/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from collections import OrderedDict

import os
import platform
import sys
import os
import subprocess
import time

# NOTE: This script is intended to be run with a vanilla Python install. We
# have to rely on the standard library instead of Python 2+3 helpers like
Expand Down Expand Up @@ -206,6 +207,15 @@
'''


OLD_REVISION_WARNING = '''
WARNING! You appear to be running `mach bootstrap` from an old revision.
bootstrap is meant primarily for getting developer environments up-to-date to
build the latest version of tree. Running bootstrap on old revisions may fail
and is not guaranteed to bring your machine to any working state in particular.
Proceed at your own peril.
'''


def update_or_create_build_telemetry_config(path):
"""Write a mach config file enabling build telemetry to `path`. If the file does not exist,
create it. If it exists, add the new setting to the existing data.
Expand Down Expand Up @@ -678,6 +688,7 @@ def current_firefox_checkout(check_output, env, hg=None):
env=env,
universal_newlines=True)
if node in HG_ROOT_REVISIONS:
_warn_if_risky_revision(path)
return ('hg', path)
# Else the root revision is different. There could be nested
# repos. So keep traversing the parents.
Expand All @@ -690,6 +701,7 @@ def current_firefox_checkout(check_output, env, hg=None):
elif os.path.exists(git_dir):
moz_configure = os.path.join(path, 'moz.configure')
if os.path.exists(moz_configure):
_warn_if_risky_revision(path)
return ('git', path)

path, child = os.path.split(path)
Expand Down Expand Up @@ -798,3 +810,15 @@ def git_clone_firefox(git, dest, watchman=None):

print('Firefox source code available at %s' % dest)
return True


def _warn_if_risky_revision(path):
# Warn the user if they're trying to bootstrap from an obviously old
# version of tree as reported by the version control system (a month in
# this case). This is an approximate calculation but is probably good
# enough for our purposes.
NUM_SECONDS_IN_MONTH = 60 * 60 * 24 * 30
from mozversioncontrol import get_repository_object
repo = get_repository_object(path)
if (time.time() - repo.get_commit_time()) >= NUM_SECONDS_IN_MONTH:
print(OLD_REVISION_WARNING)
12 changes: 12 additions & 0 deletions python/mozversioncontrol/mozversioncontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def head_ref(self):
def base_ref(self):
"""Hash of revision the current topic branch is based on."""

@abc.abstractmethod
def get_commit_time(self):
"""Return the Unix time of the HEAD revision.
"""

@abc.abstractmethod
def sparse_checkout_present(self):
"""Whether the working directory is using a sparse checkout.
Expand Down Expand Up @@ -316,6 +321,10 @@ def _run(self, *args, **runargs):
args = [a.encode('utf-8') if not isinstance(a, bytes) else a for a in args]
return self._client.rawcommand(args).decode('utf-8')

def get_commit_time(self):
return int(self._run(
'parent', '--template', '{word(0, date|hgdate)}').strip())

def sparse_checkout_present(self):
# We assume a sparse checkout is enabled if the .hg/sparse file
# has data. Strictly speaking, we should look for a requirement in
Expand Down Expand Up @@ -452,6 +461,9 @@ def has_git_cinnabar(self):
return False
return True

def get_commit_time(self):
return int(self._run('log', '-1', '--format=%ct').strip())

def sparse_checkout_present(self):
# Not yet implemented.
return False
Expand Down

0 comments on commit b1e8759

Please sign in to comment.