Fix, build and distribute
Fedora Packages

Pavel Raiskup <praiskup@redhat.com>
Copr Team

Slides: https://praiskup.fedorapeople.org/talks/fedora-hatch-brno-2022/
Fedora - how to contribute (blog)
$ git clone https://github.com/praiskup/fedora-hatch-brno-2022
$ firefox fedora-hatch-brno-2022/index.html

RPM package

  • a distro "SW building block"
  • "source" => spec + sources + patches
  • upstream / downstream
  • needs maintenance, contributors!

Typical contributor's workflow

  • problem → culprit (get package source)
  • upstream: search → report → fix
  • downstream, patch → local build, Mock
  • prod build: Koji - permissions
  • share: update via Bodhi - permissions
  • dnf update

Workshop workflow

  • problem → culprit (get package source)
  • upstream: report exists, fix optional
  • downstream, patch → local build, Mock
  • prod build+share: Fedora Copr - anyone
  • dnf update

prepare

  • containers!
    drop 'tsflags=nodocs' from /etc/dnf/dnf.conf

    $ sudo dnf install -y /usr/bin/copr   # to fix
    $ sudo dnf install -y fedora-packager # tooling

    # Environment, usually ready...
    $ sudo dnf install -y man man-pages dnf-plugins-core
    
            

Problem

(1 and 2)

    $ man copr # says:
    --timeout
           Override timeout for this build.
    
            
How am I supposed to use this option???

Culprit

  • where is the man page?
  • $ rpm [-ql|-qd] SOME_KNOWN_PACKAGE | grep man
    /usr/share/man/man1/gtar.1.gz
    $ find /usr/share/man | grep copr
  • $ which copr (command -v copr)
  • guilty package?
    $ rpm -qf /usr/share/man/man1/gtar.1.gz
    tar-1.34-3.fc36.x86_64

Culprit

  • guilty source? Nnote subpackages, e.g.
    $ rpm -qf /usr/share/doc/python3-copr/README.rst
    python3-copr-1.121-1.fc36.noarch
    $ rpm -qi python3-copr | grep Source
    Source RPM : python-copr-1.121-1.fc36.src.rpm
  • Q: What is the guilty source package?

source

https://src.fedoraproject.org/rpms/copr-cli


    $ fedpkg clone -a copr-cli
    $ cd copr-cli
    $ fedpkg switch-branch
    ...
    origin/f35
    origin/f36
    ...
    # ?? what branch ??
    
            

Fedora version


    $ cat /etc/os-release  | grep ^VERSION=
    VERSION="36 (Workstation Edition)"

    $ rpm --eval %dist
    .fc36

    $ rpm -q tar
    $ uname --kernel-release

    $ fedpkg switch-branch f36 # (git checkout f36)
    

no source tarball!


    $ ls
    copr-cli.spec  sources

    $ cat sources
    ...

    $ fepdkg sources  # or copr-distgit-client
    ... downloading from Fedora DistGit ...
    

extract source tarball


    $ fedpkg prep
    ... extracts tarball, applies patches, etc. ...
    $ # or rpmbuild -bp --define "_sourcedir $PWD" *.spec)

    $ ls copr-cli*/  # YAY, sources!
    

first local build


    $ fedpkg local
    error: Failed build dependencies: ...

    $ sudo dnf builddep *.spec

    $ fedpkg local  # retry
    Wrote: /copr-cli/noarch/copr-cli-1.102-1.fc36.noarch.rpm
    

install && test


    $ sudo dnf install /copr-cli/noarch/copr-cli-1.102-1.fc36.noarch.rpm
    Nothing to do.
    Complete!

    $ sudo rpm -ivh /copr-cli/noarch/copr-cli-1.102-1.fc36.noarch.rpm
    package copr-cli-1.102-1.fc36.noarch is already installed

    $ sudo dnf reinstall ...
    

Problem


    $ man copr # says:
    --timeout
           Override timeout for this build.
    
            
Source code to fix?

modify #1


    $ find copr-cli*/ -name '*man*'
    copr-cli-1.102/man

    $ ls copr-cli-1.102/man
    copr.1  copr-cli.1.asciidoc

    $ grep -ri "Override timeout for this build." . # alt
    ./copr-cli-1.102/man/copr-cli.1:Override timeout for this build\&.
    ./copr-cli-1.102/man/copr-cli.1.asciidoc:Override timeout for this build.

    $ # backup!
    $ cp copr-cli-1.102/man/copr-cli.1.asciidoc{,-backup}
    

modify #2

The --help has a better wording, use it...


    $ copr build --help
    ...
      --timeout TIMEOUT
            Specify build timeout (seconds), if the build
            takes longer than that, it is terminated and
            fails. The default is usually set to 5 hours on
            Copr Frontend.

    $ vim copr-cli-1.102/man/copr-cli.1.asciidoc
    

modify #3


    $ diff -u copr-cli-1.102/man/copr-cli.1.asciidoc-backup \
              copr-cli-1.102/man/copr-cli.1.asciidoc
    ...

    $ diff -u copr-cli-1.102/man/copr-cli.1.asciidoc-backup \
              copr-cli-1.102/man/copr-cli.1.asciidoc \
    > man-page.patch
    

modify #4

  • edit spec $ vim copr-cli.spec
  • change Release: bump, 1 => 2
  • specify patchfile:
    Near Source0: 'Patch0: man-page.patch'
  • apply patch file, %prep section: '%patch0 -p1'

build again


    $ fedpkg local
    ...
    Wrote: /tmp/copr-cli/noarch/copr-cli-1.102-2.fc36.noarch.rpm

    $ sudo dnf install -y \
    /tmp/copr-cli/noarch/copr-cli-1.102-2.fc36.noarch.rpm
    ...
    Upgraded:
      copr-cli-1.102-2.fc36.noarch
    

How to build for Fedora XY


    $ sudo dnf install -y mock

    $ # User needs to be in a mock group!
    $ sudo usermod -a -G mock praiskup

    $ # Run the cross-distro build.
    $ mock -r fedora-35-x86_64 --rebuild /copr-cli/copr-cli-1.102-2.fc36.src.rpm
    ...
    

Note! Dependencies are automatically installed.

Fedora Copr config

Fedora Copr - prepare srpm


    $ vim copr-cli.spec  # bump 2 > 3
    $ fedpkg srpm
    Wrote: /tmp/copr-cli/copr-cli-1.102-3.fc36.src.rpm
    

Fedora Copr - run the build


    $ copr create my-first-package \
        --chroot fedora-36-x86_64 \
        --chroot fedora-35-x86_64
    New project was successfully created:
    https://copr.fedorainfracloud.org/coprs/praiskup/my-first-package/

    $ copr build my-first-package \
        /copr-cli/copr-cli-1.102-2.fc36.src.rpm
    Build was added to my-first-package:
      https://copr.fedorainfracloud.org/coprs/build/4720270
      ...
      18:46:14 Build 4720270: succeeded
    

Fedora Copr - install


    $ sudo dnf -y copr enable my-nick/my-first-package
    $ sudo dnf -y update copr-cli  # voilà
    

Bonus

https://src.fedoraproject.org/lookaside/rpm-specs-latest.tar.xz

How easy?


    $ fedpkg clone -a PKGNAME && cd PKGNAME
    $ fedpkg switch-branch fVERSION
    $ fedpkg prep # and fix ..
    $ fedpkg srpm
    $ copr build PROJECT SRC.RPM
    $ sudo dnf -y copr enable ME/MY_PROJECT
    $ sudo dnf -y update PACKAGE
    

Find us on #fedora-buildsys channel