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 build commands."""
6
7import cr
8
9
10class BuildCommand(cr.Command):
11  """The implementation of the build command.
12
13  This is a thin shell over the Builder.Build method of the selected builder.
14  """
15
16  def __init__(self):
17    super(BuildCommand, self).__init__()
18    self.help = 'Build a target'
19    self.description = ("""
20        Uses the specified builder for the platform to bring the target
21        up to date.
22        """)
23
24  def AddArguments(self, subparsers):
25    parser = super(BuildCommand, self).AddArguments(subparsers)
26    cr.Builder.AddArguments(self, parser)
27    cr.Target.AddArguments(self, parser, allow_multiple=True)
28    self.ConsumeArgs(parser, 'the builder')
29    return parser
30
31  def Run(self):
32    return cr.Builder.Build(
33        cr.Target.GetTargets(), cr.context.remains)
34
35
36class CleanCommand(cr.Command):
37  """The implementation of the clean command.
38
39  This is a thin shell over the Builder.Clean method of the selected builder.
40  """
41
42  def __init__(self):
43    super(CleanCommand, self).__init__()
44    self.help = 'Clean a target'
45    self.description = (
46        'Uses the specified builder to clean out built files for the target.')
47
48  def AddArguments(self, subparsers):
49    parser = super(CleanCommand, self).AddArguments(subparsers)
50    cr.Builder.AddArguments(self, parser)
51    cr.Target.AddArguments(self, parser, allow_multiple=True)
52    self.ConsumeArgs(parser, 'the builder')
53    return parser
54
55  def Run(self):
56    return cr.Builder.Clean(
57        cr.Target.GetTargets(), cr.context.remains)
58
59
60class RebuildCommand(cr.Command):
61  """The implementation of the rebuild command.
62
63  This is a thin shell over the Builder.Rebuild method of the selected builder.
64  """
65
66  def __init__(self):
67    super(RebuildCommand, self).__init__()
68    self.help = 'Rebuild a target'
69    self.description = (
70        'Uses the specified builder for the platform to rebuild a target.')
71
72  def AddArguments(self, subparsers):
73    parser = super(RebuildCommand, self).AddArguments(subparsers)
74    cr.Builder.AddArguments(self, parser)
75    cr.Target.AddArguments(self, parser, allow_multiple=True)
76    self.ConsumeArgs(parser, 'the builder')
77    return parser
78
79  def Run(self):
80    return cr.Builder.Rebuild(
81        cr.Target.GetTargets(), cr.context.remains)
82