prepare.py revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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 prepare command."""
6
7import cr
8
9
10class PrepareCommand(cr.Command):
11  """The implementation of the prepare command.
12
13  The prepare command is used to perform  the steps needed to get an output
14  directory ready to use. These should not be the kind of things that need to
15  happen every time you build something, but the rarer things that you re-do
16  only when you get or add new source files, or change your build options.
17  This delegates all it's behavior to implementations of PrepareOut. These will
18  (mostly) be in the cr.actions package.
19  """
20
21  def __init__(self):
22    super(PrepareCommand, self).__init__()
23    self.help = 'Prepares an output directory'
24    self.description = ("""
25        This does any preparation needed for the output directory, such as
26        running gyp.
27        """)
28
29  def Run(self):
30    self.Prepare()
31
32  @classmethod
33  def UpdateContext(cls):
34    for preparation in PrepareOut.Plugins():
35      preparation.UpdateContext()
36
37  @classmethod
38  def Prepare(cls):
39    cls.UpdateContext()
40    for preparation in PrepareOut.Plugins():
41      preparation.Prepare()
42
43
44class PrepareOut(cr.Plugin, cr.Plugin.Type):
45  """Base class for output directory preparation plugins.
46
47  See PrepareCommand for details.
48  """
49
50  def UpdateContext(self):
51    """Update the context if needed.
52
53    This is also used by commands that want the environment setup correctly, but
54    are not going to call Prepare directly (such as sync)."""
55
56  def Prepare(self):
57    """All PrepareOut plugins must override this method to do their work."""
58    raise NotImplementedError('Must be overridden.')
59
60