Bug 1277406 - Prompt to create the state directory; r?glandium
Currently, on first run of `mach` it prompts you to create a state
directory. The hand-off between bootstrap and `mach` has always
bothered me because bootstrap is supposed to get your system in a good
state.
In this commit, we teach the bootstrap tool to create the state
directory when not present. This duplicates functionality from `mach`.
The justification for the duplication is explained by inline comment.
In future commits, we'll build on this work to have the bootstrapper
run the Mercurial config wizard, which needs this state directory.
MozReview-Commit-ID: CPKVuRJ3peM
--- a/python/mozboot/mozboot/bootstrap.py
+++ b/python/mozboot/mozboot/bootstrap.py
@@ -56,16 +56,35 @@ APPLICATIONS_LIST=[
# This is a workaround for the fact that we must support python2.6 (which has
# no OrderedDict)
APPLICATIONS = dict(
browser=APPLICATIONS_LIST[0],
mobile_android_artifact_mode=APPLICATIONS_LIST[1],
mobile_android=APPLICATIONS_LIST[2],
)
+STATE_DIR_INFO = '''
+The Firefox build system and related tools store shared, persistent state
+in a common directory on the filesystem. On this machine, that directory
+is:
+
+ {statedir}
+
+If you would like to use a different directory, hit CTRL+c and set the
+MOZBUILD_STATE_PATH environment variable to the directory you'd like to
+use and re-run the bootstrapper.
+
+Would you like to create this directory?
+
+ 1. Yes
+ 2. No
+
+Your choice:
+'''
+
FINISHED = '''
Your system should be ready to build %s! If you have not already,
obtain a copy of the source code by running:
hg clone https://hg.mozilla.org/mozilla-central
Or, if you prefer Git, you should install git-cinnabar, and follow the
instruction here to clone from the Mercurial repository:
@@ -88,16 +107,26 @@ DEBIAN_DISTROS = (
'Mint',
'LinuxMint',
'Elementary OS',
'Elementary',
'"elementary OS"',
)
+def get_state_dir():
+ """Obtain path to a directory to hold state.
+
+ This code is shared with ``mach_bootstrap.py``.
+ """
+ state_user_dir = os.path.expanduser('~/.mozbuild')
+ state_env_dir = os.environ.get('MOZBUILD_STATE_PATH')
+ return state_env_dir or state_user_dir
+
+
class Bootstrapper(object):
"""Main class that performs system bootstrap."""
def __init__(self, finished=FINISHED, choice=None, no_interactive=False):
self.instance = None
self.finished = finished
self.choice = choice
cls = None
@@ -164,12 +193,30 @@ class Bootstrapper(object):
self.instance.install_system_packages()
# Like 'install_browser_packages' or 'install_mobile_android_packages'.
getattr(self.instance, 'install_%s_packages' % application)()
self.instance.ensure_mercurial_modern()
self.instance.ensure_python_modern()
+ # The state directory code is largely duplicated from mach_bootstrap.py.
+ # We can't easily import mach_bootstrap.py because the bootstrapper may
+ # run in self-contained mode and only the files in this directory will
+ # be available. We /could/ refactor parts of mach_bootstrap.py to be
+ # part of this directory to avoid the code duplication.
+ state_dir = get_state_dir()
+
+ if not os.path.exists(state_dir):
+ if not self.instance.no_interactive:
+ choice = self.instance.prompt_int(
+ prompt=STATE_DIR_INFO.format(statedir=state_dir),
+ low=1,
+ high=2)
+
+ if choice == 1:
+ print('Creating global state directory: %s' % state_dir)
+ os.makedirs(state_dir, mode=0o770)
+
print(self.finished % name)
# Like 'suggest_browser_mozconfig' or 'suggest_mobile_android_mozconfig'.
getattr(self.instance, 'suggest_%s_mozconfig' % application)()