Backout a74bd5095902, Bug 959405 - Please update the Buri Moz-central, 1.3, 1.2 with...
[gecko.git] / build / mach_bootstrap.py
blobded809c3e6fd6a7ebbd92487084d782b06a3f587
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/psutil',
35 'python/which',
36 'build/pymake',
37 'config',
38 'dom/bindings',
39 'dom/bindings/parser',
40 'other-licenses/ply',
41 'xpcom/idl-parser',
42 'testing',
43 'testing/xpcshell',
44 'testing/marionette/client',
45 'testing/marionette/client/marionette',
46 'testing/mozbase/mozcrash',
47 'testing/mozbase/mozdevice',
48 'testing/mozbase/mozfile',
49 'testing/mozbase/mozhttpd',
50 'testing/mozbase/mozlog',
51 'testing/mozbase/moznetwork',
52 'testing/mozbase/mozprocess',
53 'testing/mozbase/mozprofile',
54 'testing/mozbase/mozrunner',
55 'testing/mozbase/mozsystemmonitor',
56 'testing/mozbase/mozinfo',
57 'testing/mozbase/moztest',
58 'testing/mozbase/manifestdestiny',
59 'xpcom/idl-parser',
62 # Individual files providing mach commands.
63 MACH_MODULES = [
64 'addon-sdk/mach_commands.py',
65 'build/valgrind/mach_commands.py',
66 'dom/bindings/mach_commands.py',
67 'layout/tools/reftest/mach_commands.py',
68 'python/mach_commands.py',
69 'python/mach/mach/commands/commandinfo.py',
70 'python/mozboot/mozboot/mach_commands.py',
71 'python/mozbuild/mozbuild/mach_commands.py',
72 'python/mozbuild/mozbuild/frontend/mach_commands.py',
73 'testing/mach_commands.py',
74 'testing/marionette/mach_commands.py',
75 'testing/mochitest/mach_commands.py',
76 'testing/xpcshell/mach_commands.py',
77 'testing/talos/mach_commands.py',
78 'testing/xpcshell/mach_commands.py',
79 'tools/docs/mach_commands.py',
80 'tools/mercurial/mach_commands.py',
81 'tools/mach_commands.py',
85 CATEGORIES = {
86 'build': {
87 'short': 'Build Commands',
88 'long': 'Interact with the build system',
89 'priority': 80,
91 'post-build': {
92 'short': 'Post-build Commands',
93 'long': 'Common actions performed after completing a build.',
94 'priority': 70,
96 'testing': {
97 'short': 'Testing',
98 'long': 'Run tests.',
99 'priority': 60,
101 'devenv': {
102 'short': 'Development Environment',
103 'long': 'Set up and configure your development environment.',
104 'priority': 50,
106 'build-dev': {
107 'short': 'Low-level Build System Interaction',
108 'long': 'Interact with specific parts of the build system.',
109 'priority': 20,
111 'misc': {
112 'short': 'Potpourri',
113 'long': 'Potent potables and assorted snacks.',
114 'priority': 10,
116 'disabled': {
117 'short': 'Disabled',
118 'long': 'These commands are unavailable for your current context, run "mach <command>" to see why.',
119 'priority': 0,
124 def bootstrap(topsrcdir, mozilla_dir=None):
125 if mozilla_dir is None:
126 mozilla_dir = topsrcdir
128 # Ensure we are running Python 2.7+. We put this check here so we generate a
129 # user-friendly error message rather than a cryptic stack trace on module
130 # import.
131 if sys.version_info[0] != 2 or sys.version_info[1] < 7:
132 print('Python 2.7 or above (but not Python 3) is required to run mach.')
133 print('You are running Python', platform.python_version())
134 sys.exit(1)
136 # Global build system and mach state is stored in a central directory. By
137 # default, this is ~/.mozbuild. However, it can be defined via an
138 # environment variable. We detect first run (by lack of this directory
139 # existing) and notify the user that it will be created. The logic for
140 # creation is much simpler for the "advanced" environment variable use
141 # case. For default behavior, we educate users and give them an opportunity
142 # to react. We always exit after creating the directory because users don't
143 # like surprises.
144 state_user_dir = os.path.expanduser('~/.mozbuild')
145 state_env_dir = os.environ.get('MOZBUILD_STATE_PATH', None)
146 if state_env_dir:
147 if not os.path.exists(state_env_dir):
148 print('Creating global state directory from environment variable: %s'
149 % state_env_dir)
150 os.makedirs(state_env_dir, mode=0o770)
151 print('Please re-run mach.')
152 sys.exit(1)
153 state_dir = state_env_dir
154 else:
155 if not os.path.exists(state_user_dir):
156 print(STATE_DIR_FIRST_RUN.format(userdir=state_user_dir))
157 try:
158 for i in range(20, -1, -1):
159 time.sleep(1)
160 sys.stdout.write('%d ' % i)
161 sys.stdout.flush()
162 except KeyboardInterrupt:
163 sys.exit(1)
165 print('\nCreating default state directory: %s' % state_user_dir)
166 os.mkdir(state_user_dir)
167 print('Please re-run mach.')
168 sys.exit(1)
169 state_dir = state_user_dir
171 try:
172 import mach.main
173 except ImportError:
174 sys.path[0:0] = [os.path.join(mozilla_dir, path) for path in SEARCH_PATHS]
175 import mach.main
177 def populate_context(context):
178 context.state_dir = state_dir
179 context.topdir = topsrcdir
181 mach = mach.main.Mach(os.getcwd())
182 mach.populate_context_handler = populate_context
184 for category, meta in CATEGORIES.items():
185 mach.define_category(category, meta['short'], meta['long'],
186 meta['priority'])
188 for path in MACH_MODULES:
189 mach.load_commands_from_file(os.path.join(mozilla_dir, path))
191 return mach