Bumping manifests a=b2g-bump
[gecko.git] / build / mach_bootstrap.py
blob1e08e7786e4117f31c465284a98477cc74bb11e4
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import print_function, unicode_literals
7 import os
8 import platform
9 import sys
10 import time
13 STATE_DIR_FIRST_RUN = '''
14 mach and the build system store shared state in a common directory on the
15 filesystem. The following directory will be created:
17 {userdir}
19 If you would like to use a different directory, hit CTRL+c and set the
20 MOZBUILD_STATE_PATH environment variable to the directory you would like to
21 use and re-run mach. For this change to take effect forever, you'll likely
22 want to export this environment variable from your shell's init scripts.
23 '''.lstrip()
26 # TODO Bug 794506 Integrate with the in-tree virtualenv configuration.
27 SEARCH_PATHS = [
28 'python/mach',
29 'python/mozboot',
30 'python/mozbuild',
31 'python/mozversioncontrol',
32 'python/blessings',
33 'python/configobj',
34 'python/jsmin',
35 'python/psutil',
36 'python/which',
37 'build/pymake',
38 'config',
39 'dom/bindings',
40 'dom/bindings/parser',
41 'layout/tools/reftest',
42 'other-licenses/ply',
43 'xpcom/idl-parser',
44 'testing',
45 'testing/xpcshell',
46 'testing/marionette/client',
47 'testing/marionette/client/marionette',
48 'testing/marionette/transport',
49 'testing/mozbase/mozcrash',
50 'testing/mozbase/mozdebug',
51 'testing/mozbase/mozdevice',
52 'testing/mozbase/mozfile',
53 'testing/mozbase/mozhttpd',
54 'testing/mozbase/mozlog',
55 'testing/mozbase/moznetwork',
56 'testing/mozbase/mozprocess',
57 'testing/mozbase/mozprofile',
58 'testing/mozbase/mozrunner',
59 'testing/mozbase/mozsystemmonitor',
60 'testing/mozbase/mozinfo',
61 'testing/mozbase/moztest',
62 'testing/mozbase/mozversion',
63 'testing/mozbase/manifestparser',
64 'xpcom/idl-parser',
67 # Individual files providing mach commands.
68 MACH_MODULES = [
69 'addon-sdk/mach_commands.py',
70 'build/valgrind/mach_commands.py',
71 'dom/bindings/mach_commands.py',
72 'layout/tools/reftest/mach_commands.py',
73 'python/mach_commands.py',
74 'python/mach/mach/commands/commandinfo.py',
75 'python/mozboot/mozboot/mach_commands.py',
76 'python/mozbuild/mozbuild/mach_commands.py',
77 'python/mozbuild/mozbuild/frontend/mach_commands.py',
78 'services/common/tests/mach_commands.py',
79 'testing/mach_commands.py',
80 'testing/marionette/mach_commands.py',
81 'testing/mochitest/mach_commands.py',
82 'testing/xpcshell/mach_commands.py',
83 'testing/talos/mach_commands.py',
84 'testing/xpcshell/mach_commands.py',
85 'tools/docs/mach_commands.py',
86 'tools/mercurial/mach_commands.py',
87 'tools/mach_commands.py',
91 CATEGORIES = {
92 'build': {
93 'short': 'Build Commands',
94 'long': 'Interact with the build system',
95 'priority': 80,
97 'post-build': {
98 'short': 'Post-build Commands',
99 'long': 'Common actions performed after completing a build.',
100 'priority': 70,
102 'testing': {
103 'short': 'Testing',
104 'long': 'Run tests.',
105 'priority': 60,
107 'devenv': {
108 'short': 'Development Environment',
109 'long': 'Set up and configure your development environment.',
110 'priority': 50,
112 'build-dev': {
113 'short': 'Low-level Build System Interaction',
114 'long': 'Interact with specific parts of the build system.',
115 'priority': 20,
117 'misc': {
118 'short': 'Potpourri',
119 'long': 'Potent potables and assorted snacks.',
120 'priority': 10,
122 'disabled': {
123 'short': 'Disabled',
124 'long': 'The disabled commands are hidden by default. Use -v to display them. These commands are unavailable for your current context, run "mach <command>" to see why.',
125 'priority': 0,
130 def bootstrap(topsrcdir, mozilla_dir=None):
131 if mozilla_dir is None:
132 mozilla_dir = topsrcdir
134 # Ensure we are running Python 2.7+. We put this check here so we generate a
135 # user-friendly error message rather than a cryptic stack trace on module
136 # import.
137 if sys.version_info[0] != 2 or sys.version_info[1] < 7:
138 print('Python 2.7 or above (but not Python 3) is required to run mach.')
139 print('You are running Python', platform.python_version())
140 sys.exit(1)
142 # Global build system and mach state is stored in a central directory. By
143 # default, this is ~/.mozbuild. However, it can be defined via an
144 # environment variable. We detect first run (by lack of this directory
145 # existing) and notify the user that it will be created. The logic for
146 # creation is much simpler for the "advanced" environment variable use
147 # case. For default behavior, we educate users and give them an opportunity
148 # to react. We always exit after creating the directory because users don't
149 # like surprises.
150 try:
151 import mach.main
152 except ImportError:
153 sys.path[0:0] = [os.path.join(mozilla_dir, path) for path in SEARCH_PATHS]
154 import mach.main
156 def populate_context(context, key=None):
157 if key is None:
158 return
159 if key == 'state_dir':
160 state_user_dir = os.path.expanduser('~/.mozbuild')
161 state_env_dir = os.environ.get('MOZBUILD_STATE_PATH', None)
162 if state_env_dir:
163 if not os.path.exists(state_env_dir):
164 print('Creating global state directory from environment variable: %s'
165 % state_env_dir)
166 os.makedirs(state_env_dir, mode=0o770)
167 print('Please re-run mach.')
168 sys.exit(1)
169 state_dir = state_env_dir
170 else:
171 if not os.path.exists(state_user_dir):
172 print(STATE_DIR_FIRST_RUN.format(userdir=state_user_dir))
173 try:
174 for i in range(20, -1, -1):
175 time.sleep(1)
176 sys.stdout.write('%d ' % i)
177 sys.stdout.flush()
178 except KeyboardInterrupt:
179 sys.exit(1)
181 print('\nCreating default state directory: %s' % state_user_dir)
182 os.mkdir(state_user_dir)
183 print('Please re-run mach.')
184 sys.exit(1)
185 state_dir = state_user_dir
187 return state_dir
188 if key == 'topdir':
189 return topsrcdir
190 raise AttributeError(key)
192 mach = mach.main.Mach(os.getcwd())
193 mach.populate_context_handler = populate_context
195 for category, meta in CATEGORIES.items():
196 mach.define_category(category, meta['short'], meta['long'],
197 meta['priority'])
199 for path in MACH_MODULES:
200 mach.load_commands_from_file(os.path.join(mozilla_dir, path))
202 return mach