Blame doc/manual/dependencies

2ff057
/*! \page dependencies Dependencies
2ff057
2ff057
Dependencies provide a way for a package builder to require other
2ff057
packages or capabilities to be installed before or simultaneously
2ff057
with one another. These can be used to require a python interpreter
2ff057
for a python based application for example. RPM ensures dependencies
2ff057
are satisfied whenever packages are installed, erased, or upgraded.
2ff057
2ff057
\section dependencies_package Requiring Packages
2ff057
2ff057
To require the packages python and perl, use:
2ff057
2ff057
\verbatim
2ff057
	Requires: python perl
2ff057
\endverbatim
2ff057
2ff057
in the spec file. Note that "Requires python, perl" would work as well. If you
2ff057
needed to have a very recent version of python but any version of perl,
2ff057
2ff057
\verbatim
2ff057
	Requires: python >= 1.3, perl
2ff057
\endverbatim
2ff057
2ff057
would do the trick. Again, the ',' in the line is optional.  Instead of
2ff057
'>=', you may also use '<', '>', '<=', or '='.  Spaces are required
2ff057
around the numeric operator to separate the operator from the package name.
2ff057
2ff057
The full syntax for specifying a dependency on an epoch, version and release
2ff057
is
2ff057
\verbatim
2ff057
	[epoch:]version[-release]
2ff057
\endverbatim
2ff057
where
2ff057
\verbatim
2ff057
	epoch	(optional) number, with assumed default of 0 if not supplied
2ff057
	version	(required) can contain any character except '-'
2ff057
	release	(optional) can contain any character except '-'
2ff057
\endverbatim
2ff057
2ff057
For example,
2ff057
2ff057
\verbatim
2ff057
	Requires: perl >= 9:5.00502-3
2ff057
\endverbatim
2ff057
2ff057
specifies
2ff057
2ff057
\verbatim
2ff057
	epoch=9
2ff057
	version=5.00502
2ff057
	release=3
2ff057
\endverbatim
2ff057
2ff057
The epoch (if present) is a monotonically increasing integer, neither the
2ff057
version or the release can contain the '-' hyphen character, and the dependency
2ff057
parser does not permit white space within a definition.  Unspecified epoch
2ff057
and releases are assumed to be zero, and are interpreted as "providing all"
2ff057
or "requiring any" value.
2ff057
2ff057
The release tag is usually incremented every time a package is rebuilt for
2ff057
any reason, even if the source code does not change. For example, changes
2ff057
to the specfile, compiler(s) used to build the package, and/or dependency
2ff057
changes should all be tracked by incrementing the release.  The version number,
2ff057
on the other hand, is usually set by the developer or upstream maintainer,
2ff057
and should not be casually modified by the packager.
2ff057
2ff057
Version numbering should be kept simple so that it is easy to determine the
2ff057
version ordering for any set of packages.  If the packager needs to separate
2ff057
a release from all other releases that came before it, then the epoch, the
2ff057
most significant part of package ordering, can be changed.
2ff057
2ff057
The algorithm that RPM uses to determine the version ordering of
2ff057
packages is simple and developers are encouraged not to rely on the
2ff057
details of its working.  Developers should keep their numbering scheme
2ff057
simple so any reasonable ordering algorithm would work.  The version
2ff057
comparison algorithm is in the routine rpmvercmp() and it is just a segmented
2ff057
strcmp(3).  First, the boundaries of the segments are found using
2ff057
isdigit(3)/isalpha(3).  Each segment is then compared in order with the
2ff057
right most segment being the least significant.  The alphabetical
2ff057
portions are compared using a lexical graphical ascii ordering, the
2ff057
digit segments strip leading zeroes and compare the strlen before
2ff057
doing a strcmp. If both numerical strings are equal, the longer string
2ff057
is larger.  Notice that the algorithm has no knowledge of decimal fractions,
2ff057
and perl-5.6 is "older" than perl-5.00503 because the number 6 is less than
2ff057
the number 503.
2ff057
2ff057
The concept of "newer" used by rpm to determine when a package should be
2ff057
upgraded can be broken if version format changes oddly, such as when the
2ff057
version segments cannot be meaningfully compared.
2ff057
2ff057
Example of a bad format change: 2.1.7Ax to 19980531
2ff057
\verbatim
2ff057
  The date may be the older version, but it is numerically greater
2ff057
  2 so it is considered newer :(
2ff057
\endverbatim
2ff057
2ff057
Example of a bad increment: 2.1.7a to 2.1.7A
2ff057
\verbatim
2ff057
  The 'a' (ASCII 97) is compared against 'A' (ASCII 65), making 2.1.7a
2ff057
  the newer version.
2ff057
\endverbatim
2ff057
2ff057
Stick to major.minor.patchlevel using numbers for each if you can.
2ff057
Keeps life simple :-)
2ff057
2ff057
If a Requires: line needs to include an epoch in the comparison, then
2ff057
the line should be written like
2ff057
2ff057
\verbatim
2ff057
	Requires: somepackage = 23:version
2ff057
\endverbatim
2ff057
2ff057
You can't continue a "Requires: " line. If you have multiple
2ff057
"Requires: " lines then the package requires all packages mentioned on
2ff057
all of the lines to be installed.
2ff057
2ff057
\section dependencies_prereqs Prereqs
2ff057
2ff057
Prereqs are different from requires only in that a PreReq is guaranteed
2ff057
to be installed before the package that contains the PreReq.  PreReq's
2ff057
are used only to order packages, otherwise PreReq's are exactly the same
2ff057
as a Requires: dependency.
2ff057
2ff057
\section dependencies_virtual Virtual Packages
2ff057
2ff057
Sometimes you need to make sure the system your package is being installed 
2ff057
on has a package which provides a certain capability, even though you don't
2ff057
care what specific package provides it. For example, sendmail won't work
2ff057
properly unless a local delivery agent (lda) is present. You can ensure that
2ff057
one is installed like this:
2ff057
2ff057
\verbatim
2ff057
	Requires: lda
2ff057
\endverbatim
2ff057
2ff057
This will match either a package called lda (as mentioned above), or any
2ff057
package which contains:
2ff057
2ff057
\verbatim
2ff057
	Provides: lda
2ff057
\endverbatim
2ff057
2ff057
in its .spec file. No version numbers may be used with virtual packages.
2ff057
2ff057
Virtual packages are often used to supply file dependencies such as /bin/sh
2ff057
on machines that are only partly managed by rpm. A virtual package with
2ff057
\verbatim
2ff057
	Provides: /bin/sh
2ff057
\endverbatim
2ff057
differs from a package that has /bin/sh in the %files list in that the
2ff057
package can be safely removed without removing /bin/sh.
2ff057
2ff057
\section dependencies_automatic Automatic Dependencies
2ff057
2ff057
To reduce the amount of work required by the package builder, RPM scans
2ff057
the file list of a package when it is being built. Any files in the file
2ff057
list which require shared libraries to work (as determined by ldd) cause
2ff057
that package to require the shared library.
2ff057
2ff057
For example, if your package contains /bin/vi, RPM will add dependencies 
2ff057
for both libtermcap.so.2 and libc.so.5. These are treated as virtual
2ff057
packages, so no version numbers are used.
2ff057
2ff057
A similar process allows RPM to add Provides information automatically. Any
2ff057
shared library in the file list is examined for its soname (the part of
2ff057
the name which must match for two shared libraries to be considered
2ff057
equivalent) and that soname is automatically provided by the package. For
2ff057
example, the libc-5.3.12 package has provides information added for
2ff057
libm.so.5 and libc.so.5. We expect this automatic dependency generation
2ff057
to eliminate the need for most packages to use explicit Requires: lines.
2ff057
2ff057
\section dependencies_custom Custom Automatic Dependency
2ff057
2ff057
The automatic dependency programs are found via macro expansion.  Thus
2ff057
sites can very the amount of dependency processing that are performed
2ff057
locally, by changing the executable/script which is run.  Dependency
2ff057
processing can even be changed on a per-package basis if the macros are
2ff057
defined in the spec file. To allow for maximum configurability the
2ff057
dependency programs are shell scripts which can be duplicated and edited
2ff057
for site specific needs.
2ff057
2ff057
The macros: %__find_provides, %__find_prereq, %__find_requires,
2ff057
%__find_conflicts, %__find_obsoletes, if they exist, are expanded to
2ff057
the name of a program to exec. For each package, the program receives
2ff057
the glob'ed %files manifest on stdin and returns dependencies on stdout. The
2ff057
discovered dependencies are parsed exactly as if they were found after
2ff057
2ff057
\verbatim
2ff057
	Provides:
2ff057
	PreReq:
2ff057
	Requires:
2ff057
	Conflicts:
2ff057
	Obsoletes:
2ff057
\endverbatim
2ff057
tokens in a spec file (i.e. the same parser is used), so items look like
2ff057
(comments added)
2ff057
\verbatim
2ff057
	/bin/sh			# file existence
2ff057
	libc.so.6		# soname existence
2ff057
	foo <= 1:2.3-4		# versioned package
2ff057
	perl5(Apache) <= 1.2	# versioned namespace
2ff057
\endverbatim
2ff057
2ff057
The default rpm configuration has only
2ff057
	%__find_provides	/usr/lib/rpm/find-provides
2ff057
	%__find_requires	/usr/lib/rpm/find-requires
2ff057
which can be overridden (or even undefined) within a spec file.
2ff057
2ff057
\section dependencies_interpreters Interpreters and Shells
2ff057
2ff057
Modules for interpreted languages like perl and tcl impose additional
2ff057
dependency requirements on packages. A script written for an interpreter
2ff057
often requires language specific modules to be installed in order to execute
2ff057
correctly. In order to automatically detect language specific modules, each
2ff057
interpreter may have its own find-provides and find-requires. To prevent
2ff057
module name collisions between interpreters, module names are enclosed within
2ff057
parentheses and a conventional interpreter specific identifier is prepended:
2ff057
2ff057
2ff057
\verbatim
2ff057
  Provides: perl(MIME-Base64), perl(Mail-Header)-1-09
2ff057
2ff057
  Requires: perl(Carp), perl(IO-Wrap) = 4.5
2ff057
\endverbatim
2ff057
2ff057
2ff057
The output of a per-interpreter find-requires (notice in this example the
2ff057
first requirement is a package and the rest are language specific modules)
2ff057
2ff057
\verbatim
2ff057
	Mail-Header >= 1.01
2ff057
	perl(Carp) >= 3.2
2ff057
	perl(IO-Wrap) == 4.5 or perl(IO-Wrap)-4.5
2ff057
\endverbatim
2ff057
2ff057
the output from find-provides is
2ff057
\verbatim
2ff057
	Foo-0.9
2ff057
	perl(Widget)-0-1
2ff057
\endverbatim
2ff057
2ff057
The per-interpreter automatic module detectors will normally be located in
2ff057
\verbatim
2ff057
	/usr/lib/rpm/{perl,tcl}/find-{provides,requires}
2ff057
with appropriate per-interpreter hooks into
2ff057
\verbatim
2ff057
	/usr/lib/rpm/find-{provides,requires}
2ff057
\endverbatim
2ff057
2ff057
@todo per-interpreter dependency generators are not located in subdirectories.
2ff057
2ff057
Notice that shell dependencies will require that all %post et al scriptlets
2ff057
be processed by the find-requires. Since a shell script depends on all the
2ff057
programs which it runs.
2ff057
2ff057
2ff057
\section dependencies_installing Installing and Erasing Packages with Dependencies
2ff057
2ff057
For the most part, dependencies should be transparent to the user. However,
2ff057
a few things will change.
2ff057
2ff057
First, when packages are added or upgraded, all of their dependencies
2ff057
must be satisfied. If they are not, an error message like this appears:
2ff057
2ff057
\verbatim
2ff057
    failed dependencies:
2ff057
	    libICE.so.6  is needed by somepackage-2.11-1
2ff057
	    libSM.so.6  is needed by somepackage-2.11-1
2ff057
	    libc.so.5  is needed by somepackage-2.11-1
2ff057
\endverbatim
2ff057
2ff057
Similarly, when packages are removed, a check is made to ensure that 
2ff057
no installed packages will have their dependency conditions break due to
2ff057
the packages being removed. If you wish to turn off dependency checking for 
2ff057
a particular command, use the --nodeps flag.
2ff057
2ff057
\section dependencies_conflicts Conflicts
2ff057
2ff057
While conflicts were implemented in earlier versions of RPM they never 
2ff057
worked properly until RPM 2.3.4 (well, we hope they work properly now
2ff057
anyway).
2ff057
2ff057
Conflicts allow a package to say it won't work with another package (or
2ff057
virtual package) installed on the system. For example, qmail doesn't work
2ff057
(w/o custom setup) on machines with sendmail installed. The qmail spec file
2ff057
may codify this with a line like:
2ff057
2ff057
\verbatim
2ff057
	Conflicts: sendmail
2ff057
\endverbatim
2ff057
2ff057
The syntax of the "Conflicts" tag is identical to the syntax of the Requires
2ff057
tag and conflict checking may be overridden by using the --nodeps flag.
2ff057
2ff057
\section dependencies_querying Querying for Dependencies
2ff057
2ff057
Two new query information selection options are now available. The first, 
2ff057
--provides, prints a list of all of the capabilities a package provides. 
2ff057
The second, --requires, shows the other packages that a package requires
2ff057
to be installed, along with any version number checking.
2ff057
2ff057
There are also two new ways to search for packages. Running a query with 
2ff057
--whatrequires \<item\> queries all of the packages that require \<item\>. 
2ff057
Similarly, running --whatprovides \<item\> queries all of the packages that 
2ff057
provide the \<item\> virtual package. Note that querying for package that 
2ff057
provides "python" will not return anything, as python is a package, not
2ff057
a virtual package.
2ff057
2ff057
\section dependencies_verifying Verifying Dependencies
2ff057
2ff057
As of RPM 2.2.2, -V (aka --verify) verifies package dependencies
2ff057
by default. You can tell rpm to ignore dependencies during system
2ff057
verification with the --nodeps. If you want RPM to verify just dependencies
2ff057
and not file attributes (including file existence), use the --nofiles
2ff057
flag. Note that "rpm -Va --nofiles --nodeps" will not verify anything at
2ff057
all, nor generate an error message.
2ff057
2ff057
\section dependencies_branching Branching Version
2ff057
2ff057
It is quite common to need to branch a set of sources in version
2ff057
control. It is not so obvious how those branches should be represented
2ff057
in the package version numbers. Here is one solution.
2ff057
2ff057
You have a bag of features that are injected into a package in a
2ff057
non-ordered fashion, and you want to have the package
2ff057
name-version-release be able to:
2ff057
2ff057
\verbatim
2ff057
	1) identify the "root version" of the source code.
2ff057
	2) identify the handful of features that are in that
2ff057
	   branch of the package.
2ff057
	3) preserve sufficient ordering so that packages upgrade
2ff057
	   without the use of --oldpackage.
2ff057
\endverbatim
2ff057
2ff057
A simple (but possibly not adequate) scheme to achieve this is:
2ff057
2ff057
\verbatim
2ff057
	Name: foo
2ff057
	Version: <the "root version" of the source code>
2ff057
	Release: <release instance>.<branch>
2ff057
\endverbatim
2ff057
2ff057
where the release instance is something like YYYYMMDD or some linear
2ff057
record of the number of builds with the current tar file, it is used
2ff057
to preserve ordering when necessary.
2ff057
2ff057
Another alternative scheme might be:
2ff057
2ff057
\verbatim
2ff057
	Name: foo
2ff057
	Epoch: <branch>
2ff057
	Version: <the branch specific version of the code>
2ff057
	Release: <release instance>
2ff057
\endverbatim
2ff057
2ff057
\section dependencies_build Build dependencies
2ff057
2ff057
The following dependencies are available at build time.  These are
2ff057
similar to the install time version but these apply only during
2ff057
package creation and are specified in the specfile not in the binary
2ff057
package.
2ff057
2ff057
\verbatim
2ff057
	BuildRequires:
2ff057
	BuildConflicts:
2ff057
	BuildPreReq:
2ff057
\endverbatim
2ff057
2ff057
*/