wiki:BufferExample

Version 3 (modified by Nikita Krupen'ko, 14 years ago) ( diff )

Fixed some typos

Example of pb usage with the buffer project

Buffer is a tool used by the MondoRescue project and I needed to create packages for it, in order to ease the installation of mondo on distributions as they require it.

The first step is to create the project structure with the newproj command. For that to work you first need to edit your $HOME/.pbrc configuration file and add in it the following:

pbconfurl buffer = svn+ssh://svn.mondorescue.org/mondo/svn/pb/projects/buffer/pbconf

Of course replace that reference by a reference to which you really have access in your case. Once done, ask pb to generate its structure, jst giving the name of the project (-p) and the release you're packaging (-r):

pb -p buffer -r 1.19 newproj buffer
Adding /users/bruno/pb/projects/buffer to SVN... A         /users/bruno/pb/projects/buffer
OK
Updating /users/bruno/pb/projects/buffer... À la révision 456.
OK
Adding /users/bruno/pb/projects/buffer/pbconf to SVN... A         /users/bruno/pb/projects/buffer/pbconf
A         /users/bruno/pb/projects/buffer/pbconf/1.19
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer.pb
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/rpm
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/rpm/buffer.spec
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/changelog
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/control
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/buffer.dirs
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/buffer.docs
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/compat
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/rules
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/deb/copyright
A         /users/bruno/pb/projects/buffer/pbconf/1.19/buffer/pbfilter
A         /users/bruno/pb/projects/buffer/pbconf/1.19/pbfilter
A         /users/bruno/pb/projects/buffer/pbconf/1.19/pbfilter/novell.pbf
A         /users/bruno/pb/projects/buffer/pbconf/1.19/pbfilter/rpm.pbf
A         /users/bruno/pb/projects/buffer/pbconf/1.19/pbfilter/all.pbf
A         /users/bruno/pb/projects/buffer/pbconf/1.19/pbfilter/deb.pbf
A         /users/bruno/pb/projects/buffer/pbconf/1.19/pbfilter/md.pbf
OK
Updating /users/bruno/pb/projects/buffer/pbconf... À la révision 456.
OK
Checking in /users/bruno/pb/projects/buffer... Ajout          buffer
Ajout          buffer/pbconf
Ajout          buffer/pbconf/1.19
Ajout          buffer/pbconf/1.19/buffer.pb
Ajout          buffer/pbconf/1.19/pbfilter
Ajout          buffer/pbconf/1.19/pbfilter/all.pbf
Ajout          buffer/pbconf/1.19/pbfilter/deb.pbf
Ajout          buffer/pbconf/1.19/pbfilter/md.pbf
Ajout          buffer/pbconf/1.19/pbfilter/novell.pbf
Ajout          buffer/pbconf/1.19/pbfilter/rpm.pbf
Ajout          buffer/pbconf/1.19/buffer
Ajout          buffer/pbconf/1.19/buffer/deb
Ajout          buffer/pbconf/1.19/buffer/deb/changelog
Ajout          buffer/pbconf/1.19/buffer/deb/compat
Ajout          buffer/pbconf/1.19/buffer/deb/control
Ajout          buffer/pbconf/1.19/buffer/deb/copyright
Ajout          buffer/pbconf/1.19/buffer/deb/buffer.dirs
Ajout          buffer/pbconf/1.19/buffer/deb/buffer.docs
Ajout          buffer/pbconf/1.19/buffer/deb/rules
Ajout          buffer/pbconf/1.19/buffer/pbfilter
Ajout          buffer/pbconf/1.19/buffer/rpm
Ajout          buffer/pbconf/1.19/buffer/rpm/pkg1.spec
Transmission des données ..............
Révision 457 propagée.
OK
Updating /users/bruno/pb/projects/buffer... À la révision 457.
OK
Project: buffer
Action: newproj

Now you "just" need to edit those configuration files to review them and prepare your build of packages. Begining with the first one, the project's conf file:

grep -Ev '^#|^$' buffer/pbconf/1.19/buffer.pb
pburl buffer = http://hello-penguin.com/software/buffer/buffer-1.19.tar.gz
pbrepo buffer = ftp://ftp.mondorescue.org
pbwf buffer = 1
pbpackager buffer = Bruno Cornec <bruno@project-builder.org>
sshhost buffer = www.mondorescue.org
sshlogin buffer = buffer
sshdir buffer = /mondo/ftp
sshport buffer = 22
projver buffer = 1.19
projtag buffer = 1
testver buffer = true
defpkgdir buffer = dir-buffer

pbrepo indicates where the resulting packages will be available for download. pbwf indicates whether the tar file is well-formed (it should contain a directory with name-version). The ssh* variables indicates where will packages be uploaded at the end of the build. And the name of the directory for defpkgdir is not important as we do not deal with a local CMS.

We also need to adapt the filter a bit:

grep -Ev '^#|^$' buffer/pbconf/1.19/pbfilter/*
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBREPO = $pbrepo
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBSRC = src/%{name}-%{version}.tar.gz
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBVER = $pbver
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBDATE = $pbdate
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBLOG = yes
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBTAG = $pbtag
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBREV = $pbrev
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBPKG = $pbpkg
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBPACKAGER = $pbpackager
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBDESC = This is a program designed to speed up writing tapes on remote tape drives.  When this program is put "in the pipe", two processes are started.  One process reads from standard-in and the other writes to standard-out.  Both processes communicate via shared memory.
buffer/pbconf/1.19/pbfilter/all.pbf:filter PBURL = http://hello-penguin.com/software/buffer
buffer/pbconf/1.19/pbfilter/deb.pbf:filter PBGRP = utils
buffer/pbconf/1.19/pbfilter/md.pbf:filter PBGRP = Archiving/Backup
buffer/pbconf/1.19/pbfilter/novell.pbf:filter PBGRP = Productivity/Archiving/Backup
buffer/pbconf/1.19/pbfilter/rpm.pbf:filter PBGRP = Applications/Archiving
buffer/pbconf/1.19/pbfilter/rpm.pbf:filter PBSUF = $pbsuf

This defines all the macro that are needed to do a build. Then adapt the spec file if you're on a rpm based distro, or the control file if under a deb one. I'm using Mandriva so go for the spec:

grep -Ev '^#|^$' buffer/pbconf/1.19/buffer/rpm/buffer.spec
Summary:        buffer speeds up writing tapes on remote tape drives
Summary(fr):    buffer accélère l'écriture des bande sur des périphériques distants
Name:           PBPKG
Version:        PBVER
Release:        PBTAGPBSUF
License:        PBLIC
Group:          PBGRP
Url:            PBURL
Source:         PBREPO/PBSRC
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
%description
PBDESC
%description -l fr
buffer accélère l'écriture des bande sur des périphériques distants
%prep
%setup -q
%build
make %{?_smp_mflags}
%install
%{__rm} -rf $RPM_BUILD_ROOT
install -m 755 -D buffer $RPM_BUILD_ROOT%{_bindir}/buffer
install -m 644 -D buffer.man $RPM_BUILD_ROOT%{_mandir}/man1/buffer.1
%clean
%{__rm} -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc ChangeLog
%doc COPYING README AUTHORS NEWS
%{_bindir}/buffer
%{_mandir}/man1/buffer.1*
%changelog
PBLOG

As you can see globally only few changes :-) Now it's time to test the result of our configuration:

pb -p buffer cms2build
Project: buffer
Action: cms2build
Packages: buffer

Management of buffer 1.19-1 (rev flat)
 ... 2008-05-30 02:18:28 URL:http://hello-penguin.com/software/buffer/buffer-1.19.tar.gz [17920/17920] -> "/users/bruno/tmp/pb.jh8U7Q7VdP/buffer-1.19.tar.gz" [1]
OK
Extracting /users/bruno/tmp/pb.jh8U7Q7VdP/buffer-1.19.tar.gz in /users/bruno/pb/projects/buffer/delivery... OK
Generating fake ChangeLog for test version
Build files generated for debian-3.1,debian-4.0,fedora-4,fedora-5,fedora-6,fedora-7,fedora-8,fedora-9,mandrake-10.1,mandrake-10.2,mandriva-2006.0,mandriva-2007.0,mandriva-2007.1,mandriva-2008.0,mandriva-2008.1,redhat-7.3,redhat-9,rhel-3,rhel-4,rhel-5,sles-10,sles-9,suse-10.0,suse-10.1,suse-10.2,suse-10.3,ubuntu-6.06,ubuntu-7.04,ubuntu-7.10,ubuntu-8.04
No Build files found for gentoo-nover
Creating buffer tar files compressed... OK
Under /users/bruno/pb/projects/buffer/delivery/buffer-1.19.tar.gz

So far so good. We now have a new tar file which contains all the build files expanded for the various distribution supported (even if some of them are not ready yet e.g. .deb in our case).

Go one step further:

pb -p buffer build2pkg
Project: buffer
Action: build2pkg
Packages: buffer
Extracting build files... OK
Building package with /users/bruno/pb/projects/buffer/build/SPECS/buffer.spec under /users/bruno/pb/projects/buffer/build... Executing(%prep): /bin/sh -e /users/bruno/pb/projects/buffer/build/tmp/rpm-tmp.85498
+ umask 022
+ cd /users/bruno/pb/projects/buffer/build/BUILD
+ '[' 1 -eq 1 ']'
+ '[' 1 -eq 1 ']'
+ '[' 1 -eq 1 ']'
+ cd /users/bruno/pb/projects/buffer/build/BUILD
+ rm -rf buffer-1.19
+ /usr/bin/gzip -dc /users/bruno/pb/projects/buffer/build/SOURCES/buffer-1.19.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd buffer-1.19
+ exit 0
Executing(%build): /bin/sh -e /users/bruno/pb/projects/buffer/build/tmp/rpm-tmp.85498
+ umask 022
+ cd /users/bruno/pb/projects/buffer/build/BUILD
+ cd buffer-1.19
+ '[' 1 -eq 1 ']'
+ '[' 1 -eq 1 ']'
+ make -j4
gcc -Wall -O6 -fomit-frame-pointer   -c -o buffer.o buffer.c
gcc -Wall -O6 -fomit-frame-pointer   -c -o sem.o sem.c
sem.c:108: attention : return type defaults to ‘int’
sem.c: In function ‘do_sem’:
sem.c:120: attention : implicit declaration of function ‘getpid’
sem.c:124: attention : ‘return’ with no value, in function returning non-void
buffer.c:133: erreur: conflicting types for ‘shmat’
/usr/include/sys/shm.h:58: erreur: previous declaration of ‘shmat’ was here
buffer.c: In function ‘main’:
buffer.c:274: attention : implicit declaration of function ‘exit’
buffer.c:274: attention : incompatible implicit declaration of built-in function ‘exit’
buffer.c: In function ‘parse_args’:
buffer.c:297: attention : implicit declaration of function ‘atoi’
buffer.c: In function ‘buffer_allocate’:
buffer.c:515: attention : format ‘%08x’ expects type ‘unsigned int’, but argument 4 has type ‘char *’
buffer.c:520: attention : implicit declaration of function ‘bzero’
buffer.c:520: attention : incompatible implicit declaration of built-in function ‘bzero’
buffer.c: In function ‘fill_block’:
buffer.c:695: attention : incompatible implicit declaration of built-in function ‘bzero’
buffer.c: In function ‘byee’:
buffer.c:874: attention : incompatible implicit declaration of built-in function ‘exit’
buffer.c:878: attention : incompatible implicit declaration of built-in function ‘exit’
make: *** [buffer.o] Erreur 1
make: *** Attente des tâches non terminées....
error: Bad exit status from /users/bruno/pb/projects/buffer/build/tmp/rpm-tmp.85498 (%build)


RPM build errors:
    Bad exit status from /users/bruno/pb/projects/buffer/build/tmp/rpm-tmp.85498 (%build)
child (rpmbuild --define 'packager Bruno Cornec <bruno@project-builder.org>' --define "_topdir /users/bruno/pb/projects/buffer/build" -ba /users/bruno/pb/projects/buffer/build/SPECS/buffer.spec) exited with value 1
Checking validity of rpms with rpmlint... Error: no installed packages by name RPMS/*/buffer-1.19-1.mdv2008.1.*.rpm
Error: no installed packages by name SRPMS/buffer-1.19-1.mdv2008.1.src.rpm
OK

Ok, some patches seem to be required to be able to compile and link cleanly that application on my new shiny Mandriva 2008.1.

Note: See TracWiki for help on using the wiki.