I decided to try something a little different because I had some ideas 
for improving the existing EAPI patches I've seen going into other 
eclasses. So here is my patch for x-modular.eclass. I tested it with 
ebuilds using EAPIs 0, 1, and 2, and it appeared to work fine. It 
already happened to have a function called src_configure, so that 
doesn't appear in the patch.

One thing I see as an improvement is a lack of EAPI value checks 
throughout the ebuild to avoid repetition between the function export 
and the function call. Things just check whether a function was 
exported, which is the only place where EAPI value checks happen.

Additionally, the fallback in case statements is "I don't know what to 
do" and supported EAPIs are explicitly defined. This will make it 
obvious when the eclass doesn't support a new EAPI instead of it 
randomly failing after you try it.

Any thoughts?

-- 
Thanks,
Donnie

Donnie Berkholz
Developer, Gentoo Linux
Blog: http://dberkholz.wordpress.com
--- /home/donnie/src/gentoo-x86/eclass/x-modular.eclass 2009-03-06 
12:11:38.000000000 -0800
+++ x-modular.eclass    2009-03-06 12:16:25.000000000 -0800
@@ -26,6 +26,21 @@
 # there. You may also want to change the SLOT.
 XDIR="/usr"
 
+EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_preinst 
pkg_postinst pkg_postrm"
+
+case "${EAPI:-0}" in
+       0|1)
+               ;;
+       2)
+               EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare 
src_configure"
+               ;;
+       *)
+               die "Unknown EAPI ${EAPI}"
+               ;;
+esac
+
+EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
+
 IUSE=""
 HOMEPAGE="http://xorg.freedesktop.org/";
 
@@ -297,6 +312,15 @@
        elibtoolize
 }
 
+# @FUNCTION: x-modular_src_prepare
+# @USAGE:
+# @DESCRIPTION:
+# Prepare a package after unpacking, performing all X-related tasks.
+x-modular_src_prepare() {
+       x-modular_patch_source
+       x-modular_reconf_source
+}
+
 # @FUNCTION: x-modular_src_unpack
 # @USAGE:
 # @DESCRIPTION:
@@ -306,8 +330,7 @@
        x-modular_server_supports_drivers_check
        x-modular_dri_check
        x-modular_unpack_source
-       x-modular_patch_source
-       x-modular_reconf_source
+       has src_prepare ${EXPORTED_FUNCTIONS} || x-modular_src_prepare
 }
 
 # @FUNCTION: x-modular_font_configure
@@ -390,7 +413,7 @@
 # @DESCRIPTION:
 # Compile a package, performing all X-related tasks.
 x-modular_src_compile() {
-       x-modular_src_configure
+       has src_configure ${EXPORTED_FUNCTIONS} || x-modular_src_configure
        x-modular_src_make
 }
 
@@ -645,5 +668,3 @@
 create_font_cache() {
        font_pkg_postinst
 }
-
-EXPORT_FUNCTIONS src_unpack src_compile src_install pkg_preinst pkg_postinst 
pkg_postrm

Attachment: pgpJpw5YxICtk.pgp
Description: PGP signature

Reply via email to