def genlang(self, lang, targets): protobuf_binary = select_binary( self.protoc_supportdir, self.protoc_version, 'protoc', self.context.config ) bases, sources = self._calculate_sources(targets) if lang == 'java': safe_mkdir(self.java_out) gen = '--java_out=%s' % self.java_out elif lang == 'python': safe_mkdir(self.py_out) gen = '--python_out=%s' % self.py_out else: raise TaskError('Unrecognized protobuf gen lang: %s' % lang) args = [self.protobuf_binary, gen] for base in bases: args.append('--proto_path=%s' % base) args.extend(sources) log.debug('Executing: %s' % ' '.join(args)) process = subprocess.Popen(args) result = process.wait() if result != 0: raise TaskError('%s ... exited non-zero (%i)' % (self.protobuf_binary, result))
def __init__(self, context): CodeGen.__init__(self, context) self.protoc_supportdir = self.context.config.get('protobuf-gen', 'supportdir') self.protoc_version = self.context.config.get('protobuf-gen', 'version') self.output_dir = (context.options.protobuf_gen_create_outdir or context.config.get('protobuf-gen', 'workdir')) def resolve_deps(key): deps = OrderedSet() for dep in context.config.getlist('protobuf-gen', key): deps.update(context.resolve(dep)) return deps self.javadeps = resolve_deps('javadeps') self.java_out = os.path.join(self.output_dir, 'gen-java') self.pythondeps = resolve_deps('pythondeps') self.py_out = os.path.join(self.output_dir, 'gen-py') self.gen_langs = set(context.options.protobuf_gen_langs) for lang in ('java', 'python'): if self.context.products.isrequired(lang): self.gen_langs.add(lang) self.protobuf_binary = select_binary( self.protoc_supportdir, self.protoc_version, 'protoc', context.config )
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 select_binary(thrift_supportdir, thrift_version, 'thrift', config)
def __init__(self, context, workdir): super(ProtobufGen, self).__init__(context, workdir) self.protoc_supportdir = self.context.config.get('protobuf-gen', 'supportdir') self.protoc_version = self.context.config.get('protobuf-gen', 'version') 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(context.options.protobuf_gen_langs) for lang in ('java', 'python'): if self.context.products.isrequired(lang): self.gen_langs.add(lang) self.protobuf_binary = select_binary( self.protoc_supportdir, self.protoc_version, 'protoc', context.config )
def __init__(self, context, workdir): super(ProtobufGen, self).__init__(context, workdir) self.protoc_supportdir = self.context.config.get( 'protobuf-gen', 'supportdir') self.protoc_version = self.context.config.get('protobuf-gen', 'version') 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(context.options.protobuf_gen_langs) for lang in ('java', 'python'): if self.context.products.isrequired(lang): self.gen_langs.add(lang) self.protobuf_binary = select_binary(self.protoc_supportdir, self.protoc_version, 'protoc', context.config)