def CallRpmBuild()

in pkg/make_rpm.py [0:0]


  def CallRpmBuild(self, dirname, rpmbuild_args):
    """Call rpmbuild with the correct arguments."""

    buildroot = os.path.join(dirname, RpmBuilder.BUILDROOT_DIR)
    # For reference, E121 is a hanging indent flake8 issue.  It really wants
    # four space indents, but properly fixing that will require re-indenting the
    # entire file.

    # Further, the use of disabling yapf and friends is to allow argument names
    # to be associated with their values neatly.
    args = [
        self.rpmbuild_path,  # noqa: E121
    ]
    if self.debug:
      args.append('-vv')

    # Common options
    args += [
        '--define', '_topdir %s' % dirname,
        '--define', '_tmppath %s/TMP' % dirname,
        '--bb',
        '--buildroot=%s' % buildroot,
    ]  # yapf: disable

    # Macro-based RPM parameter substitution, if necessary inputs provided.
    if self.preamble_file:
      args += ['--define', 'build_rpm_options %s' % self.preamble_file]
    if self.description_file:
      args += ['--define', 'build_rpm_description %s' % self.description_file]
    if self.install_script_file:
      args += ['--define', 'build_rpm_install %s' % self.install_script_file]
    if self.file_list_path:
      # %files -f is taken relative to the package root
      args += ['--define', 'build_rpm_files %s' % os.path.basename(self.file_list_path)]

    args.extend(rpmbuild_args)

    args.append(self.spec_file)

    env = {
        'LANG': 'C',
        'RPM_BUILD_ROOT': buildroot,
    }

    if self.source_date_epoch is not None:
      env['SOURCE_DATE_EPOCH'] = self.source_date_epoch
      args += ["--define", "clamp_mtime_to_source_date_epoch Y"]

    if self.debug:
      print('Running rpmbuild as:', ' '.join(["'" + a + "'" for a in args]))
      print('With environment:')
      pprint.pprint(env)

    p = subprocess.Popen(
        args,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        env=env)
    output = p.communicate()[0].decode()

    if p.returncode == 0:
      # Find the created file.
      self.rpm_path = FindOutputFile(output)

    if p.returncode != 0 or not self.rpm_path:
      print('Error calling rpmbuild:')
      print(output)
    elif self.debug:
      print(output)

    # Return the status.
    return p.returncode