Development/Howto/Spec-Helper

From Mandriva

Jump to: navigation, search
Implementing build policies with spec-helper

Contents


[edit]

How it works

Mandriva Linux policy states that man pages should be bzipped, amongst others. In order to ease the creation of packages, and to keep them as vendor neutral as possible, we use a hook in rpm to automatically enforce the policy.

Take a look at the file /usr/lib/rpm/brp-mandrake. These are the "build root policies", which is a set of rules to be applied after the build. The configuration of the BRP is made by using a macro, %_os_install_post. For Mandriva Linux, you can see it in /usr/lib/rpm/.

So, we see that /usr/lib/rpm/brp-mandrake is run when an rpm is built.

This script checks for /usr/share/spec-helper/spec-helper and runs it. And, spec-helper runs some scripts. We will describe how to add a script to spec-helper.

[edit]

Writing the script

First, find a name for your script. To give a full exemple, we will add a script that runs pngcrush on each png in an rpm. Let's call it png_crush_rpm. Don't use pngcrush, because this is already a valid executable on the system. Since /usr/share/spec_helper is added to the path by the script, it will not work as expected.

It seems that you have a choice for the language. In the current spec-helper ( spec-helper-0.9.2-1mdk when writing theses lines ), we have four perl scripts, three bash scripts and one python script. I will use shell, since it is simpler.

You can use any language, but remember that using a new language will add a dependancy to the spec-helper rpm. Using a new program, such as pngcrush will also add more dependencies, that should be added to the rpm. Please keep this in mind.

So all you have to do is to apply your script to $RPM_BUILD_ROOT. Don't forget to check if the variable is defined, and it is a valid directory. You should exit in case of problem.

#!/bin/sh


# test if $RPM_BUILD_ROOT is set
if [ -z $RPM_BUILD_ROOT ]; then
   exit 0
fi;

# check if it is a valid directory.
[ -d $RPM_BUILD_ROOT ] || exit 0

# find each png, and crush it.
for i in ind $RPM_BUILD_ROOT -type f -name '*.png' ; do
   pngcrush -q $i $i.new
   mv -f $i.new $i
done;

Do not forget to set the executable (+x) bit on the file.

Test it by defining RPM_BUILD_ROOT by hand, and check if this is correct.

[edit]

Adding the test to spec-helper

Now we should add it to spec-helper.

You should add an option to be able to not run the script to spec-helper. So add these other options:

echo "-png don't run pngcrsuh on png." 1>&2

and

-png) DONT_PNG_CRUSH=1;;

in the switch/case.

These instructions are valid for the rpm-4.2-16mdk. If no longer valid, please feel free to change this page.

Now all that remains is to invoke your script:

test -z "$DONT_PNG_CRUSH" && echo -n "Recompressing png..." && png_crush_rpm && echo "done"

And now, rpm will run your script when rebuilding.

Test it, and if you find it is useful, send your patch to Mandriva ( using Bugzilla if possible, or to the spec-helper maintainer ).

[edit]

Disabling a build policy in a specfiles

Sometimes, build policies can have an unwanted effect. One example is when you do not want to strip your executable, for debugging purposes. You can disable it by setting the correct variable in the %install section :

%install
rm -rf $RPM_BUILD_ROOT
%makeinstall
....
# prevent the stripping of executable 
export DONT_STRIP=1

%clean

See the shell script /usr/share/spec-helper/spec-helper for the list of possible variables. Here is a list ( may not be current ) :

  • DONT_CLEANUP, do not remove backup and useless files
  • DONT_CLEAN_PERL, remove some perl files not needed ( .packlist, etc. )
  • DONT_COMPRESS, compress manpages and info files in bz2
  • DONT_STRIP, strip object files and executable
  • DONT_RELINK, relativise symlinks
  • DONT_SYMLINK_LIBS, create a symlink of the library
  • DONT_GPRINTIFY, replace echo by grpintf in initscript ( see Initscripts Howto )
  • DONT_FIX_PAMD_CONFIGS, fix /lib for /lib64 in pam configs
  • DONT_REMOVE_INFO_DIR, remove /usr/share/info/dir/
  • DONT_FIX_MO, fix some translations
  • DONT_TRANSLATE_MENU, translate the menu section from the old scheme to the new one ( see Menu System Howto ).
Personal tools