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

Side by Side Diff: tools/cr/main.py

Issue 142933004: [cr tool] Make context implicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 9 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
« no previous file with comments | « tools/cr/cr/targets/target.py ('k') | 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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Chromium cr tool main module. 5 """Chromium cr tool main module.
6 6
7 Holds the main function and all it's support code. 7 Holds the main function and all it's support code.
8 """ 8 """
9 9
10 import os 10 import os
11 import sys 11 import sys
12 import cr 12 import cr
13 import cr.auto.user 13 import cr.auto.user
14 import cr.autocomplete 14 import cr.autocomplete
15 import cr.loader 15 import cr.loader
16 import cr.base.context
16 17
17 _CONTACT = 'iancottrell@chromium.org' 18 _CONTACT = 'iancottrell@chromium.org'
18 19
19 20
20 def Main(): 21 def Main():
21 """Chromium cr tool main function. 22 """Chromium cr tool main function.
22 23
23 This is the main entry point of the cr tool, it finds and loads all the 24 This is the main entry point of the cr tool, it finds and loads all the
24 plugins, creates the context and then activates and runs the specified 25 plugins, creates the context and then activates and runs the specified
25 command. 26 command.
26 """ 27 """
27 28
28 # Add the users plugin dir to the cr.auto.user package scan 29 # Add the users plugin dir to the cr.auto.user package scan
29 user_path = os.path.expanduser(os.path.join('~', '.config', 'cr')) 30 user_path = os.path.expanduser(os.path.join('~', '.config', 'cr'))
30 cr.auto.user.__path__.append(user_path) 31 cr.auto.user.__path__.append(user_path)
31 32
32 cr.loader.Scan() 33 cr.loader.Scan()
33 34
34 # Build the command context 35 # Build the command context
35 context = cr.Context( 36 with cr.base.context.Create(
36 description='The chrome dev build tool.', 37 description='The chrome dev build tool.',
37 epilog='Contact ' + _CONTACT + ' if you have issues with this tool.', 38 epilog='Contact ' + _CONTACT + ' if you have issues with this tool.',
38 ) 39 ) as context:
39 # Install the sub-commands
40 for command in cr.Command.Plugins():
41 context.AddSubParser(command)
42 40
43 # test for the special autocomplete command 41 # Try to detect the current client information
44 if context.autocompleting: 42 cr.base.client.DetectClient()
45 # After plugins are loaded so pylint: disable=g-import-not-at-top 43
46 cr.autocomplete.Complete(context) 44 # Install the sub-commands
47 return 45 for command in cr.Command.Plugins():
48 # Speculative argument processing to add config specific args 46 cr.context.AddSubParser(command)
49 context.ParseArgs(True) 47
50 cr.plugin.Activate(context) 48 # test for the special autocomplete command
51 # At this point we should know what command we are going to use 49 if cr.context.autocompleting:
52 command = cr.Command.GetActivePlugin(context) 50 # After plugins are loaded so pylint: disable=g-import-not-at-top
53 # Do some early processing, in case it changes the build dir 51 cr.autocomplete.Complete()
54 if command: 52 return
55 command.EarlyArgProcessing(context) 53 # Speculative argument processing to add config specific args
56 # Update the activated set again, in case the early processing changed it 54 cr.context.ParseArgs(True)
57 cr.plugin.Activate(context) 55 cr.plugin.Activate()
58 # Load the build specific configuration 56 # At this point we should know what command we are going to use
59 found_build_dir = cr.base.client.LoadConfig(context) 57 command = cr.Command.GetActivePlugin()
60 # Final processing or arguments 58 # Do some early processing, in case it changes the build dir
61 context.ParseArgs() 59 if command:
62 cr.plugin.Activate(context) 60 command.EarlyArgProcessing()
63 # If we did not get a command before, it might have been fixed. 61 # Update the activated set again, in case the early processing changed it
64 if command is None: 62 cr.plugin.Activate()
65 command = cr.Command.GetActivePlugin(context) 63 # Load the build specific configuration
66 # If the verbosity level is 3 or greater, then print the environment here 64 found_build_dir = cr.base.client.LoadConfig()
67 if context.verbose >= 3: 65 # Final processing or arguments
68 context.DumpValues(context.verbose > 3) 66 cr.context.ParseArgs()
69 if command is None: 67 cr.plugin.Activate()
70 print context.Substitute('No command specified.') 68 # If we did not get a command before, it might have been fixed.
71 exit(1) 69 if command is None:
72 if command.requires_build_dir: 70 command = cr.Command.GetActivePlugin()
73 if not found_build_dir: 71 # If the verbosity level is 3 or greater, then print the environment here
74 if not context.Find('CR_OUT_FULL'): 72 if cr.context.verbose >= 3:
75 print context.Substitute( 73 cr.context.DumpValues(cr.context.verbose > 3)
76 'No build directory specified. Please use cr init to make one.') 74 if command is None:
77 else: 75 print cr.context.Substitute('No command specified.')
78 print context.Substitute(
79 'Build {CR_BUILD_DIR} not a valid build directory')
80 exit(1) 76 exit(1)
81 if context.Find('CR_VERSION') != cr.base.client.VERSION: 77 if command.requires_build_dir:
82 print context.Substitute( 78 if not found_build_dir:
83 'Build {CR_BUILD_DIR} is for the wrong version of cr') 79 if not cr.context.Find('CR_OUT_FULL'):
84 print 'Please run cr init to reset it' 80 print cr.context.Substitute(
85 exit(1) 81 'No build directory specified. Please use cr init to make one.')
86 cr.Platform.Prepare(context) 82 else:
87 if context.verbose >= 1: 83 print cr.context.Substitute(
88 print context.Substitute( 84 'Build {CR_BUILD_DIR} not a valid build directory')
89 'Running cr ' + command.name + ' for {CR_BUILD_DIR}') 85 exit(1)
90 # Invoke the given command 86 if cr.context.Find('CR_VERSION') != cr.base.client.VERSION:
91 command.Run(context) 87 print cr.context.Substitute(
88 'Build {CR_BUILD_DIR} is for the wrong version of cr')
89 print 'Please run cr init to reset it'
90 exit(1)
91 cr.Platform.Prepare()
92 if cr.context.verbose >= 1:
93 print cr.context.Substitute(
94 'Running cr ' + command.name + ' for {CR_BUILD_DIR}')
95 # Invoke the given command
96 command.Run()
92 97
93 if __name__ == '__main__': 98 if __name__ == '__main__':
94 sys.exit(Main()) 99 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/cr/cr/targets/target.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698