From c35087be51c1e3f016f70d33390fc6f88f59a5ea Mon Sep 17 00:00:00 2001 From: Otto Liljalaakso Date: Oct 08 2022 11:57:40 +0000 Subject: Use dist-git repo and Rawhide in GNU Hello tutorial In practice, almost all packaging happens inside a dist-git repository. Creating new specfiles can be done outside of one, but it is also possible to use a dist-git compatible Git repository. In order to stay close to actual workflows, a dist-git-like repository is introduced to the packaging tutorial. Since 'rawhide' is the default branch for dist-git repositories, and normally all packaging work is first done in rawhide branch, the tutorial is also switched to use it. Also this moves the tutorial closer to actual workflows. The downside is that then the tutorial package is built for Rawhide, but installed in the user's system, which most probably is not Rawhide. However, due to GNU Hello's few dependencies, in practice this works well. There is also a way to avoid this problem, by introducing Toolbox and performing the test install there. --- diff --git a/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc b/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc index edafae6..24d0e70 100644 --- a/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc +++ b/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc @@ -22,7 +22,6 @@ including following the various Fedora guidance. This tutorial is intended to be run on a Fedora {MAJOROSVER} system. It should, however, work also for other releases. -Just replace strings like `f{MAJOROSVER}` with your release number. The tutorial proceeds in step by step manner, with most steps editing the package's specfile. @@ -35,18 +34,33 @@ you can peek there. Follow xref:Installing_Packager_Tools.adoc[Installing Packager Tools]. +== Initializing repository + +Fedora package sources are stored in what are called _dist-git_ repositories. +These are Git repositories that follow a specified layout. +In particular, in dist-git, branches like `f{MAJOROSVER}` contain sources for the named Fedora release. +`rawhide` is used for Rawhide release and is the default branch. +We start by creating a Git repository compatible with this structure: + +---- +$ mkdir hello && cd hello +$ git init --initial-branch=rawhide +---- + +It is usual to ido all packaging work in Rawhide first, +then merge the changes to release branches. +Following this approach, this tutorial does everything in `rawhide`. + [#building] == Building the RPM We need the source code of the project we are packaging, often referred to as the _upstream_ source. -We will download it from the project's website -into a directory we create for packaging GNU Hello. +We will download it from the project's website. We are getting the compressed tarball archive, which happens to be the preferred distribution form for most FOSS projects. ---- -$ mkdir hello && cd hello $ wget http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz ---- @@ -131,10 +145,35 @@ In many cases, many lines in the template do not need to be changed at all, at least for the initial attempt. +== Creating the sources file + +In dist-git, package source archives are not directly stored in the Git repository. +Instead, they go to the _lookaside cache_. +Tooling retrieves the files referred by `Source` tags from the cache, +and verifies that the correct file is received by checking its digest. + +As our package does not have a Fedora dist-git repository, +we cannot upload the archive to the lookaside cache, +but we can already calculate and store its digest. +This, and many other tasks, are done with the `fedpkg` tool. +---- +$ fedpkg --release rawhide new-sources --offline hello-2.10.tar.gz +---- + +The `--release rawhide` part is needed because normally, +`fedpkg` determines the active Fedora release from remote branch name, +which is not available in our local repository. + +Resulting digest is written to file `sources`: + +---- +$ cat sources +SHA512 (hello-2.10.tar.gz) = e301d785135c52575a8b4c35994c0316f8d366451f604eb5e74c1f907077502aebd5a1a32cd1e26cd7ca32c22f4de5623a335f8ae7e735ac977420df664f01de +---- + == Building the Package We are ready for the first run to build source, binary and debugging packages. -This, and many other tasks, are done with the `fedpkg` tool. The production builds for Fedora are built in the https://koji.fedoraproject.org[Koji] build system, which in turn uses https://rpm-software-management.github.io/mock/[Mock] @@ -145,7 +184,7 @@ which also invokes Mock: [subs="attributes+"] ---- -$ fedpkg --release f{MAJOROSVER} mockbuild +$ fedpkg --release rawhide mockbuild ---- The build environment created by Mock is very basic. @@ -443,7 +482,8 @@ List the files contained in the package: [subs="attributes+"] ---- -$ rpm --query --package --list results_hello/2.10/1.fc{MAJOROSVER}/hello-2.10-1.fc{MAJOROSVER}.x86_64.rpm +$ rpm --query --package --list results_hello/2.10/1.fc{MAJOROSVER}/hello-2.10-1.fc{RAWHIDEVER}.x86_64.rpm +$ dnf -C repoquery --list ./results_hello/2.10/1.fc{RAWHIDEVER}/hello-2.10-1.fc.x86_64.rpm /usr/bin/hello /usr/lib/.build-id /usr/lib/.build-id/39 @@ -477,7 +517,7 @@ List the package's runtime dependencies with the following command: [subs="attributes+"] ---- -$ rpm --query --package --requires results_hello/2.10/1.fc{MAJOROSVER}/hello-2.10-1.fc{MAJOROSVER}.x86_64.rpm +$ rpm --query --package --requires results_hello/2.10/1.fc{MAJOROSVER}/hello-2.10-1.fc{RAWHIDEVER}.x86_64.rpm libc.so.6()(64bit) libc.so.6(GLIBC_2.14)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) @@ -499,8 +539,8 @@ you can use `dnf repoquery`: [subs="attributes+"] ---- $ dnf -C repoquery --whatprovides 'libc.so.6()(64bit)' -glibc-0:2.34-11.fc{MAJOROSVER}.x86_64 -glibc-0:2.34-7.fc{MAJOROSVER}.x86_64 +glibc-0:2.34-11.fc{RAWHIDEVER}.x86_64 +glibc-0:2.34-7.fc{RAWHIDEVER}.x86_64 ---- You will see that the only dependency of GNU Hello is `+glibc+`, @@ -516,9 +556,9 @@ Conversely, to check what capabilities the package provides, you can do: [subs="attributes+"] ---- -$ rpm --query --package --provides results_hello/2.10/1.fc{MAJOROSVER}/hello-2.10-1.fc{MAJOROSVER}.x86_64.rpm -hello = 2.10-1.fc{MAJOROSVER} -hello(x86-64) = 2.10-1.fc{MAJOROSVER} +$ rpm --query --package --provides results_hello/2.10/1.fc{RAWHIDEVER}/hello-2.10-1.fc{RAWHIDEVER}.x86_64.rpm +hello = 2.10-1.fc{RAWHIDEVER} +hello(x86-64) = 2.10-1.fc{RAWHIDEVER} ---- The provides of this package are very simple. @@ -527,11 +567,15 @@ in plain and architecture specific forms. === Installing -As a final check, the package can be installed and ran: +As a final check, the package can be installed and ran. +This is not entirely correct, because we built the package for Rawhide, +and thus may not be compatible with Fedora {MAJOROSVER}, +but in practice often works, +especially with packages with few dependencies like GNU Hello: [subs="attributes+"] ---- -$ sudo dnf -C -y install ./results_hello/2.10/1.fc{MAJOROSVER}/hello-2.10-1.fc{MAJOROSVER}.x86_64.rpm +$ sudo dnf -C -y install ./results_hello/2.10/1.fc{RAWHIDEVER}/hello-2.10-1.fc{RAWHIDEVER}.x86_64.rpm $ hello --greeting="Hello, rpm!" Hello, rpm! ---- diff --git a/modules/ROOT/partials/attributes.adoc b/modules/ROOT/partials/attributes.adoc index 82e2da1..88d675f 100644 --- a/modules/ROOT/partials/attributes.adoc +++ b/modules/ROOT/partials/attributes.adoc @@ -2,4 +2,5 @@ :PREVIOUSOSVER: 35 :MAJOROSVER: 36 :NEXTOSVER: 37 +:RAWHIDEVER: 38 :MAJOREPELVER: 8