From Fedora Project Wiki
(Paste proposed changes)
Line 7: Line 7:
This page describes items that need to be changed in the [http://fedoraproject.org/wiki/Packaging/PHP PHP Guidelines]  or other items that need to be reviewed or ratified by the [http://fedoraproject.org/wiki/Packaging/Committee Fedora Packaging Comittee]  and [http://fedoraproject.org/wiki/Development/SteeringCommittee FESCo] .
This page describes items that need to be changed in the [http://fedoraproject.org/wiki/Packaging/PHP PHP Guidelines]  or other items that need to be reviewed or ratified by the [http://fedoraproject.org/wiki/Packaging/Committee Fedora Packaging Comittee]  and [http://fedoraproject.org/wiki/Development/SteeringCommittee FESCo] .


Section 2 is the current Guidelines to allow simple diff.
Section 2 is the current Guidelines + proposed changed to allow simple diff.
 


= Guidelines for packaging PHP addon modules =
= Guidelines for packaging PHP addon modules =




== Different kinds of packages ==
== Different kinds of packages ==


There are basically two different kinds of php modules, which are packaged for Fedora Extras:
There are basically 4 different kinds of php modules, which are packaged for Fedora Extras:


* [http://pecl.php.net PECL]  (PHP Extention Community Library), which are PHP modules usually written in C, which are dynamically loaded by the PHP interpreter on startup.
* [http://pecl.php.net PECL]  (PHP Extention Community Library), which are PHP modules usually written in C, which are dynamically loaded by the PHP interpreter on startup.
* [http://pear.php.net PEAR]  (PHP Extension and Application Repository), which are reusable components written in PHP, usually classes, which can be used in your own PHP applications and scripts by using e.g. the include() directive.
* [http://pear.php.net PEAR]  (PHP Extension and Application Repository), which are reusable components written in PHP, usually classes, which can be used in your own PHP applications and scripts by using e.g. the include() directive.
* CHANNEL : a package which register a channel. A channel is a repository which provides php extensions
* Other package providing php extension not handled by pear/pecl mechanisms
While upstream used the same package and distribution format for PECL and PEAR, creating RPMs has to take some differences into account.
3 channels are defined on installation of php-pear
* <code>pear.php.net</code> (alias pear) : the default channel for PHP Extension and Application Repository
* <code>pecl.php.net</code> (alias pecl) : the default channel for PHP Extension Community Library
* <code>__uri</code> : Pseudo-channel for static packages


While upstream used the same package and distribution format for both, creating RPMs has to take some differences into account.
Other channels must be configured at RPM build time and at at RPM installation time.
 
'''FPC notes''' : we already have 4 extras channels in repository (phing, phpdb, symfony and phpunit). A new one (ezc) is on the road. This Guidelines update proposal "try" to avoid change for already approved packages.


{{Anchor|NamingScheme}}
{{Anchor|NamingScheme}}
== Naming scheme ==
== Naming scheme ==


* PECL packages should be named ''php-pecl-PECLPackageName-%{version}-%{release}.%{arch}.rpm''.
* PECL packages from standard pecl channel should be named php-pecl-PECLPackageName-%{version}-%{release}.%{arch}.rpm.
* PEAR packages should be named ''php-pear-PEARPackageName-%{version}-%{release}.noarch.rpm''.
* PEAR packages from standard pear channel should be named php-pear-PEARPackageName-%{version}-%{release}.noarch.rpm.
* CHANNEL packages should be named php-channel-ChannelAlias-%{version}-%{release}.noarch.rpm
* Packages from another channel  should be named php-ChannelAlias-PackageName-%{version}-%{release}.noarch.rpm.
* Other packages should be named ''php-PackageName-%{version}-%{release}.%{arch}.rpm''; %{arch} can be "noarch" where appropriate.
* Other packages should be named ''php-PackageName-%{version}-%{release}.%{arch}.rpm''; %{arch} can be "noarch" where appropriate.


Line 35: Line 48:


Note that web applications that happen to be written in PHP do not belong under the php-* namespace.
Note that web applications that happen to be written in PHP do not belong under the php-* namespace.
'''FPC notes''' : PECL/PEAR package from standard channel also follow naming scheme for packages from another channel :)
Packages which doesn't follow this Guidelines update:
* php-pear-creole => php-phpdb-creole
* php-pear-propel_runtime => php-phpdb-propel-runtime
* php-pear-propel_generator => php-phpdb-propel-generator
* php-pear-phing => php-phing-phing
* php-pear-PHPUnit => php-phpunit-PHPUnit
* php-pear-pake => php-symfony-pake
We could probably accept an exception for this already accepted packages


== File Placement ==
== File Placement ==
Line 42: Line 67:
== Requires and Provides ==
== Requires and Provides ==


=== PEAR Packages ===
=== PEAR Packages from the standard channel/repository ===


A PEAR package '''MUST''' have:
A PEAR package '''MUST''' have:
Line 52: Line 77:
Requires(postun): %{__pear}
Requires(postun): %{__pear}
Provides:    php-pear(foo) = %{version}
Provides:    php-pear(foo) = %{version}
</pre>
=== Packages for CHANNEL (repository) configuration  ===
A CHANNEL package ''''MUST''' have :
<pre>
Requires: php-pear(PEAR)
Requires(post): %{__pear}
Requires(postun): %{__pear}
Provides: php-channel(channelname)
</pre>
=== PEAR Packages from a non standard channel/repository ===
A PEAR package '''MUST''' have:
<pre>
BuildRequires: php-channel(channelname)
BuildRequires: php-pear(PEAR)
Requires: php-pear(PEAR)
Requires(post): %{__pear}
Requires(postun): %{__pear}
Requires: php-channel(channelname)
Provides:    php-pear(channelname/foo) = %{version}
</pre>
</pre>


Line 75: Line 124:
=== Other Packages ===
=== Other Packages ===


PHP addons which are neither PEAR nor PECL should require what makes sense (either a base PHP version or a php-api as necessary).
PHP addons which are neither PEAR nor PECL should require what makes sense (either a base PHP version or a php-api, php(zend-abi) as necessary).


== Macros and scriptlets ==
== Macros and scriptlets ==
=== Packages for CHANNEL (repository) configuration  ===
And here are some recommended scriptlets for properly registering  and unregistering the channel:
<pre>
%post
if [ $1 -eq  1 ] ; then
  %{__pear} channel-add %{pear_xmldir}/%{name}.xml > /dev/null || :
else
  %{__pear} channel-update %{pear_xmldir}/%{name}.xml > /dev/null ||:
fi
%postun
if [ $1 -eq 0 ] ; then
  %{__pear} channel-delete %{channelname} > /dev/null || :
fi
</pre>
'''FPC notes''' : I recommend to use %{name} for XML file rather than channel or extension name to avoid possible conflicts


=== PEAR Modules ===
=== PEAR Modules ===
Line 92: Line 162:
BuildRequires:    php-pear >= 1:1.4.9-1.2
BuildRequires:    php-pear >= 1:1.4.9-1.2
Provides:        php-pear(PackageName) = %{version}
Provides:        php-pear(PackageName) = %{version}
Requires:        php >= 4.3, php-pear(PEAR)
Requires:        php-common >= 4.3, php-pear(PEAR)
Requires(post):  %{_bindir}/pear
Requires(post):  %{_bindir}/pear
Requires(postun): %{_bindir}/pear
Requires(postun): %{_bindir}/pear
</pre>
</pre>


And here are some recommended scriptlets for properly registering and unregistering the module:
'''FPC notes''' : i change php to php-common (to avoid httpd dependency)
 
And here are some recommended scriptlets for properly registering the module:
<pre>
<pre>
%post
%post
%{_bindir}/pear install --nodeps --soft --force --register-only %{pear_xmldir}/Foo_Bar.xml >/dev/null ||:
%{_bindir}/pear install --nodeps --soft --force --register-only %{pear_xmldir}/%{name}.xml >/dev/null ||:
</pre>
 
'''FPC notes''' : I also recommend to use %{name} for XML file rather than extension name to avoid possible conflicts
(we can only use this for non standard channel ank keep using extension name for standard one and for existing package)


And here are some recommended scriptlets for properly unregistering the module, from the standard channel:
<pre>
%postun
%postun
if [ "$1" -eq "0" ] ; then
if [ "$1" -eq "0" ] ; then
Line 107: Line 185:
fi
fi
</pre>
</pre>
From a non standard channel (pear command requires the channel):
<pre>
%postun
if [ "$1" -eq "0" ] ; then
%{_bindir}/pear uninstall --nodeps --ignore-errors --register-only Foo_channel/Foo_Bar >/dev/null ||:
fi
</pre>


=== PECL Modules ===
=== PECL Modules ===

Revision as of 18:01, 16 February 2009

[[TableOfContents(3)]

Proposed Changes to PHP Guidelines

Synopsis

This page describes items that need to be changed in the PHP Guidelines or other items that need to be reviewed or ratified by the Fedora Packaging Comittee and FESCo .

Section 2 is the current Guidelines + proposed changed to allow simple diff.


Guidelines for packaging PHP addon modules

Different kinds of packages

There are basically 4 different kinds of php modules, which are packaged for Fedora Extras:

  • PECL (PHP Extention Community Library), which are PHP modules usually written in C, which are dynamically loaded by the PHP interpreter on startup.
  • PEAR (PHP Extension and Application Repository), which are reusable components written in PHP, usually classes, which can be used in your own PHP applications and scripts by using e.g. the include() directive.
  • CHANNEL : a package which register a channel. A channel is a repository which provides php extensions
  • Other package providing php extension not handled by pear/pecl mechanisms

While upstream used the same package and distribution format for PECL and PEAR, creating RPMs has to take some differences into account.

3 channels are defined on installation of php-pear

  • pear.php.net (alias pear) : the default channel for PHP Extension and Application Repository
  • pecl.php.net (alias pecl) : the default channel for PHP Extension Community Library
  • __uri : Pseudo-channel for static packages

Other channels must be configured at RPM build time and at at RPM installation time.

FPC notes : we already have 4 extras channels in repository (phing, phpdb, symfony and phpunit). A new one (ezc) is on the road. This Guidelines update proposal "try" to avoid change for already approved packages.

Naming scheme

  • PECL packages from standard pecl channel should be named php-pecl-PECLPackageName-%{version}-%{release}.%{arch}.rpm.
  • PEAR packages from standard pear channel should be named php-pear-PEARPackageName-%{version}-%{release}.noarch.rpm.
  • CHANNEL packages should be named php-channel-ChannelAlias-%{version}-%{release}.noarch.rpm
  • Packages from another channel should be named php-ChannelAlias-PackageName-%{version}-%{release}.noarch.rpm.
  • Other packages should be named php-PackageName-%{version}-%{release}.%{arch}.rpm; %{arch} can be "noarch" where appropriate.

Please make sure that the PEAR package is correctly being built for noarch.

The PECLPackageName and the PEARPackageName should be consistent with the upstream naming scheme. The Crack PHP Extension would thus be named php-pecl-crack with the resulting packages being php-pecl-crack-0.4-1.i386.rpm and php-pecl-crack-0.4-1.src.rpm.

Note that web applications that happen to be written in PHP do not belong under the php-* namespace.

FPC notes : PECL/PEAR package from standard channel also follow naming scheme for packages from another channel :)

Packages which doesn't follow this Guidelines update:

  • php-pear-creole => php-phpdb-creole
  • php-pear-propel_runtime => php-phpdb-propel-runtime
  • php-pear-propel_generator => php-phpdb-propel-generator
  • php-pear-phing => php-phing-phing
  • php-pear-PHPUnit => php-phpunit-PHPUnit
  • php-pear-pake => php-symfony-pake

We could probably accept an exception for this already accepted packages

File Placement

Non-PEAR PHP extensions should put their Class files in /usr/share/php.

Requires and Provides

PEAR Packages from the standard channel/repository

A PEAR package MUST have:

BuildRequires: php-pear(PEAR)
Requires: php-pear(PEAR)
Requires(post): %{__pear}
Requires(postun): %{__pear}
Provides:     php-pear(foo) = %{version}

Packages for CHANNEL (repository) configuration

A CHANNEL package 'MUST have :

Requires: php-pear(PEAR)
Requires(post): %{__pear}
Requires(postun): %{__pear}
Provides: php-channel(channelname)

PEAR Packages from a non standard channel/repository

A PEAR package MUST have:

BuildRequires: php-channel(channelname)
BuildRequires: php-pear(PEAR)
Requires: php-pear(PEAR)
Requires(post): %{__pear}
Requires(postun): %{__pear}
Requires: php-channel(channelname)
Provides:     php-pear(channelname/foo) = %{version}

PECL Packages

A PECL package MUST have:

BuildRequires: php-devel, php-pear
Requires(post): %{__pecl}
Requires(postun): %{__pecl}

%if %{?php_zend_api}0
Requires:     php(zend-abi) = %{php_zend_api}
Requires:     php(api) = %{php_core_api}
%else
Requires:     php-api = %{php_apiver}
%endif

Provides:     php-pecl(foo) = %{version}

Other Packages

PHP addons which are neither PEAR nor PECL should require what makes sense (either a base PHP version or a php-api, php(zend-abi) as necessary).

Macros and scriptlets

Packages for CHANNEL (repository) configuration

And here are some recommended scriptlets for properly registering and unregistering the channel:

%post
if [ $1 -eq  1 ] ; then
   %{__pear} channel-add %{pear_xmldir}/%{name}.xml > /dev/null || :
else
   %{__pear} channel-update %{pear_xmldir}/%{name}.xml > /dev/null ||:
fi

%postun
if [ $1 -eq 0 ] ; then
   %{__pear} channel-delete %{channelname} > /dev/null || :
fi

FPC notes : I recommend to use %{name} for XML file rather than channel or extension name to avoid possible conflicts


PEAR Modules

The php-pear package in Fedora Core 5 and above (version 1:1.4.9-1.2) provides several useful macros:

  • %{pear_phpdir}
  • %{pear_docdir}
  • %{pear_testdir}
  • %{pear_datadir}
  • %{pear_xmldir}

These defintions for the .spec should be of interest:

BuildRequires:    php-pear >= 1:1.4.9-1.2
Provides:         php-pear(PackageName) = %{version}
Requires:         php-common >= 4.3, php-pear(PEAR)
Requires(post):   %{_bindir}/pear
Requires(postun): %{_bindir}/pear

FPC notes : i change php to php-common (to avoid httpd dependency)

And here are some recommended scriptlets for properly registering the module:

%post
%{_bindir}/pear install --nodeps --soft --force --register-only %{pear_xmldir}/%{name}.xml >/dev/null ||:

FPC notes : I also recommend to use %{name} for XML file rather than extension name to avoid possible conflicts (we can only use this for non standard channel ank keep using extension name for standard one and for existing package)

And here are some recommended scriptlets for properly unregistering the module, from the standard channel:

%postun
if [ "$1" -eq "0" ] ; then
%{_bindir}/pear uninstall --nodeps --ignore-errors --register-only Foo_Bar >/dev/null ||:
fi

From a non standard channel (pear command requires the channel):

%postun
if [ "$1" -eq "0" ] ; then
%{_bindir}/pear uninstall --nodeps --ignore-errors --register-only Foo_channel/Foo_Bar >/dev/null ||:
fi


PECL Modules

The php-pear package in Fedora Core 5 and above (version 1:1.4.9-1.2) provides several useful macros:

  • %{pecl_phpdir}
  • %{pecl_docdir}
  • %{pecl_testdir}
  • %{pecl_datadir}
  • %{pecl_xmldir}

You may need to define a few additional macros to extract some information from PHP. It is recommended that you use the following:

%global php_apiver  %((echo 0; php -i 2>/dev/null | sed -n 's/^PHP API => //p') | tail -1)
%{!?__pecl:     %{expand: %%global __pecl     %{_bindir}/pecl}}
%{!?php_extdir: %{expand: %%global php_extdir %(php-config --extension-dir)}}

And here are some recommended scriptlets for properly registering and unregistering the module:

%if 0%{?pecl_install:1}
%post
%{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || :
%endif


%if 0%{?pecl_uninstall:1}
%postun
if [ $1 -eq 0 ]  ; then
%{pecl_uninstall} %{pecl_name} >/dev/null || :
fi
%endif

Other Modules

If your module includes compiled code, you may need to define some macros to extract some information from PHP. It is recommended that you user the following:

%global php_apiver  %((echo 0; php -i 2>/dev/null | sed -n 's/^PHP API => //p') | tail -1)
%global php_extdir  %(php-config --extension-dir 2>/dev/null || echo "undefined")
%global php_version %(php-config --version 2>/dev/null || echo 0)

Additional Hints for Packagers

PEAR & PECL Packages

The source archive contains a package.xml outside any directory, so you have to use use

%setup -q -c

in your %prep section to avoid writing files to the build root.

PEAR Packages

To create your initial specfile, you can use the default template provided by the rpmdevtools package:

fedora-newrpmspec -t php-pear php-pear-Foo

Or you can generate one; make sure you have the php-pear-PEAR-Command-Packaging package installed:

pear make-rpm-spec Foo.tgz

Packages with Optional Requires

TODO: Some PEAR packages such as Auth have many other PEAR packages that are optional Requires. We need to discuss how to handle splitting up large packages such as this.

Other Items

No additional items required.