Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: slave/run_slave.py

Issue 2094713002: Include PowerShell in Windows PATH, if available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Cleaner, better dox. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 """Issue reboot command according to platform type.""" 50 """Issue reboot command according to platform type."""
51 if sys.platform.startswith('win'): 51 if sys.platform.startswith('win'):
52 subprocess.call(['shutdown', '-r', '-f', '-t', '1']) 52 subprocess.call(['shutdown', '-r', '-f', '-t', '1'])
53 elif sys.platform in ('darwin', 'posix', 'linux2'): 53 elif sys.platform in ('darwin', 'posix', 'linux2'):
54 subprocess.call(['sudo', 'shutdown', '-r', 'now']) 54 subprocess.call(['sudo', 'shutdown', '-r', 'now'])
55 else: 55 else:
56 raise NotImplementedError('Implement IssueReboot function ' 56 raise NotImplementedError('Implement IssueReboot function '
57 'for %s' % sys.platform) 57 'for %s' % sys.platform)
58 58
59 59
60 def SigTerm(*args): 60 def SigTerm(*_args):
61 """Receive a SIGTERM and do nothing.""" 61 """Receive a SIGTERM and do nothing."""
62 Log('SigTerm: Received SIGTERM, doing nothing.') 62 Log('SigTerm: Received SIGTERM, doing nothing.')
63 63
64 64
65 def UpdateSignals(): 65 def UpdateSignals():
66 """Override the twisted SIGTERM handler with our own. 66 """Override the twisted SIGTERM handler with our own.
67 67
68 Ensure that the signal module is available and do nothing if it is not. 68 Ensure that the signal module is available and do nothing if it is not.
69 """ 69 """
70 try: 70 try:
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 python_path.append(os.path.join(BUILD_DIR, 'third_party', bb_ver)) 426 python_path.append(os.path.join(BUILD_DIR, 'third_party', bb_ver))
427 python_path.append(os.path.join(BUILD_DIR, 'third_party', tw_ver)) 427 python_path.append(os.path.join(BUILD_DIR, 'third_party', tw_ver))
428 sys.path = python_path[-2:] + sys.path 428 sys.path = python_path[-2:] + sys.path
429 429
430 os.environ['PYTHONPATH'] = ( 430 os.environ['PYTHONPATH'] = (
431 os.pathsep.join(python_path) + os.pathsep + os.environ['PYTHONPATH']) 431 os.pathsep.join(python_path) + os.pathsep + os.environ['PYTHONPATH'])
432 432
433 os.environ['CHROME_HEADLESS'] = '1' 433 os.environ['CHROME_HEADLESS'] = '1'
434 os.environ['PAGER'] = 'cat' 434 os.environ['PAGER'] = 'cat'
435 435
436 # Split the path into its components.
437 path_components = os.environ['PATH'].split(os.pathsep)
438 # This function identifies a PATH component that has the supplied phrase in
439 # one of its directories.
440 def get_path_component_containing(phrase):
agable 2016/06/24 18:29:16 This function is only used once, and is defined ne
dnj (Google) 2016/06/24 18:39:59 My thought was that it is OS-independent and seeme
441 phrase = phrase.lower()
442 for c in path_components:
443 if any(phrase == d.lower() for d in c.split(os.sep)):
444 return [c]
445 return []
446
436 # Platform-specific initialization. 447 # Platform-specific initialization.
437
438 if sys.platform.startswith('win'): 448 if sys.platform.startswith('win'):
439 # list of all variables that we want to keep 449 # list of all variables that we want to keep
440 env_var = [ 450 env_var = [
441 'APPDATA', 451 'APPDATA',
442 'BUILDBOT_ARCHIVE_FORCE_SSH', 452 'BUILDBOT_ARCHIVE_FORCE_SSH',
443 'CHROME_HEADLESS', 453 'CHROME_HEADLESS',
444 'CHROMIUM_BUILD', 454 'CHROMIUM_BUILD',
445 'COMMONPROGRAMFILES', 455 'COMMONPROGRAMFILES',
446 'COMMONPROGRAMFILES(X86)', 456 'COMMONPROGRAMFILES(X86)',
447 'COMMONPROGRAMW6432', 457 'COMMONPROGRAMW6432',
(...skipping 29 matching lines...) Expand all
477 'USERNAME', 487 'USERNAME',
478 'USERDOMAIN', 488 'USERDOMAIN',
479 'USERPROFILE', 489 'USERPROFILE',
480 'VS100COMNTOOLS', 490 'VS100COMNTOOLS',
481 'VS110COMNTOOLS', 491 'VS110COMNTOOLS',
482 'WINDIR', 492 'WINDIR',
483 ] 493 ]
484 494
485 remove_all_vars_except(os.environ, env_var) 495 remove_all_vars_except(os.environ, env_var)
486 496
487 # Extend the env variables with the chrome-specific settings. 497 # Extend the env variables with the chrome-specific settings. Tailor the
498 # slave process' (and derivative tasks') PATH environment variable.
488 slave_path = [ 499 slave_path = [
489 depot_tools, 500 depot_tools,
490 # Reuse the python executable used to start this script. 501 # Reuse the python executable used to start this script.
491 os.path.dirname(sys.executable), 502 os.path.dirname(sys.executable),
492 os.path.join(os.environ['SYSTEMROOT'], 'system32'), 503 os.path.join(os.environ['SYSTEMROOT'], 'system32'),
493 os.path.join(os.environ['SYSTEMROOT'], 'system32', 'WBEM'), 504 os.path.join(os.environ['SYSTEMROOT'], 'system32', 'WBEM'),
494 # Use os.sep to make this absolute, not relative. 505 # Use os.sep to make this absolute, not relative.
495 os.path.join(os.environ['SYSTEMDRIVE'], os.sep, 'Program Files', 506 os.path.join(os.environ['SYSTEMDRIVE'], os.sep, 'Program Files',
496 '7-Zip'), 507 '7-Zip'),
497 # TODO(hinoka): Remove this when its no longer needed crbug.com/481695 508 # TODO(hinoka): Remove this when its no longer needed crbug.com/481695
498 os.path.join(os.environ['SYSTEMDRIVE'], os.sep, 'cmake', 'bin'), 509 os.path.join(os.environ['SYSTEMDRIVE'], os.sep, 'cmake', 'bin'),
499 ] 510 ]
511
512 # Include Windows PowerShell in PATH, if defined. It does this by looking
513 # through the system path for an element containing a directory named
514 # "WindowsPowerShell", which is assumed to be the component adding
515 # PowerShell to the PATH.
516 slave_path += get_path_component_containing('WindowsPowerShell')
517
500 # build_internal/tools contains tools we can't redistribute. 518 # build_internal/tools contains tools we can't redistribute.
501 tools = os.path.join(ROOT_DIR, 'build_internal', 'tools') 519 tools = os.path.join(ROOT_DIR, 'build_internal', 'tools')
502 if os.path.isdir(tools): 520 if os.path.isdir(tools):
503 slave_path.append(os.path.abspath(tools)) 521 slave_path.append(os.path.abspath(tools))
504 os.environ['PATH'] = os.pathsep.join(slave_path) 522 os.environ['PATH'] = os.pathsep.join(slave_path)
505 os.environ['LOGNAME'] = os.environ['USERNAME'] 523 os.environ['LOGNAME'] = os.environ['USERNAME']
506 524
507 elif sys.platform in ('darwin', 'posix', 'linux2'): 525 elif sys.platform in ('darwin', 'posix', 'linux2'):
508 # list of all variables that we want to keep 526 # list of all variables that we want to keep
509 env_var = [ 527 env_var = [
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 if subprocess.call( 644 if subprocess.call(
627 [GetGClientPath(), 'sync', '--force', '--break_repo_locks'], 645 [GetGClientPath(), 'sync', '--force', '--break_repo_locks'],
628 env=EnvWithDepotTools()) != 0: 646 env=EnvWithDepotTools()) != 0:
629 print >> sys.stderr, ( 647 print >> sys.stderr, (
630 '(%s) `gclient sync` failed; proceeding anyway...' % sys.argv[0]) 648 '(%s) `gclient sync` failed; proceeding anyway...' % sys.argv[0])
631 os.execv(sys.executable, [sys.executable] + sys.argv + [skip_sync_arg]) 649 os.execv(sys.executable, [sys.executable] + sys.argv + [skip_sync_arg])
632 650
633 # Remove skip_sync_arg from arg list. Needed because twistd. 651 # Remove skip_sync_arg from arg list. Needed because twistd.
634 sys.argv.remove(skip_sync_arg) 652 sys.argv.remove(skip_sync_arg)
635 main() 653 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698