Пример #1
0
    def test_reset(self):
        self._assert_source_root_empty()
        SourceRoot.register("tests", TestTarget)
        self.assertEquals({"tests": OrderedSet([TestTarget])}, SourceRoot.all_roots())

        SourceRoot.reset()

        self._assert_source_root_empty()
Пример #2
0
  def test_reset(self):
    self._assert_source_root_empty()
    SourceRoot.register("tests", TestTarget)
    self.assertEquals({"tests": OrderedSet([TestTarget])}, SourceRoot.all_roots())

    SourceRoot.reset()

    self._assert_source_root_empty()
Пример #3
0
    def test_register_none(self):
        self._assert_source_root_empty()

        SourceRoot.register("tests")
        self.assertEquals({"tests": OrderedSet()}, SourceRoot.all_roots())
        self.assertEquals(OrderedSet(), SourceRoot.types("tests"))
        self.assertEquals("tests", SourceRoot.find(TestTarget("//tests/foo/bar:baz")))
        self.assertEquals("tests", SourceRoot.find_by_path("tests/foo/bar"))
Пример #4
0
    def test_register(self):
        self._assert_source_root_empty()

        SourceRoot.register("tests", TestTarget)

        self.assertEquals({"tests": OrderedSet([TestTarget])}, SourceRoot.all_roots())
        self.assertEquals(OrderedSet([TestTarget]), SourceRoot.types("tests"))
        self.assertEquals(OrderedSet(["tests"]), SourceRoot.roots(TestTarget))
Пример #5
0
  def test_register_none(self):
    self._assert_source_root_empty()

    SourceRoot.register("tests", )
    self.assertEquals({"tests": OrderedSet()}, SourceRoot.all_roots())
    self.assertEquals(OrderedSet(), SourceRoot.types("tests"))
    self.assertEquals("tests", SourceRoot.find(TestTarget("//tests/foo/bar:baz")))
    self.assertEquals("tests", SourceRoot.find_by_path("tests/foo/bar"))
Пример #6
0
  def test_register(self):
    self._assert_source_root_empty()

    SourceRoot.register("tests", TestTarget)

    self.assertEquals({"tests": OrderedSet([TestTarget])}, SourceRoot.all_roots())
    self.assertEquals(OrderedSet([TestTarget]), SourceRoot.types("tests"))
    self.assertEquals(OrderedSet(["tests"]), SourceRoot.roots(TestTarget))
Пример #7
0
    def generate_targets(self, local_go_targets):
        # TODO(John Sirois): support multiple source roots like GOPATH does?
        # The GOPATH's 1st element is read-write, the rest are read-only; ie: their sources build to
        # the 1st element's pkg/ and bin/ dirs.
        all_rooted_types = set()
        for types in SourceRoot.all_roots().values():
            all_rooted_types.update(types)

        def safe_get_source_roots(target_type):
            return set(SourceRoot.roots(
                target_type)) if target_type in all_rooted_types else set()

        local_roots = safe_get_source_roots(GoBinary) | safe_get_source_roots(
            GoLibrary)
        if not local_roots:
            raise self.NoLocalRootsError(
                'Can only BUILD gen if a Go local sources source root is'
                'defined.')
        if len(local_roots) > 1:
            raise self.InvalidLocalRootsError(
                'Can only BUILD gen for a single Go local sources source '
                'root, found:\n\t{}'.format('\n\t'.join(sorted(local_roots))))
        local_root = local_roots.pop()
        unrooted_locals = {
            t
            for t in local_go_targets if t.target_base != local_root
        }
        if unrooted_locals:
            raise self.UnrootedLocalSourceError(
                'Cannot BUILD gen until the following targets are '
                'relocated to the build root at {}:\n\t{}'.format(
                    local_root, '\n\t'.join(
                        sorted(t.address.reference()
                               for t in unrooted_locals))))

        remote_roots = set(safe_get_source_roots(GoRemoteLibrary))
        if len(remote_roots) > 1:
            raise self.InvalidRemoteRootsError(
                'Can only BUILD gen for a single Go remote library source '
                'root, found:\n\t{}'.format('\n\t'.join(sorted(remote_roots))))
        remote_root = remote_roots.pop() if remote_roots else None

        generator = GoTargetGenerator(
            self.context.new_workunit,
            self.go_dist,
            self.context.build_graph,
            local_root,
            Fetchers.global_instance(),
            generate_remotes=self.get_options().remote,
            remote_root=remote_root)
        with self.context.new_workunit('go.buildgen',
                                       labels=[WorkUnitLabel.MULTITOOL]):
            try:
                return generator.generate(local_go_targets)
            except generator.GenerationError as e:
                raise self.GenerationError(e)
Пример #8
0
    def check_buildroot(self, buildroot_path):
        self._assert_source_root_empty()

        SourceRoot.register(buildroot_path, TestTarget)

        self.assertEquals({".": OrderedSet([TestTarget])}, SourceRoot.all_roots())
        self.assertEquals(OrderedSet([TestTarget]), SourceRoot.types("."))
        self.assertEquals(OrderedSet(["."]), SourceRoot.roots(TestTarget))

        target = TestTarget("//mock/foo/bar:baz")
        self.assertEqual("", SourceRoot.find(target))
Пример #9
0
  def check_buildroot(self, buildroot_path):
    self._assert_source_root_empty()

    SourceRoot.register(buildroot_path, TestTarget)

    self.assertEquals({".": OrderedSet([TestTarget])}, SourceRoot.all_roots())
    self.assertEquals(OrderedSet([TestTarget]), SourceRoot.types("."))
    self.assertEquals(OrderedSet(["."]), SourceRoot.roots(TestTarget))

    target = TestTarget("//mock/foo/bar:baz")
    self.assertEqual("", SourceRoot.find(target))
Пример #10
0
  def generate_targets(self, local_go_targets):
    # TODO(John Sirois): support multiple source roots like GOPATH does?
    # The GOPATH's 1st element is read-write, the rest are read-only; ie: their sources build to
    # the 1st element's pkg/ and bin/ dirs.
    all_rooted_types = set()
    for types in SourceRoot.all_roots().values():
      all_rooted_types.update(types)

    def safe_get_source_roots(target_type):
      return set(SourceRoot.roots(target_type)) if target_type in all_rooted_types else set()

    local_roots = safe_get_source_roots(GoBinary) | safe_get_source_roots(GoLibrary)
    if not local_roots:
      raise self.NoLocalRootsError('Can only BUILD gen if a Go local sources source root is'
                                   'defined.')
    if len(local_roots) > 1:
      raise self.InvalidLocalRootsError('Can only BUILD gen for a single Go local sources source '
                                        'root, found:\n\t{}'
                                        .format('\n\t'.join(sorted(local_roots))))
    local_root = local_roots.pop()
    unrooted_locals = {t for t in local_go_targets if t.target_base != local_root}
    if unrooted_locals:
      raise self.UnrootedLocalSourceError('Cannot BUILD gen until the following targets are '
                                          'relocated to the build root at {}:\n\t{}'
                                          .format(local_root,
                                                  '\n\t'.join(sorted(t.address.reference()
                                                                     for t in unrooted_locals))))

    remote_roots = set(safe_get_source_roots(GoRemoteLibrary))
    if len(remote_roots) > 1:
      raise self.InvalidRemoteRootsError('Can only BUILD gen for a single Go remote library source '
                                         'root, found:\n\t{}'
                                         .format('\n\t'.join(sorted(remote_roots))))
    remote_root = remote_roots.pop() if remote_roots else None

    generator = GoTargetGenerator(self.context.new_workunit,
                                  self.go_dist,
                                  self.context.build_graph,
                                  local_root,
                                  Fetchers.global_instance(),
                                  generate_remotes=self.get_options().remote,
                                  remote_root=remote_root)
    with self.context.new_workunit('go.buildgen', labels=[WorkUnitLabel.MULTITOOL]):
      try:
        return generator.generate(local_go_targets)
      except generator.GenerationError as e:
        raise self.GenerationError(e)
Пример #11
0
 def _assert_source_root_empty(self):
     self.assertEqual({}, SourceRoot.all_roots())
     with self.assertRaises(KeyError):
         self.assertEqual(set(), SourceRoot.types("tests"))
     with self.assertRaises(KeyError):
         self.assertEqual(set(), SourceRoot.roots(TestTarget))
Пример #12
0
 def console_output(self, targets):
   for src_root, targets in SourceRoot.all_roots().items():
     all_targets = ','.join(sorted([tgt.__name__ for tgt in targets]))
     yield '%s: %s' % (src_root, all_targets or '*')
Пример #13
0
 def _assert_source_root_empty(self):
     self.assertEqual({}, SourceRoot.all_roots())
     with self.assertRaises(KeyError):
         self.assertEqual(set(), SourceRoot.types("tests"))
     with self.assertRaises(KeyError):
         self.assertEqual(set(), SourceRoot.roots(TestTarget))