def build(self) -> Path: cmd, escaped_command = self.get_build_command() present_srpms = set(self.srpm_dir.glob("*.src.rpm")) logger.debug(f"Present SRPMs: {present_srpms}") try: out = self.upstream.command_handler.run_command( cmd, return_output=True ).stdout.strip() except PackitCommandFailedError as ex: logger.error(f"The `rpmbuild` command failed: {ex!r}") raise PackitFailedToCreateSRPMException( f"reason:\n{ex}\n" f"command:\n{escaped_command}\n" f"stdout:\n{ex.stdout_output}\n" f"stderr:\n{ex.stderr_output}" ) from ex except PackitException as ex: logger.error(f"The `rpmbuild` command failed: {ex!r}") raise PackitFailedToCreateSRPMException( f"The `rpmbuild` command failed:\n{ex}" ) from ex return self.get_path(out)
def create_srpm(self, srpm_path: str = None, srpm_dir: str = None) -> Path: """ Create SRPM from the actual content of the repo :param srpm_path: path to the srpm :param srpm_dir: path to the directory where the srpm is meant to be placed :return: path to the srpm """ if self.running_in_service(): srpm_dir = "." rpmbuild_dir = "." src_dir = str( self.absolute_specfile_dir.relative_to(self.local_project.working_dir) ) else: srpm_dir = srpm_dir or os.getcwd() src_dir = rpmbuild_dir = str(self.absolute_specfile_dir) cmd = [ "rpmbuild", "-bs", "--define", f"_sourcedir {rpmbuild_dir}", f"--define", f"_srcdir {src_dir}", "--define", f"_specdir {rpmbuild_dir}", "--define", f"_srcrpmdir {srpm_dir}", # no idea about this one, but tests were failing in tox w/o it "--define", f"_topdir {rpmbuild_dir}", # we also need these 3 so that rpmbuild won't create them "--define", f"_builddir {rpmbuild_dir}", "--define", f"_rpmdir {rpmbuild_dir}", "--define", f"_buildrootdir {rpmbuild_dir}", self.package_config.specfile_path, ] escaped_command = " ".join([f'"{cmd_part}"' for cmd_part in cmd]) logger.debug(f"SRPM build command: {escaped_command}") present_srpms = set(Path(srpm_dir).glob("*.src.rpm")) logger.debug("present srpms = %s", present_srpms) try: out = self.command_handler.run_command(cmd, return_output=True).strip() except PackitCommandFailedError as ex: logger.error(f"The `rpmbuild` command failed: {ex!r}") raise PackitFailedToCreateSRPMException( f"reason:\n" f"{ex}\n" f"command:\n" f"{escaped_command}\n" f"stdout:\n" f"{ex.stdout_output}\n" f"stderr:\n" f"{ex.stderr_output}" ) from ex except PackitException as ex: logger.error(f"The `rpmbuild` command failed: {ex!r}") raise PackitFailedToCreateSRPMException( f"The `rpmbuild` command failed:\n{ex}" ) from ex the_srpm = self._get_srpm_from_rpmbuild_output(out) if srpm_path: shutil.move(the_srpm, srpm_path) return Path(srpm_path) if self.running_in_service(): return Path(self.local_project.working_dir).joinpath(the_srpm) return Path(the_srpm)
def create_srpm(self, srpm_path: Union[Path, str] = None, srpm_dir: Union[Path, str] = None) -> Path: """ Create SRPM from the actual content of the repo :param srpm_path: path to the srpm :param srpm_dir: path to the directory where the srpm is meant to be placed :return: path to the srpm """ if self.running_in_service(): srpm_dir = Path(".") rpmbuild_dir = self.absolute_specfile_dir.relative_to( self.local_project.working_dir) else: srpm_dir = Path(srpm_dir) if srpm_dir else Path.cwd() rpmbuild_dir = self.absolute_specfile_dir cmd = [ "rpmbuild", "-bs", "--define", f"_sourcedir {rpmbuild_dir}", "--define", f"_srcdir {rpmbuild_dir}", "--define", f"_specdir {rpmbuild_dir}", "--define", f"_srcrpmdir {srpm_dir}", "--define", f"_topdir {rpmbuild_dir}", # we also need these 3 so that rpmbuild won't create them "--define", f"_builddir {rpmbuild_dir}", "--define", f"_rpmdir {rpmbuild_dir}", "--define", f"_buildrootdir {rpmbuild_dir}", self.package_config.specfile_path, ] escaped_command = " ".join(cmd) logger.debug(f"SRPM build command: {escaped_command}") present_srpms = set(srpm_dir.glob("*.src.rpm")) logger.debug(f"Present SRPMs: {present_srpms}") try: out = self.command_handler.run_command(cmd, return_output=True).strip() except PackitCommandFailedError as ex: logger.error(f"The `rpmbuild` command failed: {ex!r}") raise PackitFailedToCreateSRPMException( f"reason:\n" f"{ex}\n" f"command:\n" f"{escaped_command}\n" f"stdout:\n" f"{ex.stdout_output}\n" f"stderr:\n" f"{ex.stderr_output}") from ex except PackitException as ex: logger.error(f"The `rpmbuild` command failed: {ex!r}") raise PackitFailedToCreateSRPMException( f"The `rpmbuild` command failed:\n{ex}") from ex the_srpm = self._get_srpm_from_rpmbuild_output(out) if srpm_path: shutil.move(the_srpm, srpm_path) return Path(srpm_path) if self.running_in_service(): return self.local_project.working_dir / the_srpm return Path(the_srpm)