Пример #1
0
def register_sourceroot():
  try:
    yield SourceRoot.register
  except (ValueError, IndexError) as e:
    print("SourceRoot Registration Failed.")
    raise e
  finally:
    SourceRoot.reset()
Пример #2
0
 def setUpClass(self):
   super(TestPythonThriftBuilder, self).setUpClass()
   SourceRoot.register(os.path.realpath(os.path.join(self.build_root, 'test_thrift_replacement')),
                       PythonThriftLibrary)
   self.create_target('test_thrift_replacement', dedent('''
     python_thrift_library(name='one',
       sources=['thrift/keyword.thrift'],
       dependencies=None
     )
   '''))
Пример #3
0
  def setUpClass(cls):
    super(JarCreateExecuteTest, cls).setUpClass()
    cls.create_target('build-support/ivy',
                      dedent('''
                         repo(name = 'ivy',
                              url = 'https://art.twitter.biz/',
                              push_db = 'dummy.pushdb')
                       '''))

    def get_source_root_fs_path(path):
        return os.path.realpath(os.path.join(cls.build_root, path))

    SourceRoot.register(get_source_root_fs_path('src/resources'), Resources)
    SourceRoot.register(get_source_root_fs_path('src/java'), JavaLibrary)
    SourceRoot.register(get_source_root_fs_path('src/scala'), ScalaLibrary)
    SourceRoot.register(get_source_root_fs_path('src/thrift'), JavaThriftLibrary)

    cls.res = cls.create_resources('src/resources/com/twitter', 'spam', 'r.txt')
    cls.jl = cls.java_library('src/java/com/twitter', 'foo', ['a.java'],
                              resources='src/resources/com/twitter:spam')
    cls.sl = cls.scala_library('src/scala/com/twitter', 'bar', ['c.scala'])
    cls.jtl = cls.java_thrift_library('src/thrift/com/twitter', 'baz', 'd.thrift')
    cls.java_lib_foo= cls.java_library('src/java/com/twitter/foo', 'java_foo', ['java_foo.java'])
    cls.scala_lib = cls.scala_library('src/scala/com/twitter/foo',
                                      'scala_foo',
                                      ['scala_foo.scala'],
                                      provides=True,
                                      java_sources=['src/java/com/twitter/foo:java_foo'])
Пример #4
0
  def __init__(self, name, sources=None, exclusives=None):
    Target.__init__(self, name, exclusives=exclusives)

    self.add_labels('sources')
    self.target_base = SourceRoot.find(self)
    self._unresolved_sources = sources or []
    self._resolved_sources = None
Пример #5
0
  def setUpClass(cls):
    super(JarCreateExecuteTest, cls).setUpClass()

    def get_source_root_fs_path(path):
        return os.path.realpath(os.path.join(cls.build_root, path))

    SourceRoot.register(get_source_root_fs_path('src/resources'), Resources)
    SourceRoot.register(get_source_root_fs_path('src/java'), JavaLibrary)
    SourceRoot.register(get_source_root_fs_path('src/scala'), ScalaLibrary)
    SourceRoot.register(get_source_root_fs_path('src/thrift'), JavaThriftLibrary)

    cls.res = cls.resources('src/resources/com/twitter', 'spam', 'r.txt')
    cls.jl = cls.java_library('src/java/com/twitter', 'foo', ['a.java'],
                              resources='src/resources/com/twitter:spam')
    cls.sl = cls.scala_library('src/scala/com/twitter', 'bar', ['c.scala'])
    cls.jtl = cls.java_thrift_library('src/thrift/com/twitter', 'baz', 'd.thrift')
Пример #6
0
  def console_output(self, _):
    buildfiles = OrderedSet()
    if self._dependees_type:
      base_paths = OrderedSet()
      for dependees_type in self._dependees_type:
        try:
          # Try to do a fully qualified import 1st for filtering on custom types.
          from_list, module, type_name = dependees_type.rsplit('.', 2)
          __import__('%s.%s' % (from_list, module), fromlist=[from_list])
        except (ImportError, ValueError):
          # Fall back on pants provided target types.
          if hasattr(pants.base.build_file_context, dependees_type):
            type_name = getattr(pants.base.build_file_context, dependees_type)
          else:
            raise TaskError('Invalid type name: %s' % dependees_type)
        # Find the SourceRoot for the given input type
        base_paths.update(SourceRoot.roots(type_name))
      if not base_paths:
        raise TaskError('No SourceRoot set for any target type in %s.' % self._dependees_type +
                        '\nPlease define a source root in BUILD file as:' +
                        '\n\tsource_root(\'<src-folder>\', %s)' % ', '.join(self._dependees_type))
      for base_path in base_paths:
        buildfiles.update(BuildFile.scan_buildfiles(get_buildroot(), base_path))
    else:
      buildfiles = BuildFile.scan_buildfiles(get_buildroot())

    dependees_by_target = defaultdict(set)
    for buildfile in buildfiles:
      for address in Target.get_all_addresses(buildfile):
        for target in Target.get(address).resolve():
          # TODO(John Sirois): tighten up the notion of targets written down in a BUILD by a
          # user vs. targets created by pants at runtime.
          target = self.get_concrete_target(target)
          if hasattr(target, 'dependencies'):
            for dependencies in target.dependencies:
              for dependency in dependencies.resolve():
                dependency = self.get_concrete_target(dependency)
                dependees_by_target[dependency].add(target)

    roots = set(self.context.target_roots)
    if self._closed:
      for root in roots:
        yield str(root.address)

    for dependant in self.get_dependants(dependees_by_target, roots):
      yield str(dependant.address)
Пример #7
0
 def root(path, *types):
   SourceRoot.register(os.path.join(basedir, path) if basedir else path, *types)
Пример #8
0
 def _create_new_target(self, target_base, target_type, *args, **kwargs):
   if not os.path.exists(target_base):
     os.makedirs(target_base)
   SourceRoot.register(target_base, target_type)
   with ParseContext.temp(target_base):
     return target_type(*args, **kwargs)
Пример #9
0
 def setUpClass(cls):
   super(TargetsHelpTest, cls).setUpClass()
   SourceRoot.register(os.path.join(get_buildroot(), 'fakeroot'), TargetsHelpTest.MyTarget)
Пример #10
0
 def tearDownClass(cls):
   BuildRoot().reset()
   SourceRoot.reset()
   safe_rmtree(cls.build_root)
Пример #11
0
 def __init__(self, basedir, *allowed_target_types):
   SourceRoot.register(os.path.join(buildfile_dir, basedir), *allowed_target_types)
Пример #12
0
 def here(*allowed_target_types):
   """Registers the cwd as a source root for the given target types."""
   SourceRoot.register(buildfile_dir, *allowed_target_types)
Пример #13
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 '*')
Пример #14
0
 def _set_up_mocks(self, class_type, src_roots):
   self.mox.StubOutWithMock(SourceRoot, 'roots')
   SourceRoot.roots(class_type).AndReturn(src_roots)
   self.mox.ReplayAll()