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 20, 2023
1 parent 0f4ac14 commit 78f4038
Show file tree
Hide file tree
Showing 3 changed files with 54 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}
48 changes: 48 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,50 @@ 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:
# TODO We want to loop over all name-version chroots and parse the
# spec values for each of them. For that, we will set dist macros.
# It expect tuples like this: [("fedora", "39"), ("foo", "bar")]
macros = []
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 78f4038

Please sign in to comment.