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