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
3 # found in the LICENSE file.
5 """Chromium cr tool main module.
7 Holds the main function and all it's support code.
14 _CONTACT
= 'iancottrell@chromium.org'
18 """Chromium cr tool main function.
20 This is the main entry point of the cr tool, it finds and loads all the
21 plugins, creates the context and then activates and runs the specified
25 # Add the users plugin dir to the cr.auto.user package scan
26 user_path
= os
.path
.expanduser(os
.path
.join('~', '.config', 'cr'))
27 cr
.auto
.user
.__path
__.append(user_path
)
31 # Build the command context
32 with cr
.base
.context
.Create(
33 description
='The chrome dev build tool.',
34 epilog
='Contact ' + _CONTACT
+ ' if you have issues with this tool.',
37 # Try to detect the current client information
38 cr
.base
.client
.DetectClient()
40 # Install the sub-commands
41 for command
in cr
.Command
.Plugins():
42 cr
.context
.AddSubParser(command
)
44 # test for the special autocomplete command
45 if cr
.context
.autocompleting
:
46 # After plugins are loaded so pylint: disable=g-import-not-at-top
47 cr
.autocomplete
.Complete()
49 # Speculative argument processing to add config specific args
50 cr
.context
.ParseArgs(True)
52 # At this point we should know what command we are going to use
53 command
= cr
.Command
.GetActivePlugin()
54 # Do some early processing, in case it changes the build dir
56 command
.EarlyArgProcessing()
57 # Update the activated set again, in case the early processing changed it
59 # Load the build specific configuration
60 found_build_dir
= cr
.base
.client
.LoadConfig()
61 # Final processing or arguments
63 cr
.context
.ParseArgs()
64 # If we did not get a command before, it might have been fixed.
66 command
= cr
.Command
.GetActivePlugin()
67 # If the verbosity level is 3 or greater, then print the environment here
68 if cr
.context
.verbose
>= 3:
69 cr
.context
.DumpValues(cr
.context
.verbose
> 3)
71 print cr
.context
.Substitute('No command specified.')
73 if command
.requires_build_dir
:
74 if not found_build_dir
:
75 if not cr
.context
.Find('CR_OUT_FULL'):
76 print cr
.context
.Substitute(
77 'No build directory specified. Please use cr init to make one.')
79 print cr
.context
.Substitute(
80 'Build {CR_BUILD_DIR} not a valid build directory')
82 if cr
.context
.Find('CR_VERSION') != cr
.base
.client
.VERSION
:
83 print cr
.context
.Substitute(
84 'Build {CR_BUILD_DIR} is for the wrong version of cr')
85 print 'Please run cr init to reset it'
88 if cr
.context
.verbose
>= 1:
89 print cr
.context
.Substitute(
90 'Running cr ' + command
.name
+ ' for {CR_BUILD_DIR}')
91 # Invoke the given command
94 if __name__
== '__main__':