Spec-helper

Материал из Rosalab Wiki
Версия от 12:43, 9 февраля 2012; D uragan (обсуждение | вклад) (Adopted spec-helper page)

(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Это снимок страницы. Он включает старые, но не удалённые версии шаблонов и изображений.
Перейти к: навигация, поиск
Implementing build policies with spec-helper

How it works

Spec-helper provides a set ot scripts that are automatically launched during the build process to ease the creation of rpm packages conforming to ROSA Linux packaging policies.

For example, ROSA Linux policy states that man pages should be compressed with xz, 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 /usr/lib/rpm/brp-* files. 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 ROSA Linux, you can see it in /usr/lib/rpm/.

So, we see that most of the /usr/lib/rpm/brp-* files are run when an rpm is built.

Scripts used by spec-helper are located at /usr/share/spec-helper folder. The scripts which will be actually launched are set in the /etc/rpm/macros.d/spec-helper.macros file. We will describe how to add a script to spec-helper.

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 we have scripts in perl, bash and python script. In the examples below, we will use shell.

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.

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.

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 ROSA Linux developers.

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 %{buildroot}
%makeinstall
....
# prevent the stripping of executable 
export DONT_STRIP=1

%clean

See the /etc/rpm/macros.d/spec-helper.macros file 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 policy )
  • 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 ).

Замечание:
This page is based on the Mandriva spec-helper description.