Development/Packaging/RepositorySystem/Quickstart
From Mandriva Community Wiki
This page contains a complete example showing how to work with RPM packages stored in SVN.
Contents |
[edit] Modifying a package in SVN
[edit] bm + svn + repsys
Here we will apply a small change to the bm package which has been in SVN for a few months now. To show some basic SVN usage, we will remove the compression from its patch.
NOTE: please do not assume you will have to manually remove bzipped patches from all your SPEC files! SVN can deal with binary files very easily, and if we want to, we can make a script to remove bzip2 from all patches. The example below was done just to show a few simple operations in the SVN world.
This tutorial assumes you have an ssh account on the SVN server. If you do not have it, do not despair! You can use the cvs.mandriva.com server via the https:// url instead of svn+ssh:// on svn.mandriva.com. It won't allow you to commit the changes back, but at least you can see how checkout and diff work.
[edit] Authentication
First, let's add the ssh identity to ssh-agent so that we are not prompted for the passphrase all the time (see http://wiki.mandriva.com/Development/Docs/Contributor_Tricks#SSH_configuration to configure your ssh agent) :
[andreas@pandora svn]$ ssh-add Enter passphrase for /home/andreas/.ssh/id_dsa: Identity added: /home/andreas/.ssh/id_dsa (/home/andreas/.ssh/id_dsa)
If the ssh-add command returns an error, you may need to launch ssh-agent manually:
[zeb@n4 svn]$ exec ssh-agent bash
then add your key with ssh-add as described above.
[edit] Checkout
Now, let's check out the current bm tree from SVN:
[andreas@pandora svn]$ svn co svn+ssh://svn.mandriva.com/svn/packages/cooker/bm/current bm A bm/SOURCES A bm/SOURCES/bm-2.1-rpmbuild.patch.bz2 A bm/SOURCES/bm-2.1.tar.bz2 A bm/SPECS A bm/SPECS/bm.spec Checked out revision 975.
This created a local directory called bm and extracted into it the SPECS and SOURCES directories. Let's perform our changes:
[andreas@pandora svn]$ cd bm [andreas@pandora bm]$ bunzip2 SOURCES/bm-2.1-rpmbuild.patch.bz2 [andreas@pandora bm]$ vi SPECS/bm.spec
Note that we are working inside the checkout area. There is no need to copy things over to, say, ~/rpm and work there.
Let's see what we changed.
[andreas@pandora bm]$ svn status ? SOURCES/bm-2.1-rpmbuild.patch ! SOURCES/bm-2.1-rpmbuild.patch.bz2 M SPECS/bm.spec
The first line tells us that a new file showed up in the SOURCES directory and that SVN knows nothing about it. Hence, the question mark. The second line warns us that a file which was under revision control disappeared. This is expected, since we basically renamed the file when we removed the bzip2 compression.
So, what we need to do now is remove the .bz2 one from revision control and add the .patch one:
[andreas@pandora bm]$ svn rm SOURCES/bm-2.1-rpmbuild.patch.bz2 D SOURCES/bm-2.1-rpmbuild.patch.bz2 [andreas@pandora bm]$ svn add SOURCES/bm-2.1-rpmbuild.patch A SOURCES/bm-2.1-rpmbuild.patch
"svn status" is now correct:
[andreas@pandora bm]$ svn status D SOURCES/bm-2.1-rpmbuild.patch.bz2 A SOURCES/bm-2.1-rpmbuild.patch M SPECS/bm.spec
[edit] Build test
[edit] Quick check
We can now build our package to make sure everything is correct. We will do this again inside the svn checkout area. bm itself is being used here not because we are changing the bm package (it's just a coincidence), but because it makes it easy to build rpm packages outside %_topdir (usually ~/rpm):
[andreas@pandora bm]$ bm creating package list processing package bm-2.1-1mdk building source and binary packages error: File /home/andreas/svn/bm/SOURCES/bm-2.1-rpmbuild.patch.bz2: No such file or directory error: failed!
Oops! Glad we did that! Commiting something that doesn't built is not nice... One more small fix and we can try again:
[andreas@pandora bm]$ vi SPECS/bm.spec [andreas@pandora bm]$ bm creating package list processing package bm-2.1-1mdk building source and binary packages succeeded!
You may find a log file on the current build (useful for checking compilation warnings e.g.) under SPECS/log.bm. Or you may use bm -l to get them on screen.
[edit] Checking in a clean chroot
Since the buildsystem server builds packages in a clean chroot, it may be also wise to check if our package builds correctly in a clean environment. In particular, this helps debugging the BuildRequires section of your spec file. If a package builds correctly on a node, but not by the buildsystem server, this certainly means a BuildRequires is missing in your spec file. In order to test if your package builds in a clean chroot before submitting, you may use Iurt:
[zeb@n4 bm]$ cd SRPMS [zeb@n4 SRPMS]$ sudo iurt bm-2.1-214mdv2007.1.src.rpm
[edit] Checking in other architectures
You may want to check if your package builds in a 64-bit environment, since the buildsystem will attempt building in both i586 and x86_64, and will reject the package if either of these builds fails. To do so, login on a 64-bit node (deborah or seggie), and use once again bm or Iurt to rebuild your package in this environment.
In case of problems specific to one architecture, you may use conditionals in your spec file (for instance, when one architecture requires different ./configure options):
%ifarch x86_64 # ...this will be executed in the x86_64 machine only %else # ...this will be exectuted in the i586 machine %endif
To exclude completely one architecture, use Buildarch in the spec file. In particular, this is necessary when building noarch packages:
Buildarch : noarch
[edit] Reviewing the changes
The changes are now ready to be commited. Reviewing them before commit is a good procedure, as it also helps to write the changelog messages. Note that the diff below now includes the "new" patch because it's in plain text now:
[andreas@pandora bm]$ svn diff Index: SOURCES/bm-2.1-rpmbuild.patch.bz2 =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: SOURCES/bm-2.1-rpmbuild.patch =================================================================== --- SOURCES/bm-2.1-rpmbuild.patch (revision 0) +++ SOURCES/bm-2.1-rpmbuild.patch (revision 0) @@ -0,0 +1,15 @@ +diff -ur bm-2.1/BuildManager/build.py bm-2.1.acme/BuildManager/build.py +--- bm-2.1/BuildManager/build.py 2003-11-20 15:37:22.000000000 -0200 ++++ bm-2.1.acme/BuildManager/build.py 2004-01-17 14:58:57.843281631 -0200 +@@ -198,9 +198,9 @@ + tmppath = " --define '_tmppath %s/BUILDROOT'" % pkg.builddir + else: + tmppath = "" +- cmd = "rpm -b%s --define '_topdir %s'%s %s %s 2>&1" % \ ++ cmd = "rpmbuild -b%s --define '_topdir %s'%s %s %s 2>&1" % \ + (stagechar,pkg.builddir,tmppath,passtrough,pkg.spec) +- logger.debug("rpm command: "+cmd) ++ logger.debug("rpmbuild command: "+cmd) + if not dryrun: + log = open(pkg.log, "w") + pop = popen2.Popen3(cmd) Index: SPECS/bm.spec =================================================================== --- SPECS/bm.spec (revision 975) +++ SPECS/bm.spec (working copy) @@ -3,6 +3,6 @@ %define py_libdir %{py_prefix}/%{_lib}/python%{py_ver} %define py_sitedir %{py_libdir}/site-packages Name: bm Version: 2.1 Release: 1mdk @@ -11,7 +15,7 @@ License: GPL URL: http://moin.conectiva.com.br/BuildManager Source: bm-%{version}.tar.bz2 -Patch: bm-2.1-rpmbuild.patch.bz2 +Patch: bm-2.1-rpmbuild.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Requires: python >= %pyver Requires: rpm-build
[edit] Checking out
mdvsys co xinetd
[edit] Submitting
Now that the fix is commited, we may want to upload the package. We don't have to, though: the SVN usage makes sure that whoever is going to upload the package later on will include the fix we just made.
So, let's assume we are going to upload the package. We call this submitting.
To submit to cooker the bm package we just touched we run this command, from anywhere:
repsys submit svn+ssh://svn.mandriva.com/svn/packages/cooker/bm 976
If successful, the bm package at revision 976 will be submitted (for the implementation details, see Submitting in detail ).
You can omit the URL part and just use the package name instead if you have /etc/repsys.conf configured correctly with the default_parent parameter.
Note: You need to have ssh-agent configured properly or else the submit command will fail!
It's important to know that the submission process does not need access to the .src.rpm file! The commit could have been done from the machine at work and the actual upload commanded from the machine at home which didn't even touch the bm package. It's like a phone call: "hey, please upload package bm, thanks".
[edit] mdvsys
mdvsys is a script part of the perl-MDV-Repsys package which is replacing repsys. It can be used to perform most of the svn commands when dealing with rpm packages stored in svn.
mdvsys currently needs repsys to be installed and configured, because they both use the same configuration file /etc/repsys.conf). The defaults from that file should be enough for cooker usage.
Here are examples of how mdvsys can be used (this time using the xinetd package). You will note that it avoids the somewhat "low level" svn commands.
[edit] Checking out
mdvsys co xinetd</tt>
[edit] Syncing changes
Modify it:
$ cd pkg-dir $ emacs|vi SPECS/pkg.spec
Add/remove the file to svn repository after your changes:
mdvsys sync
[edit] Building
Build your package:
mdvsys build
[edit] Committing
Test it and, if ok, commit your changes:
mdvsys ci -m 'some greate changes'
[edit] Submitting
mdvsys submit xinetd
[edit] Importing a package into SVN
To import a new package into SVN, use the srpm2svn.sh tool from anywhere (your home machine, cluster, whatever):
$ srpm2svn.sh /mnt/BIG/distrib/cooker/SRPMS/main/release/bm-2.1-212mdk.src.rpm
The script is hosted at http://svn.mandriva.com/cgi-bin/viewvc.cgi/soft/build_system/srpm2svn/trunk/ and needs the following packages to be installed:
- perl-MDV-Repsys
- repsys (for the /etc/repsys.conf configuration file: please review it for the correct URLs)
Alternatively, you can also use mdvsys import src.rpm [src.rpm ...] directly.