Bumping manifests a=b2g-bump
[gecko.git] / build / mach_bootstrap.py
blobea72431c0b4140217803787aa0e391f5d38d66d4
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/web-platform',
47 'testing/web-platform/harness',
48 'testing/marionette/client/marionette',
49 'testing/marionette/transport',
50 'testing/mozbase/mozcrash',
51 'testing/mozbase/mozdebug',
52 'testing/mozbase/mozdevice',
53 'testing/mozbase/mozfile',
54 'testing/mozbase/mozhttpd',
55 'testing/mozbase/mozlog',
56 'testing/mozbase/moznetwork',
57 'testing/mozbase/mozprocess',
58 'testing/mozbase/mozprofile',
59 'testing/mozbase/mozrunner',
60 'testing/mozbase/mozsystemmonitor',
61 'testing/mozbase/mozinfo',
62 'testing/mozbase/moztest',
63 'testing/mozbase/mozversion',
64 'testing/mozbase/manifestparser',
65 'xpcom/idl-parser',
68 # Individual files providing mach commands.
69 MACH_MODULES = [
70 'addon-sdk/mach_commands.py',
71 'build/valgrind/mach_commands.py',
72 'dom/bindings/mach_commands.py',
73 'layout/tools/reftest/mach_commands.py',
74 'python/mach_commands.py',
75 'python/mach/mach/commands/commandinfo.py',
76 'python/mozboot/mozboot/mach_commands.py',
77 'python/mozbuild/mozbuild/mach_commands.py',
78 'python/mozbuild/mozbuild/backend/mach_commands.py',
79 'python/mozbuild/mozbuild/frontend/mach_commands.py',
80 'services/common/tests/mach_commands.py',
81 'testing/mach_commands.py',
82 'testing/marionette/mach_commands.py',
83 'testing/mochitest/mach_commands.py',
84 'testing/xpcshell/mach_commands.py',
85 'testing/talos/mach_commands.py',
86 'testing/web-platform/mach_commands.py',
87 'testing/xpcshell/mach_commands.py',
88 'tools/docs/mach_commands.py',
89 'tools/mercurial/mach_commands.py',
90 'tools/mach_commands.py',
91 'mobile/android/mach_commands.py',
95 CATEGORIES = {
96 'build': {
97 'short': 'Build Commands',
98 'long': 'Interact with the build system',
99 'priority': 80,
101 'post-build': {
102 'short': 'Post-build Commands',
103 'long': 'Common actions performed after completing a build.',
104 'priority': 70,
106 'testing': {
107 'short': 'Testing',
108 'long': 'Run tests.',
109 'priority': 60,
111 'devenv': {
112 'short': 'Development Environment',
113 'long': 'Set up and configure your development environment.',
114 'priority': 50,
116 'build-dev': {
117 'short': 'Low-level Build System Interaction',
118 'long': 'Interact with specific parts of the build system.',
119 'priority': 20,
121 'misc': {
122 'short': 'Potpourri',
123 'long': 'Potent potables and assorted snacks.',
124 'priority': 10,
126 'disabled': {
127 'short': 'Disabled',
128 '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.',
129 'priority': 0,
134 def bootstrap(topsrcdir, mozilla_dir=None):
135 if mozilla_dir is None:
136 mozilla_dir = topsrcdir
138 # Ensure we are running Python 2.7+. We put this check here so we generate a
139 # user-friendly error message rather than a cryptic stack trace on module
140 # import.
141 if sys.version_info[0] != 2 or sys.version_info[1] < 7:
142 print('Python 2.7 or above (but not Python 3) is required to run mach.')
143 print('You are running Python', platform.python_version())
144 sys.exit(1)
146 # Global build system and mach state is stored in a central directory. By
147 # default, this is ~/.mozbuild. However, it can be defined via an
148 # environment variable. We detect first run (by lack of this directory
149 # existing) and notify the user that it will be created. The logic for
150 # creation is much simpler for the "advanced" environment variable use
151 # case. For default behavior, we educate users and give them an opportunity
152 # to react. We always exit after creating the directory because users don't
153 # like surprises.
154 try:
155 import mach.main
156 except ImportError:
157 sys.path[0:0] = [os.path.join(mozilla_dir, path) for path in SEARCH_PATHS]
158 import mach.main
160 def populate_context(context, key=None):
161 if key is None:
162 return
163 if key == 'state_dir':
164 state_user_dir = os.path.expanduser('~/.mozbuild')
165 state_env_dir = os.environ.get('MOZBUILD_STATE_PATH', None)
166 if state_env_dir:
167 if not os.path.exists(state_env_dir):
168 print('Creating global state directory from environment variable: %s'
169 % state_env_dir)
170 os.makedirs(state_env_dir, mode=0o770)
171 print('Please re-run mach.')
172 sys.exit(1)
173 state_dir = state_env_dir
174 else:
175 if not os.path.exists(state_user_dir):
176 print(STATE_DIR_FIRST_RUN.format(userdir=state_user_dir))
177 try:
178 for i in range(20, -1, -1):
179 time.sleep(1)
180 sys.stdout.write('%d ' % i)
181 sys.stdout.flush()
182 except KeyboardInterrupt:
183 sys.exit(1)
185 print('\nCreating default state directory: %s' % state_user_dir)
186 os.mkdir(state_user_dir)
187 print('Please re-run mach.')
188 sys.exit(1)
189 state_dir = state_user_dir
191 return state_dir
192 if key == 'topdir':
193 return topsrcdir
194 raise AttributeError(key)
196 mach = mach.main.Mach(os.getcwd())
197 mach.populate_context_handler = populate_context
199 for category, meta in CATEGORIES.items():
200 mach.define_category(category, meta['short'], meta['long'],
201 meta['priority'])
203 for path in MACH_MODULES:
204 mach.load_commands_from_file(os.path.join(mozilla_dir, path))
206 return mach