User:Maw/Tips
From openSUSE
Here are some tips that I give out to people working on building packages.
Note: This document assumes some basic knowledge about building packages, the build service, emacs, etc, all things which are adequately documented elsewhere. It's meant to provide ideas to help you optimize your own personal setup and to be more productive when building packages, not to serve as a tutorial.
Contents |
Emacs
I have a file called autobuild.el that has saved me a lot of time when working on packages. If you're an emacs fan, feel free to take a look. To get it, do "bzr branch http://treehou.se/~mw/bzr/autobuild.el". Install in the usual way.
The commands defined therein that I use most frequently are M-x ab-changelog and M-x ab-open-rej, but there are other goodies there too, and their documentation is available via M-x apropos. All of the commands start with ab-, so you should use ^ab- as the regexp passed to apropos.
If you have your own elisp snippets that you find useful, by all means send them my way.
Extra packages to install when building
osc lets you specify packages beyond those included in BuildRequires and their dependencies using the -x flag. I install some extra packages for virtually every build I do.
ccache
The most useful extra package to install is my patched version of ccache. It differs from stock ccache in several ways.
- It keeps its cache in /.ccache with respect to your build chroot; this is not overwritten or erased, even when the chroot is rebuilt.
- It installs gcc, cc, g++, and c++ symlinks in /usr/local/bin for transparent operation. As such, there is no need to modify your sources or specs to use it.
- The default cache size is generous, so old cached output will remain for many months.
I do not suggest this package for general use, but for local use when running osc it makes repeated rebuilds of programs implemented in C and C++ considerably faster.
It is available in the home:maw project.
a revision control tool
Sometimes a package won't build, even though you have all the correct build dependencies listed in your BuildRequires:, due to compiler changes, not very portable code, etc. In that case, you have to patch it. You can do so with quilt, but what a pain! An less error-prone solution is to install a revision control in your chroot. I prefer bzr, but hg or git will also do.
I run a build with -x bzr set, and let it try to build and fail. Then I go into the build directory inside the chroot, run make distclean (or whatever the package's equivalent command happens to be). Then, bzr init, bzr add, bzr commit -m "base commit". This creates a baseline of sources plus patches listed in your spec file applied. Then you can make changes to the code as you see fit. Run configure and make as necessary. Once it builds successfully, run make clean; make (this will be fast, because you installed my ccache package) to check that it builds again. Then run make distclean. Now run bzr diff. The resultant output can be saved and applied as a patch in your spec file.
(Replace the bzr commands above with equivalent commands for your favourite revision control tool as necessary.)
an editor
It is useful to build with an editor installed for the same reason that it's useful to build with a revision control tool. I usually build with -x emacs-nox.
build machine setup
I use a dedicated machine for builds, mostly because my primary workstation doesn't have much disk space. Here is how I set it up.
prerequisites
Install the osc and build packages. Their use and installation are described in the osc page. I use a stock openSUSE 10.2 system because it was the latest and greatest at the time I set up my build machine. Later distros would work equally well.
caches
To save time between rebuilds, osc caches packages and chroots across invocations. By default, it keeps those caches under /var/tmp, which is prone to being periodically wiped. Since chroots and packages don't change a whole lot, it makes sense to store them elsewhere.
Since I use a dedicated machine for builds, I had no compunctions about creating and using nonstandard directories for this purpose.
dependencies cache
I store all of my cached packages in /cache.
Packages I created
I keep packages that I create myself under /cache/packages:
maw@builder:~> ls /cache/packages 10.0 10.1 10.2 10.3 factory sle10 sles9
One directory for each distro that I build for. The packages in these subdirectories can override upstream packages by using the -p flag.
Upstream packages
I store packages from upstream in /cache/packagecache:
maw@builder:~> ls /cache/packagecache/ Beagle SUSE:SLE-10:SDK home:snorp GNOME:Community SUSE:SLES-9 mozilla GNOME:STABLE devel:languages:haskell openSUSE:10.2 GNOME:UNSTABLE devel:tools:scm openSUSE:10.3 Java:Sun-Java-1.5 home:FunkyPenguin openSUSE:Factory SUSE:Factory home:btimothy openSUSE:Tools SUSE:SL-10.0 home:joshkress ruby SUSE:SL-10.1 home:maw telepathy SUSE:SL-9.3 home:maw:bzr SUSE:SLE-10 home:maw:playground
These subdirectories are created and populated by osc and require no maintenance. (Exception: eventually disk space will run short on my build machine. When that happens, I will delete directories associated with personal projects I'm not currently interested in. I will also delete old Factory packages.)
save your chroots
I keep at least one chroot for each distro I build for. I store them under /abuild. There is nothing magic about this choice of directory name -- I use it because it's standard on the internal SUSE build system, and old habits die hard. But it could just as easily be something else.
maw@builder:~> ls /abuild/ maw maw-10.2 maw-10.3+GNOME_UNSTABLE maw-sled10 maw-10.0 maw-10.2-1 maw-9.3 maw-sles9 maw-10.1 maw-10.3 maw-factory+GNOME_UNSTABLE maw2
All of my chroot directory names start with "maw", another habit acquired from using the internal SUSE build system. The directory named "maw" is a Factory chroot. The rest are suffixed by the distro installed inside.
Putting it all together
Here is a typical set of commands to build a package against openSUSE 10.3:
export OSC_BUILD_ROOT=/abuild/maw-10.3 export OSC_PACKAGE_CACHE=/cache/packagecache osc build -x ccache -x bzr -x emacs-nox -p /cache/packages/10.3 openSUSE_10.3 i586 maws-hello.spec

