Esempio n. 1
0
  def setUp(self):
    super(GroupEngineTest, self).setUp()

    self.java_library('src/java', 'a')
    self.scala_library('src/scala', 'b', deps=['src/java:a'])
    self.java_library('src/java', 'c', deps=['src/scala:b'])
    self.scala_library('src/scala', 'd', deps=['src/java:c'])
    self.java_library('src/java', 'e', deps=['src/scala:d'])
    self.python_library('src/python', 'f')

    self.context = create_context(options=dict(explain=False),
                                  target_roots=self.targets('src/java:e', 'src/python:f'),
                                  build_graph=self.build_graph,
                                  build_file_parser=self.build_file_parser)
    self.assertTrue(self.context.is_unlocked())

    # TODO(John Sirois): disentangle GroupEngine from relying upon the CheckExclusives task being
    # run.  It should either arrange this directly or else the requirement should be in a different
    # layer.
    exclusives_mapping = ExclusivesMapping(self.context)
    exclusives_mapping._populate_target_maps(self.context.targets())
    self.context.products.safe_create_data('exclusives_groups', lambda: exclusives_mapping)

    self.engine = GroupEngine()
    self.recorded_actions = []
Esempio n. 2
0
    def run(self, lock):
        # TODO(John Sirois): Consider moving to straight python logging.  The divide between the
        # context/work-unit logging and standard python logging doesn't buy us anything.

        # Enable standard python logging for code with no handle to a context/work-unit.
        if self.options.log_level:
            LogOptions.set_stderr_log_level((self.options.log_level
                                             or 'info').upper())
            logdir = self.options.logdir or self.config.get(
                'goals', 'logdir', default=None)
            if logdir:
                safe_mkdir(logdir)
                LogOptions.set_log_dir(logdir)
                log.init('goals')
            else:
                log.init()

        # Update the reporting settings, now that we have flags etc.
        def is_console_task():
            for phase in self.phases:
                for goal in phase.goals():
                    if issubclass(goal.task_type, ConsoleTask):
                        return True
            return False

        is_explain = self.options.explain
        update_reporting(self.options,
                         is_console_task() or is_explain, self.run_tracker)

        context = Context(self.config,
                          self.options,
                          self.run_tracker,
                          self.targets,
                          requested_goals=self.requested_goals,
                          build_graph=self.build_graph,
                          build_file_parser=self.build_file_parser,
                          lock=lock)

        unknown = []
        for phase in self.phases:
            if not phase.goals():
                unknown.append(phase)

        if unknown:
            context.log.error('Unknown goal(s): %s\n' %
                              ' '.join(phase.name for phase in unknown))
            return 1

        engine = GroupEngine()
        return engine.execute(context, self.phases)
Esempio n. 3
0
  def run(self, lock):
    # TODO(John Sirois): Consider moving to straight python logging.  The divide between the
    # context/work-unit logging and standard python logging doesn't buy us anything.

    # Enable standard python logging for code with no handle to a context/work-unit.
    if self.options.log_level:
      LogOptions.set_stderr_log_level((self.options.log_level or 'info').upper())
      logdir = self.options.logdir or self.config.get('goals', 'logdir', default=None)
      if logdir:
        safe_mkdir(logdir)
        LogOptions.set_log_dir(logdir)
        log.init('goals')
      else:
        log.init()

    # Update the reporting settings, now that we have flags etc.
    def is_console_task():
      for phase in self.phases:
        for goal in phase.goals():
          if issubclass(goal.task_type, ConsoleTask):
            return True
      return False

    is_explain = self.options.explain
    update_reporting(self.options, is_console_task() or is_explain, self.run_tracker)

    context = Context(
      self.config,
      self.options,
      self.run_tracker,
      self.targets,
      requested_goals=self.requested_goals,
      build_graph=self.build_graph,
      build_file_parser=self.build_file_parser,
      lock=lock)

    unknown = []
    for phase in self.phases:
      if not phase.goals():
        unknown.append(phase)

    if unknown:
      context.log.error('Unknown goal(s): %s\n' % ' '.join(phase.name for phase in unknown))
      return 1

    engine = GroupEngine()
    return engine.execute(context, self.phases)
Esempio n. 4
0
  def setUp(self):
    super(GroupEngineTest, self).setUp()

    self.context = create_context(options=dict(explain=False),
                                  target_roots=self.targets('src/java:e', 'src/python:f'))
    self.assertTrue(self.context.is_unlocked())

    # TODO(John Sirois): disentangle GroupEngine from relying upon the CheckExclusives task being
    # run.  It should either arrange this directly or else the requirement should be in a different
    # layer.
    exclusives_mapping = ExclusivesMapping(self.context)
    exclusives_mapping._populate_target_maps(self.context.targets())
    self.context.products.safe_create_data('exclusives_groups', lambda: exclusives_mapping)

    self.engine = GroupEngine(print_timing=False)
    self.recorded_actions = []
Esempio n. 5
0
 def _execute(context, phases, print_timing):
   engine = GroupEngine(print_timing=print_timing)
   return engine.execute(context, phases)
Esempio n. 6
0
class GroupEngineTest(EngineTestBase, JvmTargetTest):
  def setUp(self):
    super(GroupEngineTest, self).setUp()

    self.java_library('src/java', 'a')
    self.scala_library('src/scala', 'b', deps=['src/java:a'])
    self.java_library('src/java', 'c', deps=['src/scala:b'])
    self.scala_library('src/scala', 'd', deps=['src/java:c'])
    self.java_library('src/java', 'e', deps=['src/scala:d'])
    self.python_library('src/python', 'f')

    self.context = create_context(options=dict(explain=False),
                                  target_roots=self.targets('src/java:e', 'src/python:f'),
                                  build_graph=self.build_graph,
                                  build_file_parser=self.build_file_parser)
    self.assertTrue(self.context.is_unlocked())

    # TODO(John Sirois): disentangle GroupEngine from relying upon the CheckExclusives task being
    # run.  It should either arrange this directly or else the requirement should be in a different
    # layer.
    exclusives_mapping = ExclusivesMapping(self.context)
    exclusives_mapping._populate_target_maps(self.context.targets())
    self.context.products.safe_create_data('exclusives_groups', lambda: exclusives_mapping)

    self.engine = GroupEngine()
    self.recorded_actions = []

  def tearDown(self):
    self.assertTrue(self.context.is_unlocked())
    super(GroupEngineTest, self).tearDown()

  def construct_action(self, tag):
    return 'construct', tag, self.context

  def execute_action(self, tag, targets=None):
    return 'execute', tag, (targets or self.context.targets())

  def record(self, tag):
    class RecordingTask(Task):
      def __init__(me, context, workdir):
        super(RecordingTask, me).__init__(context, workdir)
        self.recorded_actions.append(self.construct_action(tag))

      def execute(me, targets):
        self.recorded_actions.append(self.execute_action(tag, targets=targets))

    return RecordingTask

  def install_goal(self, name, group=None, dependencies=None, phase=None):
    return self.installed_goal(name,
                               action=self.record(name),
                               group=group,
                               dependencies=dependencies,
                               phase=phase)

  def test_no_groups(self):
    self.install_goal('resolve')
    self.install_goal('javac', dependencies=['resolve'], phase='compile')
    self.install_goal('checkstyle', phase='compile')
    self.install_goal('resources')
    self.install_goal('test', dependencies=['compile', 'resources'])

    result = self.engine.execute(self.context, self.as_phases('test'))
    self.assertEqual(0, result)

    expected = [self.construct_action('test'),
                self.construct_action('resources'),
                self.construct_action('checkstyle'),
                self.construct_action('javac'),
                self.construct_action('resolve'),
                self.execute_action('resolve'),
                self.execute_action('javac'),
                self.execute_action('checkstyle'),
                self.execute_action('resources'),
                self.execute_action('test')]
    self.assertEqual(expected, self.recorded_actions)

  def test_groups(self):
    self.install_goal('resolve')
    self.install_goal('javac',
                      group=Group('jvm', lambda t: t.is_java),
                      dependencies=['resolve'],
                      phase='compile')
    self.install_goal('scalac',
                      group=Group('jvm', lambda t: t.is_scala),
                      dependencies=['resolve'],
                      phase='compile')
    self.install_goal('checkstyle', phase='compile')

    result = self.engine.execute(self.context, self.as_phases('compile'))
    self.assertEqual(0, result)

    expected = [self.construct_action('checkstyle'),
                self.construct_action('scalac'),
                self.construct_action('javac'),
                self.construct_action('resolve'),
                self.execute_action('resolve'),
                self.execute_action('javac', targets=self.targets('src/java:a')),
                self.execute_action('scalac', targets=self.targets('src/scala:b')),
                self.execute_action('javac', targets=self.targets('src/java:c')),
                self.execute_action('scalac', targets=self.targets('src/scala:d')),
                self.execute_action('javac', targets=self.targets('src/java:e')),
                self.execute_action('checkstyle')]
    self.assertEqual(expected, self.recorded_actions)