Example #1
0
 def test_nobases(self):
   """Tests exception handling if build support urls are improperly specified."""
   try:
     util = BinaryUtil(config=self.config_urls())
     with util.select_binary_stream('bin/foo', '4.4.3', 'foo') as stream:
       self.fail('We should have gotten a "NoBaseUrlsError".')
   except BinaryUtil.NoBaseUrlsError as e:
     pass # expected
Example #2
0
 def test_nobases(self):
   """Tests exception handling if build support urls are improperly specified."""
   try:
     util = BinaryUtil(config=self.config_urls())
     with util.select_binary_stream('bin/foo', '4.4.3', 'foo') as stream:
       self.fail('We should have gotten a "NoBaseUrlsError".')
   except BinaryUtil.NoBaseUrlsError as e:
     pass # expected
Example #3
0
 def _seens_test(self, binaries, bases, reader, config=None):
     unseen = [item for item in reader.values() if item.startswith('SEEN ')]
     if not config:
         config = self.config_urls(bases)
     util = BinaryUtil(config=config)
     for key in binaries:
         base_path, version, name = binaries[key]
         with util.select_binary_stream(base_path,
                                        version,
                                        name,
                                        url_opener=reader) as stream:
             self.assertEqual(stream(), 'SEEN ' + key.upper())
             unseen.remove(stream())
     self.assertEqual(0, len(unseen))  # Make sure we've seen all the SEENs.
Example #4
0
 def _seens_test(self, binaries, bases, reader, config=None):
   unseen = [item for item in reader.values() if item.startswith('SEEN ')]
   if not config:
     config = self.config_urls(bases)
   util = BinaryUtil(config=config)
   for key in binaries:
     base_path, version, name = binaries[key]
     with util.select_binary_stream(base_path,
                                    version,
                                    name,
                                    url_opener=reader) as stream:
       self.assertEqual(stream(), 'SEEN ' + key.upper())
       unseen.remove(stream())
   self.assertEqual(0, len(unseen)) # Make sure we've seen all the SEENs.
Example #5
0
def select_thrift_binary(options):
  """Selects a thrift compiler binary matching the current os and architecture.

  :param Options options: options for the current task
  Defaults to the thrift compiler version specified in the gen.thrift options scope.
  """
  return BinaryUtil.from_options(options).select_binary('thrift')
Example #6
0
    def __init__(self, *args, **kwargs):
        super(ProtobufGen, self).__init__(*args, **kwargs)

        self.protoc_supportdir = self.context.config.get(
            'protobuf-gen',
            'supportdir',
            default=_PROTOBUF_GEN_SUPPORTDIR_DEFAULT)
        self.protoc_version = self.context.config.get(
            'protobuf-gen', 'version', default=_PROTOBUF_VERSION_DEFAULT)
        self.plugins = self.context.config.getlist('protobuf-gen',
                                                   'plugins',
                                                   default=[])

        self.java_out = os.path.join(self.workdir, 'gen-java')
        self.py_out = os.path.join(self.workdir, 'gen-py')

        self.gen_langs = set(self.context.options.protobuf_gen_langs)
        for lang in ('java', 'python'):
            if self.context.products.isrequired(lang):
                self.gen_langs.add(lang)

        self.protobuf_binary = BinaryUtil(
            config=self.context.config).select_binary(self.protoc_supportdir,
                                                      self.protoc_version,
                                                      'protoc')
Example #7
0
 def __init__(self, *args, **kwargs):
     """Generates Java files from .proto files using the Google protobuf compiler."""
     super(ProtobufGen, self).__init__(*args, **kwargs)
     self.plugins = self.get_options().plugins
     self._extra_paths = self.get_options().extra_path
     self.protobuf_binary = BinaryUtil.from_options(
         self.get_options()).select_binary('protoc')
Example #8
0
def select_thrift_binary(options):
    """Selects a thrift compiler binary matching the current os and architecture.

  :param Options options: options for the current task
  Defaults to the thrift compiler version specified in the gen.thrift options scope.
  """
    return BinaryUtil.from_options(options).select_binary('thrift')
Example #9
0
 def test_nobases(self):
     """Tests exception handling if build support urls are improperly specified."""
     try:
         with BinaryUtil('bin/protobuf', '2.4.1', [], 30,
                         '/tmp').select_binary_stream('protoc') as stream:
             self.fail('We should have gotten a "NoBaseUrlsError".')
     except BinaryUtil.NoBaseUrlsError as e:
         pass  # expected
Example #10
0
 def test_support_url_multi(self):
   """Tests to make sure existing base urls function as expected."""
   config = self.config_urls([
     'BLATANTLY INVALID URL',
     'https://pantsbuild.github.io/binaries/reasonably-invalid-url',
     'https://pantsbuild.github.io/binaries/build-support',
     'https://pantsbuild.github.io/binaries/build-support', # Test duplicate entry handling.
     'https://pantsbuild.github.io/binaries/another-invalid-url',
   ])
   binaries = [
     ('bin/protobuf', '2.4.1', 'protoc',),
   ]
   util = BinaryUtil(config=config)
   for base_path, version, name in binaries:
     one = 0
     with util.select_binary_stream(base_path, version, name) as stream:
       stream()
       one += 1
     self.assertEqual(one, 1)
Example #11
0
 def test_support_url_multi(self):
   """Tests to make sure existing base urls function as expected."""
   config = self.config_urls([
     'BLATANTLY INVALID URL',
     'https://pantsbuild.github.io/binaries/reasonably-invalid-url',
     'https://pantsbuild.github.io/binaries/build-support',
     'https://pantsbuild.github.io/binaries/build-support', # Test duplicate entry handling.
     'https://pantsbuild.github.io/binaries/another-invalid-url',
   ])
   binaries = [
     ('bin/protobuf', '2.4.1', 'protoc',),
   ]
   util = BinaryUtil(config=config)
   for base_path, version, name in binaries:
     one = 0
     with util.select_binary_stream(base_path, version, name) as stream:
       stream()
       one += 1
     self.assertEqual(one, 1)
Example #12
0
def select_thrift_binary(config, version=None):
  """Selects a thrift compiler binary matching the current os and architecture.

  By default uses the repo default thrift compiler version specified in the pants config.

  config: The pants config containing thrift thrift binary selection data.
  version: An optional thrift compiler binary version override.
  """
  thrift_supportdir = config.get('thrift-gen', 'supportdir')
  thrift_version = version or config.get('thrift-gen', 'version')
  return BinaryUtil(config=config).select_binary(thrift_supportdir, thrift_version, 'thrift')
Example #13
0
    def test_support_url_fallback(self):
        """Tests fallback behavior with multiple support baseurls.

    Mocks up some dummy baseurls and then swaps out the URL reader to make sure urls are accessed
    and others are not.
    """
        fake_base, fake_url = self._fake_base, self._fake_url
        binaries = {
            'protoc': (
                'bin/protobuf',
                '2.4.1',
                'protoc',
            ),
            'ivy': (
                'bin/ivy',
                '4.3.7',
                'ivy',
            ),
            'bash': (
                'bin/bash',
                '4.4.3',
                'bash',
            ),
        }
        bases = [
            fake_base('apple'),
            fake_base('orange'),
            fake_base('banana'),
        ]
        reader = self.MapReader({
            fake_url(binaries, bases[0], 'protoc'):
            'SEEN PROTOC',
            fake_url(binaries, bases[0], 'ivy'):
            'SEEN IVY',
            fake_url(binaries, bases[1], 'bash'):
            'SEEN BASH',
            fake_url(binaries, bases[1], 'protoc'):
            'UNSEEN PROTOC 1',
            fake_url(binaries, bases[2], 'protoc'):
            'UNSEEN PROTOC 2',
            fake_url(binaries, bases[2], 'ivy'):
            'UNSEEN IVY 2',
        })

        unseen = [item for item in reader.values() if item.startswith('SEEN ')]
        for key in binaries:
            supportdir, version, name = binaries[key]
            with BinaryUtil(supportdir, version, bases, 30,
                            '/tmp').select_binary_stream(
                                key, url_opener=reader) as stream:
                self.assertEqual(stream(), 'SEEN ' + key.upper())
                unseen.remove(stream())
        self.assertEqual(0, len(unseen))  # Make sure we've seen all the SEENs.
Example #14
0
  def __init__(self, *args, **kwargs):
    """Generates Java and Python files from .proto files using the Google protobuf compiler."""
    super(ProtobufGen, self).__init__(*args, **kwargs)

    self.plugins = self.get_options().plugins
    self._extra_paths = self.get_options().extra_path

    self.java_out = os.path.join(self.workdir, 'gen-java')
    self.py_out = os.path.join(self.workdir, 'gen-py')

    self.gen_langs = set(self.get_options().lang)
    for lang in ('java', 'python'):
      if self.context.products.isrequired(lang):
        self.gen_langs.add(lang)

    self.protobuf_binary = BinaryUtil.from_options(self.get_options()).select_binary('protoc')
Example #15
0
 def test_support_url_multi(self):
     """Tests to make sure existing base urls function as expected."""
     count = 0
     with BinaryUtil(
             supportdir='bin/protobuf',
             version='2.4.1',
             baseurls=
         [
             'BLATANTLY INVALID URL',
             'https://dl.bintray.com/pantsbuild/bin/reasonably-invalid-url',
             'https://dl.bintray.com/pantsbuild/bin/build-support',
             'https://dl.bintray.com/pantsbuild/bin/build-support',  # Test duplicate entry handling.
             'https://dl.bintray.com/pantsbuild/bin/another-invalid-url',
         ],
             timeout_secs=30,
             bootstrapdir='/tmp').select_binary_stream('protoc') as stream:
         stream()
         count += 1
     self.assertEqual(count, 1)
Example #16
0
  def __init__(self, *args, **kwargs):
    """Generates Java and Python files from .proto files using the Google protobuf compiler."""
    super(ProtobufGen, self).__init__(*args, **kwargs)

    self.protoc_supportdir = self.get_options().supportdir
    self.protoc_version = self.get_options().version
    self.plugins = self.get_options().plugins
    self._extra_paths = self.get_options().extra_path

    self.java_out = os.path.join(self.workdir, 'gen-java')
    self.py_out = os.path.join(self.workdir, 'gen-py')

    self.gen_langs = set(self.get_options().lang)
    for lang in ('java', 'python'):
      if self.context.products.isrequired(lang):
        self.gen_langs.add(lang)

    self.protobuf_binary = BinaryUtil(config=self.context.config).select_binary(
      self.protoc_supportdir,
      self.protoc_version,
      'protoc'
    )
Example #17
0
 def _fake_url(cls, binaries, base, binary_key):
     base_path, version, name = binaries[binary_key]
     return '{base}/{binary}'.format(
         base=base,
         binary=BinaryUtil().select_binary_base_path(
             base_path, version, name))
Example #18
0
 def ragel_binary(self):
     if self._ragel_binary is None:
         self._ragel_binary = BinaryUtil(
             config=self.context.config).select_binary(
                 self._ragel_supportdir, self._ragel_version, 'ragel')
     return self._ragel_binary
Example #19
0
 def _fake_url(cls, binaries, base, binary_key):
   supportdir, version, name = binaries[binary_key]
   return '{base}/{binary}'.format(base=base,
                                   binary=BinaryUtil.select_binary_base_path(
                                     supportdir, version, binary_key))
Example #20
0
 def __init__(self, *args, **kwargs):
   """Generates Java files from .proto files using the Google protobuf compiler."""
   super(ProtobufGen, self).__init__(*args, **kwargs)
   self.plugins = self.get_options().plugins
   self._extra_paths = self.get_options().extra_path
   self.protobuf_binary = BinaryUtil.from_options(self.get_options()).select_binary('protoc')
Example #21
0
 def ragel_binary(self):
     if self._ragel_binary is None:
         self._ragel_binary = BinaryUtil.from_options(
             self.get_options()).select_binary('ragel')
     return self._ragel_binary
Example #22
0
 def _fake_url(cls, binaries, base, binary_key):
     supportdir, version, name = binaries[binary_key]
     return '{base}/{binary}'.format(
         base=base,
         binary=BinaryUtil.select_binary_base_path(supportdir, version,
                                                   binary_key))
Example #23
0
 def ragel_binary(self):
     if self._ragel_binary is None:
         self._ragel_binary = BinaryUtil.from_options(self.get_options()).select_binary("ragel")
     return self._ragel_binary