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