示例#1
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 = []
示例#2
0
class GroupEngineTest(EngineTestBase, JvmTargetTest):
  @classmethod
  def setUpClass(cls):
    super(GroupEngineTest, cls).setUpClass()

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

  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 = []

  def tearDown(self):
    self.assertTrue(self.context.is_unlocked())

  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):
        super(RecordingTask, me).__init__(context)
        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)
示例#3
0
 def _execute(context, phases, print_timing):
   engine = GroupEngine(print_timing=print_timing)
   return engine.execute(context, phases)