Skip to content

Commit

Permalink
rpmbuild: query exclusivearch and excludearch from spec instead of SRPM
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Jun 13, 2023
1 parent 765a79c commit 63d8869
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
2 changes: 2 additions & 0 deletions rpmbuild/copr-rpmbuild.spec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BuildRequires: %{python_pfx}-munch
BuildRequires: %{python}-requests
BuildRequires: %{python_pfx}-jinja2
BuildRequires: %{python_pfx}-simplejson
BuildRequires: %{python_pfx}-specfile
BuildRequires: python3-backoff >= 1.9.0

%if 0%{?fedora} || 0%{?rhel} > 7
Expand All @@ -66,6 +67,7 @@ Requires: %{python_pfx}-jinja2
Requires: %{python_pfx}-munch
Requires: %{python}-requests
Requires: %{python_pfx}-simplejson
Requires: %{python_pfx}-specfile
Requires: python3-backoff >= 1.9.0

Requires: mock >= 2.0
Expand Down
8 changes: 4 additions & 4 deletions rpmbuild/copr_rpmbuild/automation/srpm_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import simplejson
from copr_rpmbuild.automation.base import AutomationTool
from copr_rpmbuild.helpers import locate_srpm, get_rpm_header
from copr_rpmbuild.helpers import locate_spec, Spec


class SRPMResults(AutomationTool):
Expand Down Expand Up @@ -33,7 +33,7 @@ def get_package_info(self):
"""
Return ``dict`` with interesting package metadata
"""
srpm = locate_srpm(self.resultdir)
hdr = get_rpm_header(srpm)
spec_path = locate_spec(self.resultdir)
spec = Spec(spec_path)
keys = ["name", "exclusivearch", "excludearch"]
return {key: hdr[key] for key in keys}
return {key: getattr(spec, key) for key in keys}
45 changes: 45 additions & 0 deletions rpmbuild/copr_rpmbuild/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import backoff
import rpm
import munch
from specfile import Specfile

from six.moves.urllib.parse import urlparse
from copr_common.enums import BuildSourceEnum
Expand Down Expand Up @@ -377,3 +378,47 @@ def is_srpm_build(task):
Return `True` if the `self.source_dict` belongs to a SRPM build task
"""
return task.get("source_type") is not None


class Spec:
"""
Wrapper around `specfile.Specfile` to easily access attributes that we need
"""

def __init__(self, path):
try:
macros = [("fedora", "39"), ("rhel", "")]
self.spec = Specfile(path, macros=macros)
except TypeError as ex:
raise RuntimeError("No .spec file") from ex
except OSError as ex:
raise RuntimeError(ex) from ex

self.path = path
self.tags = self.spec.tags(self.spec.parsed_sections.package).content

def __getattr__(self, name):
return getattr(self.spec, name)

@property
def exclusivearch(self):
"""
Evaluated %{exclusivearch} as a list
"""
return self.safe_attr("exclusivearch").split()

@property
def excludearch(self):
"""
Evaluated %{excludearch} as a list
"""
return self.safe_attr("excludearch").split()

def safe_attr(self, name):
"""
Return evaluated spec file attribute or empty string
"""
try:
return getattr(self.tags, name).expanded_value
except AttributeError:
return ""

0 comments on commit 63d8869

Please sign in to comment.