Difference between revisions of "RPM Packaging Process"

From CDOT Wiki
Jump to: navigation, search
(Setting up the Packaging Environment)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:SBR600]]{{Chris Tylers Draft}}
+
[[Category:SBR600]][[Category:DPI908]][[Category:RPM]][[Category:SPO600]]
 
RPM packages are built from the source files plus a spec file, using the ''rpmbuild'' program.
 
RPM packages are built from the source files plus a spec file, using the ''rpmbuild'' program.
  
Line 16: Line 16:
 
== Needed Packages ==
 
== Needed Packages ==
  
Install with ''yum'':
+
Install with ''dnf'' (or ''yum'' on older versions of Fedora):
* rpm-build
+
* "Fedora Packager" (this is a group of packages - use "dnf groupinstall" or put an @ sign in front of the group name)
 
* rpmdevtools
 
* rpmdevtools
 
* rpmlint
 
* rpmlint
 
* yum-utils
 
* yum-utils
 
{{Admon/tip|"Fedora Packager" group|Many of these tools can be installed at once by installing the "Fedora Packager" group: <code>yum groupinstall "Fedora Packager"</code>}}
 
  
 
== Setting up the RPM tree ==
 
== Setting up the RPM tree ==
Line 50: Line 48:
  
 
# Download the source code for an existing RPM: <code>yumdownloader --source ''nameofpackage''</code>
 
# Download the source code for an existing RPM: <code>yumdownloader --source ''nameofpackage''</code>
# Install that downloaded SRPM: <code>rpm -i ''nameofpackage''*.src.rpm</code>
+
# Install that downloaded SRPM (this does not require root access): <code>rpm -i ''nameofpackage''*.src.rpm</code>
 
#* Source will be in <code>~/rpmbuild/SOURCES</code>
 
#* Source will be in <code>~/rpmbuild/SOURCES</code>
 
#* Spec file will be in <code>~/rpmbuild/SPECS</code>
 
#* Spec file will be in <code>~/rpmbuild/SPECS</code>
 +
 +
After installing the SRPM you can:
 +
 
* Examine the specfile: <code>cd ~/rpmbuild/SPECS; less ''nameofpackage''.spec</code>
 
* Examine the specfile: <code>cd ~/rpmbuild/SPECS; less ''nameofpackage''.spec</code>
* To build from source using the specfile:
+
* Prep the sources (unpack tarballs, apply patches) to see the source code as it will be built: <code>rpmbuild -bp ''nameofpackage''.spec</code> # Results will be in <code>~/rpmbuild/BUILD/</code> (usually in a subdirectory named <code>''nameofpackage''-''version''</code>).
 +
* Build from source using the specfile:
 
*# Build all (binary RPMS plus SRPMS): <code>rpmbuild -ba ''nameofpackage''.spec</code>
 
*# Build all (binary RPMS plus SRPMS): <code>rpmbuild -ba ''nameofpackage''.spec</code>
 
*# Build just the spec file: <code>rpmbuild -bs ''nameofpackage''.spec</code>
 
*# Build just the spec file: <code>rpmbuild -bs ''nameofpackage''.spec</code>
Line 83: Line 85:
  
 
Some spec files may produce multiple packages -- for example, they may produce separate packages for a game, game data, and documentation; or for a base package and additional plugins for use with that package; or for a base package and multiple user interfaces (such as separate command-line, graphical, and web interfaces). This is done at the discretion of the spec file author where she decides that the user may want to install a subset of the package's features.
 
Some spec files may produce multiple packages -- for example, they may produce separate packages for a game, game data, and documentation; or for a base package and additional plugins for use with that package; or for a base package and multiple user interfaces (such as separate command-line, graphical, and web interfaces). This is done at the discretion of the spec file author where she decides that the user may want to install a subset of the package's features.
 +
 +
{{Admon/note|Building to Different Points|The <code>-ba</code> argument means "build all". You can substitute different values to build to different points in the process: <code>-bp</code> to build to the prep stage, <code>-bs</code> to build only a SRPM, and so forth. See the manpage for <rpmbuild" for details.}}
  
 
== Testing the RPM ==
 
== Testing the RPM ==
Line 88: Line 92:
 
The ''rpmlint'' tool tests spec files, source RPMs, and binary RPMs to verify that they were created in compliance with the Fedora packaging guidelines.
 
The ''rpmlint'' tool tests spec files, source RPMs, and binary RPMs to verify that they were created in compliance with the Fedora packaging guidelines.
 
* Test the spec file: <code>rpmlint ~/rpmbuild/SPECS/''packagename''*</code>
 
* Test the spec file: <code>rpmlint ~/rpmbuild/SPECS/''packagename''*</code>
* Test the source RPM: <code>rpmlint ~/rpmbuild/SRPMS/''packagename''*.src.rpm
+
* Test the source RPM: <code>rpmlint ~/rpmbuild/SRPMS/''packagename''*.src.rpm</code>
* Test the binary RPMs: <code>rpmlint ~/rpmbuild/RPMS/*/''packagename''*.rpm
+
* Test the binary RPMs: <code>rpmlint ~/rpmbuild/RPMS/*/''packagename''*.rpm</code>
  
 
Notice that the checks performed vary based on the input file. For example, some errors in the spec file (such as the summary ending in a period ".") could be determined from the spec file, but only show up when the SRPM/RPM is checked. Each run will report the number of errors and warnings; errors are serious problems which should not be ignored, while warnings may be ignored depending on the context.
 
Notice that the checks performed vary based on the input file. For example, some errors in the spec file (such as the summary ending in a period ".") could be determined from the spec file, but only show up when the SRPM/RPM is checked. Each run will report the number of errors and warnings; errors are serious problems which should not be ignored, while warnings may be ignored depending on the context.
  
 
If you discover any errors, edit the specfile to correct them. If you need additional information on the error:
 
If you discover any errors, edit the specfile to correct them. If you need additional information on the error:
* add the <code>-i</code> (information) option to the ''rpmlint'' command
+
* add the -i (information) option to the ''rpmlint'' command
 
* see the [[:fedora:Common Rpmlint issues|Fedora Common Rpmlint issues]] page on the Fedora wiki
 
* see the [[:fedora:Common Rpmlint issues|Fedora Common Rpmlint issues]] page on the Fedora wiki
 +
 +
= Common Challenges =
 +
 +
Refer to these documents on the Fedora wiki for help on specific packaging challenges:
 +
* [[:fedora:Packaging:Guidelines|Packaging Guidelines]] - General packaging guidelines for Fedora, including instructions for specific languages and packaging cases
 +
* [[:fedora:Packaging:ScriptletSnippets|Scriptlet Snippets]] - Script(lets) that can be used in RPM packages to solve specific problems
 +
 +
In particular, these sections are useful for GNU software:
 +
* [[:fedora:Packaging:ScriptletSnippets#Texinfo|Packaging .info (texinfo) documentation files]]
 +
* [[:fedora:Packaging:Guidelines#Handling_Locale_Files|Handling locale files (message translations)]]

Latest revision as of 12:18, 17 July 2017

RPM packages are built from the source files plus a spec file, using the rpmbuild program.

Stop (medium size).png
Do Not Build as Root
Always build RPM packages as a regular, non-root user. Building as a root user is unnecessary and may cause unintended side effects, including damaging your system.

Resources

Setting up the Packaging Environment

Needed Packages

Install with dnf (or yum on older versions of Fedora):

  • "Fedora Packager" (this is a group of packages - use "dnf groupinstall" or put an @ sign in front of the group name)
  • rpmdevtools
  • rpmlint
  • yum-utils

Setting up the RPM tree

The directories used by the rpm build tools can be defined as RPM macros. A script is provided in the rpmdevtools package to create a set of personal build directories and create the appropriate entries in the ~/.rpmmacros file:

rpmdev-setuptree

The directories created are:

  • ~/rpmbuild/SOURCES - for source code (tarballs/zip archives and patches)
  • ~/rpmbuild/SPECS - for the spec file
  • ~/rpmbuild/SRPMS - for the resulting source RPMs
  • ~/rpmbuild/RPMS - for the resulting binary RPMs
  • ~/rpmbuild/BUILD - directory used to perform the build
  • ~/rpmbuild/BUILDROOT - contains a fake root directory into which the built files are "installed" prior to being packaged

Wiping out the RPM tree

Important.png
Wiping the Tree Deletes Data
Be sure to save any files you need from your previous build activity before wiping the tree.

When switching to a new package, it is customary to wipe out the rpmbuild tree to avoid clutter: rpmdev-wipetree

Examining Existing SRPMs

A great place to start when learning to build RPMs is to examine some existing SRPMs.

  1. Download the source code for an existing RPM: yumdownloader --source nameofpackage
  2. Install that downloaded SRPM (this does not require root access): rpm -i nameofpackage*.src.rpm
    • Source will be in ~/rpmbuild/SOURCES
    • Spec file will be in ~/rpmbuild/SPECS

After installing the SRPM you can:

  • Examine the specfile: cd ~/rpmbuild/SPECS; less nameofpackage.spec
  • Prep the sources (unpack tarballs, apply patches) to see the source code as it will be built: rpmbuild -bp nameofpackage.spec # Results will be in ~/rpmbuild/BUILD/ (usually in a subdirectory named nameofpackage-version).
  • Build from source using the specfile:
    1. Build all (binary RPMS plus SRPMS): rpmbuild -ba nameofpackage.spec
    2. Build just the spec file: rpmbuild -bs nameofpackage.spec

Rebuild from SRPMS

Instead of installing an SRPM and building from the spec file, it is possible to build the binary RPMs and SRPM directly from an SRPM:

rpmbuild --rebuild nameofpackage*.src.rpm

This is useful when a no binary package is available for a particular platform or distribution version, but an SRPM is available.

Creating a New Package

Writing a specfile

  1. Run rpmdev-newspec packagename in ~/rpmbuild/SPECS
  2. Edit the skeleton specfile. Refer to the Packaging How-To for guidance.

Building the RPM

  1. rpmbuild -ba packagename.spec
    • If successful, output will be binary RPM(s) in ~/rpmbuild/RPMS and source RPM in ~/rpmbuild/SRPMS
      • You can install binary RPM as root using this command: rpm -i rpmfile or yum localinstall rpmfile
    • If unsuccessful, read the error messages carefully.

Note that a successful build of a compiled binary will usually produce both a binary RPM and a debuginfo RPM. The debuginfo package contains additional information which is useful for debugging a problem, but which just takes up space when the program is being used normally.

Some spec files may produce multiple packages -- for example, they may produce separate packages for a game, game data, and documentation; or for a base package and additional plugins for use with that package; or for a base package and multiple user interfaces (such as separate command-line, graphical, and web interfaces). This is done at the discretion of the spec file author where she decides that the user may want to install a subset of the package's features.

Note.png
Building to Different Points
The -ba argument means "build all". You can substitute different values to build to different points in the process: -bp to build to the prep stage, -bs to build only a SRPM, and so forth. See the manpage for <rpmbuild" for details.

Testing the RPM

The rpmlint tool tests spec files, source RPMs, and binary RPMs to verify that they were created in compliance with the Fedora packaging guidelines.

  • Test the spec file: rpmlint ~/rpmbuild/SPECS/packagename*
  • Test the source RPM: rpmlint ~/rpmbuild/SRPMS/packagename*.src.rpm
  • Test the binary RPMs: rpmlint ~/rpmbuild/RPMS/*/packagename*.rpm

Notice that the checks performed vary based on the input file. For example, some errors in the spec file (such as the summary ending in a period ".") could be determined from the spec file, but only show up when the SRPM/RPM is checked. Each run will report the number of errors and warnings; errors are serious problems which should not be ignored, while warnings may be ignored depending on the context.

If you discover any errors, edit the specfile to correct them. If you need additional information on the error:

Common Challenges

Refer to these documents on the Fedora wiki for help on specific packaging challenges:

  • Packaging Guidelines - General packaging guidelines for Fedora, including instructions for specific languages and packaging cases
  • Scriptlet Snippets - Script(lets) that can be used in RPM packages to solve specific problems

In particular, these sections are useful for GNU software: