Skip to content

Instantly share code, notes, and snippets.

@kentfredric
Created January 11, 2014 13:32
Show Gist options
  • Save kentfredric/8370999 to your computer and use it in GitHub Desktop.
Save kentfredric/8370999 to your computer and use it in GitHub Desktop.
--- /usr/portage/eclass/perl-module.eclass 2013-12-30 11:01:16.000000000 +1300
+++ /tmp/perl-module-r1.eclass 2014-01-12 02:30:27.526844896 +1300
@@ -52,6 +52,22 @@
;;
esac
+case "${PERL_MODULE_TOOLKIT//[[:space:]]/}" in
+ mb)
+ DEPEND="${DEPEND} virtual/perl-Module-Build"
+ ;;
+ mbtiny)
+ DEPEND="${DEPEND} dev-perl/Module-Build-Tiny"
+ ;;
+ eumm)
+ DEPEND="${DEPEND} virtual/perl-ExtUtils-MakeMaker"
+ ;;
+ none|'')
+ ;;
+ *)
+ die "PERL_MODULE_TOOLKIT=${PERL_MODULE_TOOLKIT} is not supported by perl-module.eclass"
+esac
+
case "${PERL_EXPORT_PHASE_FUNCTIONS:-yes}" in
yes)
EXPORT_FUNCTIONS ${PERL_EXPF}
@@ -103,6 +119,259 @@
perl-module_src_prep
}
+
+# @ECLASS-VARIABLE: PERL_MODULE_TOOLKIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Declares the intended toolkit that the current package should use.
+#
+# This variable is intended to be set prior to inheriting perl-module.eclass,
+# and if specified, will intelligently add some minimal dependencies to ensure
+# that the specified toolkit can be imagined to work.
+#
+# Additionally, this variable controls how toolkits are invoked, and triggers
+# QA Warnings if the source tree has indicators that it is not the specified tooling.
+#
+# Rationale however for this variable is partially the fact you can't declare
+# dependencies by fetching SRC_URI and scraping the fetched files,
+# so declaration of some type is required, and failing to declare correctly
+# leads to installation failure.
+#
+# Valid values:
+# @CODE
+# eumm mb mbtiny none
+# @CODE
+#
+
+# @FUNCTION: perl-module-toolkit
+# @USAGE: <output_variable_name>
+# @DESCRIPTION:
+# Determine the toolkit for the current package.
+# This respects the value of PERL_MODULE_TOOLKIT if specified
+# and otherwise attempts to detect the right value with some basic heuristics.
+#
+# Example:
+# @CODE
+# local somevar;
+# perl-module-toolkit somevar;
+# @CODE
+#
+# This will cause 'somevar' to contain the detected/specified toolkit verb.
+#
+perl-module-toolkit() {
+ local _output=$1;
+ local _result='';
+ if [[ -n ${PERL_MODULE_TOOLKIT} ]]; then
+ _result=${PERL_MODULE_TOOLKIT//[[:space:]]/};
+ eval $_output=\$_result;
+ return 0;
+ fi
+ eqawarn "QA Notice: The ebuild does not declare PERL_MODULE_TOOLKIT to determine install process"
+ eqawarn " Reverting to sniffing may cause later subtle errors";
+ if [[ -n ${PERLQAFATAL} ]]; then
+ eerror "Bailing due to PERLQAFATAL=1";
+ die;
+ fi
+ if [[ -f Build.PL ]]; then
+ if grep 'Module::Build::Tiny' Build.PL >/dev/null; then
+ einfo "Sniffed Module::Build::Tiny";
+ _result="mbtiny";
+ eval $_output=\$_result;
+ return 0
+ fi;
+ einfo "Sniffed Module::Build";
+ _result="mb";
+ eval $_output=\$_result;
+ return 0;
+ fi
+ if [[ -f Makefile.PL ]]; then
+ einfo "Sniffed ExtUtils::MakeMaker";
+ _result="eumm";
+ eval $_output=\$_result;
+ return 0;
+ fi;
+ eerror "Could not determine PERL_MODULE_TOOLKIT automatically. Bailing";
+ die;
+ return 1;
+}
+
+# @FUNCTION: perl-module-check-toolkit-mb
+# @DESCRIPTION:
+# Perform sanity checks to make sure the package can be built with Module::Build.
+#
+# Fatal Checks:
+# - Checks Build.PL exists
+# QA Checks:
+# - Checks dependencies are sane
+# - Checks Build.PL has competing tools like "use Module::Build::Tiny"
+#
+perl-module-check-toolkit-mb() {
+ einfo "using Module::Build";
+ if [[ ! -f Build.PL ]]; then
+ eerror "PERL_MODULE_TOOLKIT=mb requires Build.PL";
+ die;
+ fi
+
+ # Module::Build is slated to be removed from Perl around 5.20
+ # which subsequently means accidental failure to depend on Module::Build
+ # could cause random unexpected failures if it is not magically already installed.
+ #
+ # So A QA Warning should be heeded as it indicates a future failure likely.
+ #
+ if [[ "${DEPEND}" != *"virtual/perl-Module-Build"* ]]; then
+ eqawarn "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
+ eqawarn " Add virtual/perl-Module-Build to DEPEND to prevent possible compile failure!"
+ if [[ -n ${PERLQAFATAL} ]]; then
+ eerror "Bailing out due to PERLQAFATAL=1";
+ die;
+ fi
+ fi
+ if grep 'use\s+Module::Build::Tiny' Build.PL >/dev/null; then
+ eqawarn "QA Notice: Module::Build toolkit indicated, but Build.PL suggests Module::Build::Tiny!"
+ eqawarn " File a bug if investigation confirms tooling is Module::Build::Tiny,"
+ eqawarn " as it may be responsible for a subsequent compile failure!"
+ if [[ -n ${PERLQAFATAL} ]]; then
+ eerror "Bailing out due to PERLQAFATAL=1";
+ die;
+ fi
+ fi
+ return 0;
+}
+
+# @FUNCTION: perl-module-check-toolkit-eumm
+# @DESCRIPTION:
+# Perform sanity checks to make sure the package can be built with ExtUtils::MakeMaker
+#
+# Fatal Checks:
+# - Checks Makefile.PL exists
+#
+perl-module-check-toolkit-eumm() {
+ einfo "using ExtUtils::MakeMaker";
+ if [[ ! -f Makefile.PL ]]; then
+ eerror "PERL_MODULE_TOOLKIT=eumm requires Makefile.PL";
+ die;
+ fi
+
+ # This logic is presently disabled because eumm is generally reliable to be in core
+ # and a large amount of ebuilds will use it without dependency, but its never likely to
+ # become a problem, so an onslaught of warnings are not welcome at this time.
+ #
+ #if [[ "${DEPEND}" != *"virtual/perl-ExtUtils-MakeMaker"* ]]; then
+ # eqawarn "QA Notice: The ebuild uses ExtUtils::MakeMaker but doesn't depend on it."
+ # eqawarn " Add virtual/perl-ExtUtils-MakeMaker to DEPEND!"
+ # if [[ -n ${PERLQAFATAL} ]]; then
+ # eerror "Bailing out due to PERLQAFATAL=1";
+ # die;
+ # fi
+ #fi
+ return 0;
+}
+
+# @FUNCTION: perl-module-check-toolkit-mbtiny
+# @DESCRIPTION:
+# Perform sanity checks to make sure the package can be built with Module::Build::Tiny
+#
+# Fatal Checks:
+# - Checks Build.PL exists
+#
+# QA Checks:
+# - Checks dependencies are sane
+# - Checks Build.PL has competing tools like "use Module::Build"
+#
+perl-module-check-toolkit-mbtiny() {
+ einfo "Module::Build::Tiny";
+ if [[ ! -f Build.PL ]]; then
+ eerror "PERL_MODULE_TOOLKIT=mbtiny requires Build.PL";
+ die;
+ fi
+ if [[ "${DEPEND}" != *"dev-perl/Module-Build-Tiny"* ]]; then
+ eqawarn "QA Notice: The ebuild uses Module::Build::Tiny but doesn't depend on it."
+ eqawarn " Add dev-perl/Module-Build-Tiny to DEPEND to prevent LIKELY compile failure!"
+ if [[ -n ${PERLQAFATAL} ]]; then
+ eerror "Bailing out due to PERLQAFATAL=1";
+ die;
+ fi
+ fi
+ if grep 'use\s+Module::Build\s*;' Build.PL >/dev/null; then
+ eqawarn "QA Notice: Module::Build::Tiny toolkit indicated, but Build.PL suggests Module::Build!"
+ eqawarn " File a bug if investigation confirms tooling is Module::Build,"
+ eqawarn " as it may be responsible for a subsequent compile failure!"
+ if [[ -n ${PERLQAFATAL} ]]; then
+ eerror "Bailing out due to PERLQAFATAL=1";
+ die;
+ fi
+ fi
+ return 0;
+}
+
+# @FUNCTION: perl-module-check-toolkit-none
+# @DESCRIPTION:
+# Fallback method for explicit declaration of PERL_MODULE_TOOLKIT='none'
+# or PERL_MODULE_TOOLKIT=''
+#
+perl-module-check-toolkit-none() {
+ einfo "'none' perl-module.eclass toolkit specified";
+ return 0;
+}
+
+# @FUNCTION: perl-module-check-toolkit
+# @USAGE: <toolkitname>
+#
+# Executes the validation check for the specified toolkit name.
+#
+# Example:
+# @CODE
+# local toolkit
+# perl-module-toolkit toolkit;
+# perl-module-check-toolkit $toolkit;
+# @CODE
+#
+# This will detect the toolkit using perl-module-toolkit
+# and then validate the detected toolkits validity.
+#
+# @CODE
+# perl-module-check-toolkit 'mb';
+# @CODE
+# on its own simply serves to call perl-module-check-toolkit-mb
+#
+# But additional logic is implemented to safely guard against calling functions
+# that are known not to exist.
+#
+# so
+# @CODE
+# perl-module-check-toolkit 'bogus'
+# @CODE
+#
+# is expected to fail
+#
+# Additionally:
+# @CODE
+# perl-module-check-toolkit ''
+# perl-module-check-toolkit 'none';
+# @CODE
+#
+# Both do the same thing.
+#
+# All whitespace in the passed variable is ignored.
+#
+perl-module-check-toolkit() {
+ local _toolkit=$1;
+
+ # Removes all whitespace
+ local _trimmed_toolkit=${_toolkit//[[:space:]]/};
+
+ case "$_trimmed_toolkit" in
+ mb|eumm|mbtiny)
+ perl-module-check-toolkit-${_trimmed_toolkit};
+ return $?;;
+ ''|none)
+ perl-module-check-toolkit-none;
+ return $?;;
+ esac;
+ eerror "Toolkit ${_toolkit} does not exist. New/Old enough perl-module.eclass?";
+ die;
+}
+
perl-module_src_prep() {
debug-print-function $FUNCNAME "$@"
[[ ${SRC_PREP} = yes ]] && return 0
@@ -121,41 +390,39 @@
local myconf_local=("${myconf[@]}")
fi
- if [[ ( ${PREFER_BUILDPL} == yes || ! -f Makefile.PL ) && -f Build.PL ]] ; then
- einfo "Using Module::Build"
- if [[ ${DEPEND} != *virtual/perl-Module-Build* && ${PN} != Module-Build ]] ; then
- eqawarn "QA Notice: The ebuild uses Module::Build but doesn't depend on it."
- eqawarn " Add virtual/perl-Module-Build to DEPEND!"
- if [[ -n ${PERLQAFATAL} ]]; then
- eerror "Bailing out due to PERLQAFATAL=1";
- die;
- fi
- fi
- set -- \
- --installdirs=vendor \
- --libdoc= \
- --destdir="${D}" \
- --create_packlist=0 \
- "${myconf_local[@]}"
- einfo "perl Build.PL" "$@"
- perl Build.PL "$@" <<< "${pm_echovar}" \
- || die "Unable to build!"
- elif [[ -f Makefile.PL ]] ; then
- einfo "Using ExtUtils::MakeMaker"
- set -- \
- PREFIX=${EPREFIX}/usr \
- INSTALLDIRS=vendor \
- INSTALLMAN3DIR='none' \
- DESTDIR="${D}" \
- "${myconf_local[@]}"
- einfo "perl Makefile.PL" "$@"
- perl Makefile.PL "$@" <<< "${pm_echovar}" \
- || die "Unable to build!"
- fi
- if [[ ! -f Build.PL && ! -f Makefile.PL ]] ; then
- einfo "No Make or Build file detected..."
- return
- fi
+ local toolkit;
+ perl-module-toolkit toolkit;
+ perl-module-check-toolkit $toolkit;
+
+
+ case "${toolkit//[[:space:]]/}" in
+ mb|mbtiny)
+ set -- \
+ --installdirs=vendor \
+ --libdoc= \
+ --destdir="${D}" \
+ --create_packlist=0 \
+ "${myconf_local[@]}"
+ einfo "perl Build.PL" "$@"
+ perl Build.PL "$@" <<< "${pm_echovar}" \
+ || die "Unable to build!"
+ ;;
+ eumm)
+ set -- \
+ PREFIX=${EPREFIX}/usr \
+ INSTALLDIRS=vendor \
+ INSTALLMAN3DIR='none' \
+ DESTDIR="${D}" \
+ "${myconf_local[@]}"
+ einfo "perl Makefile.PL" "$@"
+ perl Makefile.PL "$@" <<< "${pm_echovar}" \
+ || die "Unable to build!"
+ ;;
+ none|'')
+ einfo "No Tookit detected."
+ ;;
+ esac
+ return;
}
perl-module_src_compile() {
@@ -170,18 +437,24 @@
local mymake_local=("${mymake[@]}")
fi
- if [[ -f Build ]] ; then
- ./Build build \
- || die "Compilation failed"
- elif [[ -f Makefile ]] ; then
- set -- \
- OTHERLDFLAGS="${LDFLAGS}" \
- "${mymake_local[@]}"
- einfo "emake" "$@"
- emake "$@" \
- || die "Compilation failed"
-# OPTIMIZE="${CFLAGS}" \
- fi
+ local toolkit;
+ perl-module-toolkit toolkit;
+
+ case "${toolkit//[[:space:]]/}" in
+ mb|mbtiny)
+ ./Build build \
+ || die "Compilation failed"
+ ;;
+ eumm)
+ set -- \
+ OTHERLDFLAGS="${LDFLAGS}" \
+ "${mymake_local[@]}"
+ einfo "emake" "$@"
+ emake "$@" \
+ || die "Compilation failed"
+ ;;
+ # OPTIMIZE="${CFLAGS}" \
+ esac
}
# For testers:
@@ -207,17 +480,23 @@
perl-module_src_test() {
debug-print-function $FUNCNAME "$@"
+ local toolkit;
+ perl-module-toolkit toolkit;
+
if has 'do' ${SRC_TEST} || has 'parallel' ${SRC_TEST} ; then
if has "${TEST_VERBOSE:-0}" 0 && has 'parallel' ${SRC_TEST} ; then
export HARNESS_OPTIONS=j$(makeopts_jobs)
einfo "Test::Harness Jobs=$(makeopts_jobs)"
fi
${perlinfo_done} || perl_set_version
- if [[ -f Build ]] ; then
- ./Build test verbose=${TEST_VERBOSE:-0} || die "test failed"
- elif [[ -f Makefile ]] ; then
- emake test TEST_VERBOSE=${TEST_VERBOSE:-0} || die "test failed"
- fi
+ case "${toolkit//[[:space:]]/}" in
+ mb|mbtiny)
+ ./Build test verbose=${TEST_VERBOSE:-0} || die "test failed"
+ ;;
+ eumm)
+ emake test TEST_VERBOSE=${TEST_VERBOSE:-0} || die "test failed"
+ ;;
+ esac
fi
}
@@ -242,17 +521,27 @@
local myinst_local=("${myinst[@]}")
fi
- if [[ -f Build ]] ; then
- ./Build ${mytargets} \
+ local toolkit;
+ perl-module-toolkit toolkit;
+
+
+ case "${toolkit//[[:space:]]/}" in
+ mbtiny)
+ ./Build install \
+ || die "./Build install failed"
+ ;;
+ mb)
+ ./Build ${mytargets} \
|| die "./Build ${mytargets} failed"
- elif [[ -f Makefile ]] ; then
- emake "${myinst_local[@]}" ${mytargets} \
- || die "emake ${myinst_local[@]} ${mytargets} failed"
- fi
+ ;;
+ eumm)
+ emake "${myinst_local[@]}" ${mytargets} \
+ || die "emake ${myinst_local[@]} ${mytargets} failed"
+ ;;
+ esac;
perl_delete_module_manpages
perl_delete_localpod
- perl_delete_packlist
perl_remove_temppath
for f in Change* CHANGES README* TODO FAQ ${mydoc}; do
@@ -349,16 +638,6 @@
}
-perl_delete_packlist() {
- debug-print-function $FUNCNAME "$@"
- perl_set_version
- if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
- find "${D}/${VENDOR_ARCH}" -type f -a \( -name .packlist \
- -o \( -name '*.bs' -a -empty \) \) -delete
- find "${D}" -depth -mindepth 1 -type d -empty -delete
- fi
-}
-
perl_remove_temppath() {
debug-print-function $FUNCNAME "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment