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. 4 5"""A module for the run command.""" 6 7import cr 8 9 10class RunCommand(cr.Command): 11 """The implementation of the run command. 12 13 This first uses Builder to bring the target up to date. 14 It then uses Installer to install the target (if needed), and 15 finally it uses Runner to run the target. 16 You can use skip version to not perform any of these steps. 17 """ 18 19 def __init__(self): 20 super(RunCommand, self).__init__() 21 self.help = 'Invoke a target' 22 23 def AddArguments(self, subparsers): 24 parser = super(RunCommand, self).AddArguments(subparsers) 25 cr.Builder.AddArguments(self, parser) 26 cr.Installer.AddArguments(self, parser) 27 cr.Runner.AddArguments(self, parser) 28 cr.Target.AddArguments(self, parser, allow_multiple=True) 29 self.ConsumeArgs(parser, 'the binary') 30 return parser 31 32 def Run(self): 33 targets = cr.Target.GetTargets() 34 test_targets = [target for target in targets if target.is_test] 35 run_targets = [target for target in targets if not target.is_test] 36 if cr.Installer.Skipping(): 37 # No installer, only build test targets 38 build_targets = test_targets 39 else: 40 build_targets = targets 41 if build_targets: 42 cr.Builder.Build(build_targets, []) 43 # See if we can use restart when not installing 44 if cr.Installer.Skipping(): 45 cr.Runner.Restart(targets, cr.context.remains) 46 else: 47 cr.Runner.Kill(run_targets, []) 48 cr.Installer.Reinstall(run_targets, []) 49 cr.Runner.Invoke(targets, cr.context.remains) 50 51