Beispiel #1
0
class BuildCommand(CommandBase):
  """This class represents build command."""

  DEFAULT_TARGETS = [":all"]

  def __init__(self, config=None, project_filesystem=None, console=None,
               artifact_cache=None, step_runner=None):
    CommandBase.__init__(self, config, project_filesystem, console)
    self._artifact_cache   = artifact_cache or ArtifactCachePlug()
    self._step_runner      = step_runner or DefaultStepRunner()
    self._dependency_graph = None
    self._parser           = None

  def get_dependency_graph(self):
    return self._dependency_graph

  def get_parser(self):
    return self._parser

  @classmethod
  def setup_command_line_arguments_parser(cls, parser):
    parser.epilog = "Builds the specified target(s)."
    parser.usage = "\n%(prog)s (options) [targets]\n"
    parser.add_argument("targets", metavar="TARGET", type=str, nargs="*")

  def execute(self, arguments):
    """Executes build process. By default DEFAULT_TARGETS will be taken as
    starting points.
    """
    names = (arguments.get("targets") if len(arguments.get("targets"))
             else BuildCommand.DEFAULT_TARGETS)
    known_rule_types = KnownRuleTypes()
    self._parser = Parser(self._config, self._project_filesystem, self._console,
                          known_rule_types)
    targets = self._parser.parse_build_files_for_target_names(names)
    raw_build_target_table = self._parser.get_raw_build_target_table()
    self._dependency_graph = DependencyGraphBuilder(self._config).build(
      raw_build_target_table, known_rule_types)
    build_context = BuildContext(artifact_cache=self._artifact_cache,
                                 console=self._console,
                                 project_filesystem=self._project_filesystem,
                                 dependency_graph=self._dependency_graph,
                                 step_runner=self._step_runner)
    for target in targets:
      rule = self._dependency_graph.find_rule_by_target(target)
      rule.build(build_context)
    return 0

  def cleanup(self):
    pass
Beispiel #2
0
 def execute(self, arguments):
   """Executes build process. By default DEFAULT_TARGETS will be taken as
   starting points.
   """
   names = (arguments.get("targets") if len(arguments.get("targets"))
            else BuildCommand.DEFAULT_TARGETS)
   known_rule_types = KnownRuleTypes()
   self._parser = Parser(self._config, self._project_filesystem, self._console,
                         known_rule_types)
   targets = self._parser.parse_build_files_for_target_names(names)
   raw_build_target_table = self._parser.get_raw_build_target_table()
   self._dependency_graph = DependencyGraphBuilder(self._config).build(
     raw_build_target_table, known_rule_types)
   build_context = BuildContext(artifact_cache=self._artifact_cache,
                                console=self._console,
                                project_filesystem=self._project_filesystem,
                                dependency_graph=self._dependency_graph,
                                step_runner=self._step_runner)
   for target in targets:
     rule = self._dependency_graph.find_rule_by_target(target)
     rule.build(build_context)
   return 0