Example #1
0
  def genlang(self, lang, targets):
    bases, sources = calculate_compile_roots(targets, self.is_gentarget)

    if lang == 'java':
      gen = self.gen_java.gen
    elif lang == 'python':
      gen = self.gen_python.gen
    else:
      raise TaskError('Unrecognized thrift gen lang: %s' % lang)

    args = [
      self.thrift_binary,
      '--gen', gen,
      '-recurse',
    ]

    if self.strict:
      args.append('-strict')
    if self.verbose:
      args.append('-verbose')
    for base in bases:
      args.extend(('-I', base))

    sessions = []
    for source in sources:
      self.context.log.info('Generating thrift for %s\n' % source)
      # Create a unique session dir for this thrift root.  Sources may be full paths but we only
      # need the path relative to the build root to ensure uniqueness.
      # TODO(John Sirois): file paths should be normalized early on and uniformly, fix the need to
      # relpath here at all.
      relsource = os.path.relpath(source, get_buildroot())

      if lang == "python":
        copied_source = os.path.join(self._workdir, relsource)
        safe_mkdir(os.path.dirname(copied_source))
        shutil.copyfile(source, copied_source)
        replace_python_keywords_in_file(copied_source)
        source = relsource = copied_source

      outdir = os.path.join(self.session_dir, '.'.join(relsource.split(os.path.sep)))
      safe_mkdir(outdir)

      cmd = args[:]
      cmd.extend(('-o', outdir))
      cmd.append(source)
      log.debug('Executing: %s' % ' '.join(cmd))
      sessions.append(self.ThriftSession(outdir, cmd, subprocess.Popen(cmd)))

    result = 0
    for session in sessions:
      if result != 0:
        session.process.kill()
      else:
        result = session.process.wait()
        if result != 0:
          self.context.log.error('Failed: %s' % ' '.join(session.cmd))
        else:
          _copytree(session.outdir, self.combined_dir)
    if result != 0:
      raise TaskError('%s ... exited non-zero (%i)' % (self.thrift_binary, result))
Example #2
0
    def genlang(self, lang, targets):
        bases, sources = calculate_compile_roots(targets, self.is_gentarget)

        if lang == 'java':
            gen = self.gen_java.gen
        elif lang == 'python':
            gen = self.gen_python.gen
        else:
            raise TaskError('Unrecognized thrift gen lang: {}'.format(lang))

        args = [
            self.thrift_binary,
            '--gen',
            gen,
            '-recurse',
        ]

        if self.get_options().strict:
            args.append('-strict')
        if self.get_options().level == 'debug':
            args.append('-verbose')
        for base in bases:
            args.extend(('-I', base))

        sessions = []
        for source in sources:
            self.context.log.info('Generating thrift for {}\n'.format(source))
            # Create a unique session dir for this thrift root.  Sources may be full paths but we only
            # need the path relative to the build root to ensure uniqueness.
            # TODO(John Sirois): file paths should be normalized early on and uniformly, fix the need to
            # relpath here at all.
            relsource = os.path.relpath(source, get_buildroot())

            outdir = os.path.join(self.session_dir,
                                  '.'.join(relsource.split(os.path.sep)))
            safe_mkdir(outdir)

            cmd = args[:]
            cmd.extend(('-o', outdir))
            cmd.append(relsource)
            self.context.log.debug('Executing: {}'.format(' '.join(cmd)))
            sessions.append(
                self.ThriftSession(outdir, cmd, subprocess.Popen(cmd)))

        result = 0
        for session in sessions:
            if result != 0:
                session.process.kill()
            else:
                result = session.process.wait()
                if result != 0:
                    self.context.log.error('Failed: {}'.format(' '.join(
                        session.cmd)))
                else:
                    _copytree(session.outdir, self.combined_dir)
        if result != 0:
            raise TaskError('{} ... exited non-zero ({})'.format(
                self.thrift_binary, result))