OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ Initialize the environment variables and start the buildbot slave. | 6 """ Initialize the environment variables and start the buildbot slave. |
7 """ | 7 """ |
8 | 8 |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
11 import socket | |
12 import subprocess | 11 import subprocess |
13 import sys | 12 import sys |
14 import time | 13 import time |
15 | 14 |
16 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) | 15 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) |
17 needs_reboot = False | 16 needs_reboot = False |
18 | 17 |
| 18 # Temporarily add scripts to the path. We do so in a more consistent |
| 19 # manner below, but cannot keep it here because of our recursive calls. |
| 20 sys.path.insert(0, os.path.join(os.path.dirname(SCRIPT_PATH), 'scripts')) |
| 21 from common import chromium_utils |
| 22 sys.path.pop(0) |
| 23 |
19 # By default, the slave will identify itself to the master by its hostname. | 24 # By default, the slave will identify itself to the master by its hostname. |
20 # To override that, explicitly set a slavename here. | 25 # To override that, explicitly set a slavename here. |
21 slavename = None | 26 slavename = None |
22 | 27 |
23 def remove_all_vars_except(dictionary, keep): | 28 def remove_all_vars_except(dictionary, keep): |
24 """Remove all keys from the specified dictionary except those in !keep|""" | 29 """Remove all keys from the specified dictionary except those in !keep|""" |
25 for key in set(dictionary.keys()) - set(keep): | 30 for key in set(dictionary.keys()) - set(keep): |
26 dictionary.pop(key) | 31 dictionary.pop(key) |
27 | 32 |
28 | 33 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 168 |
164 Bot.old_remote_setBuilderList = Bot.remote_setBuilderList | 169 Bot.old_remote_setBuilderList = Bot.remote_setBuilderList |
165 def cleanup(self, wanted): | 170 def cleanup(self, wanted): |
166 retval = self.old_remote_setBuilderList(wanted) | 171 retval = self.old_remote_setBuilderList(wanted) |
167 wanted_dirs = sorted(['info', 'cert', '.svn'] + [r[1] for r in wanted]) | 172 wanted_dirs = sorted(['info', 'cert', '.svn'] + [r[1] for r in wanted]) |
168 Log('Wanted directories: %s' % wanted_dirs) | 173 Log('Wanted directories: %s' % wanted_dirs) |
169 actual_dirs = sorted( | 174 actual_dirs = sorted( |
170 i for i in os.listdir(self.basedir) | 175 i for i in os.listdir(self.basedir) |
171 if os.path.isdir(os.path.join(self.basedir, i))) | 176 if os.path.isdir(os.path.join(self.basedir, i))) |
172 Log('Actual directories: %s' % actual_dirs) | 177 Log('Actual directories: %s' % actual_dirs) |
173 from common import chromium_utils | |
174 for d in actual_dirs: | 178 for d in actual_dirs: |
175 # Delete build.dead directories. | 179 # Delete build.dead directories. |
176 possible_build_dead = os.path.join(self.basedir, d, 'build.dead') | 180 possible_build_dead = os.path.join(self.basedir, d, 'build.dead') |
177 if os.path.isdir(possible_build_dead): | 181 if os.path.isdir(possible_build_dead): |
178 Log('Deleting unwanted directory %s' % possible_build_dead) | 182 Log('Deleting unwanted directory %s' % possible_build_dead) |
179 if not is_testing: | 183 if not is_testing: |
180 chromium_utils.RemoveDirectory(possible_build_dead) | 184 chromium_utils.RemoveDirectory(possible_build_dead) |
181 | 185 |
182 # Delete old slave directories. | 186 # Delete old slave directories. |
183 if d not in wanted_dirs: | 187 if d not in wanted_dirs: |
184 Log('Deleting unwanted directory %s' % d) | 188 Log('Deleting unwanted directory %s' % d) |
185 if not is_testing: | 189 if not is_testing: |
186 chromium_utils.RemoveDirectory(os.path.join(self.basedir, d)) | 190 chromium_utils.RemoveDirectory(os.path.join(self.basedir, d)) |
187 return retval | 191 return retval |
188 Bot.new_remote_setBuilderList = cleanup | 192 Bot.new_remote_setBuilderList = cleanup |
189 Bot.remote_setBuilderList = Bot.new_remote_setBuilderList | 193 Bot.remote_setBuilderList = Bot.new_remote_setBuilderList |
190 | 194 |
191 | 195 |
192 def FixSubversionConfig(): | 196 def FixSubversionConfig(): |
193 if sys.platform == 'win32': | 197 if sys.platform == 'win32': |
194 dest = os.path.join(os.environ['APPDATA'], 'Subversion', 'config') | 198 dest = os.path.join(os.environ['APPDATA'], 'Subversion', 'config') |
195 else: | 199 else: |
196 dest = os.path.join(os.environ['HOME'], '.subversion', 'config') | 200 dest = os.path.join(os.environ['HOME'], '.subversion', 'config') |
197 shutil.copyfile('config', dest) | 201 shutil.copyfile('config', dest) |
198 | 202 |
199 | 203 |
200 def GetActiveSlavename(config_bootstrap): | |
201 active_slavename = os.environ.get('TESTING_SLAVENAME', slavename) | |
202 if active_slavename: | |
203 config_bootstrap.Master.active_slavename = active_slavename | |
204 else: | |
205 config_bootstrap.Master.active_slavename = ( | |
206 socket.getfqdn().split('.', 1)[0].lower()) | |
207 return active_slavename | |
208 | |
209 | |
210 def GetActiveMaster(slave_bootstrap, config_bootstrap, active_slavename): | 204 def GetActiveMaster(slave_bootstrap, config_bootstrap, active_slavename): |
211 master_name = os.environ.get( | 205 master_name = os.environ.get( |
212 'TESTING_MASTER', slave_bootstrap.GetActiveMaster(active_slavename)) | 206 'TESTING_MASTER', chromium_utils.GetActiveMaster(active_slavename)) |
213 if not master_name: | 207 if not master_name: |
214 raise RuntimeError('*** Failed to detect the active master') | 208 raise RuntimeError('*** Failed to detect the active master') |
215 slave_bootstrap.ImportMasterConfigs(master_name) | 209 slave_bootstrap.ImportMasterConfigs(master_name) |
216 if hasattr(config_bootstrap.Master, 'active_master'): | 210 if hasattr(config_bootstrap.Master, 'active_master'): |
217 # pylint: disable=E1101 | 211 # pylint: disable=E1101 |
218 return config_bootstrap.Master.active_master | 212 return config_bootstrap.Master.active_master |
219 if master_name and getattr(config_bootstrap.Master, master_name): | 213 if master_name and getattr(config_bootstrap.Master, master_name): |
220 master = getattr(config_bootstrap.Master, master_name) | 214 master = getattr(config_bootstrap.Master, master_name) |
221 config_bootstrap.Master.active_master = master | 215 config_bootstrap.Master.active_master = master |
222 return master | 216 return master |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 os.path.join(build_dir, 'third_party'), | 267 os.path.join(build_dir, 'third_party'), |
274 os.path.join(root_dir, 'build_internal', 'site_config'), | 268 os.path.join(root_dir, 'build_internal', 'site_config'), |
275 os.path.join(root_dir, 'build_internal', 'symsrc'), | 269 os.path.join(root_dir, 'build_internal', 'symsrc'), |
276 SCRIPT_PATH, # Include the current working directory by default. | 270 SCRIPT_PATH, # Include the current working directory by default. |
277 ] | 271 ] |
278 | 272 |
279 # Need to update sys.path prior to the following imports. | 273 # Need to update sys.path prior to the following imports. |
280 sys.path = python_path + sys.path | 274 sys.path = python_path + sys.path |
281 import slave.bootstrap | 275 import slave.bootstrap |
282 import config_bootstrap | 276 import config_bootstrap |
283 active_slavename = GetActiveSlavename(config_bootstrap) | 277 active_slavename = chromium_utils.GetActiveSlavename() |
284 active_master = GetActiveMaster(slave.bootstrap, config_bootstrap, | 278 config_bootstrap.Master.active_slavename = active_slavename |
285 active_slavename) | 279 active_master = GetActiveMaster( |
| 280 slave.bootstrap, config_bootstrap, active_slavename) |
286 | 281 |
287 bb_ver, tw_ver = GetThirdPartyVersions(active_master) | 282 bb_ver, tw_ver = GetThirdPartyVersions(active_master) |
288 python_path.append(os.path.join(build_dir, 'third_party', bb_ver)) | 283 python_path.append(os.path.join(build_dir, 'third_party', bb_ver)) |
289 python_path.append(os.path.join(build_dir, 'third_party', tw_ver)) | 284 python_path.append(os.path.join(build_dir, 'third_party', tw_ver)) |
290 sys.path.extend(python_path[-2:]) | 285 sys.path.extend(python_path[-2:]) |
291 | 286 |
292 os.environ['PYTHONPATH'] = ( | 287 os.environ['PYTHONPATH'] = ( |
293 os.pathsep.join(python_path) + os.pathsep + os.environ['PYTHONPATH']) | 288 os.pathsep.join(python_path) + os.pathsep + os.environ['PYTHONPATH']) |
294 | 289 |
295 os.environ['CHROME_HEADLESS'] = '1' | 290 os.environ['CHROME_HEADLESS'] = '1' |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 msg = '(%s) `gclient sync` failed; proceeding anyway...' % sys.argv[0] | 417 msg = '(%s) `gclient sync` failed; proceeding anyway...' % sys.argv[0] |
423 print >> sys.stderr, msg | 418 print >> sys.stderr, msg |
424 os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' | 419 os.environ['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' |
425 return True | 420 return True |
426 | 421 |
427 | 422 |
428 if '__main__' == __name__: | 423 if '__main__' == __name__: |
429 if UpdateScripts(): | 424 if UpdateScripts(): |
430 os.execv(sys.executable, [sys.executable] + sys.argv) | 425 os.execv(sys.executable, [sys.executable] + sys.argv) |
431 main() | 426 main() |
OLD | NEW |