d35ea2
# Sensible Perl-specific RPM build macros.
d35ea2
#
d35ea2
# Note that these depend on the generic filtering system being in place in
d35ea2
# rpm core; but won't cause a build to fail if they're not present.
d35ea2
#
d35ea2
# Chris Weyl <cweyl@alumni.drew.edu> 2009
d35ea2
# Marcela Mašláňová <mmaslano@redhat.com> 2011
d35ea2
d35ea2
# This macro unsets several common vars used to control how Makefile.PL (et
d35ea2
# al) build and install packages.  We also set a couple to help some of the
d35ea2
# common systems be less interactive.  This was blatantly stolen from
d35ea2
# cpanminus, and helps building rpms locally when one makes extensive use of
d35ea2
# local::lib, etc.
d35ea2
#
d35ea2
# Usage, in %build, before "%{__perl} Makefile.PL ..."
d35ea2
#
d35ea2
#   %{?perl_ext_env_unset}
d35ea2
d35ea2
%perl_ext_env_unset %{expand:
d35ea2
unset PERL_MM_OPT MODULEBUILDRC PERL5INC
d35ea2
export PERL_AUTOINSTALL="--defaultdeps"
d35ea2
export PERL_MM_USE_DEFAULT=1
d35ea2
}
d35ea2
d35ea2
#############################################################################
d35ea2
# Perl specific macros, no longer part of rpm >= 4.15
d35ea2
%perl_vendorarch %(eval "`%{__perl} -V:installvendorarch`"; echo $installvendorarch)
d35ea2
%perl_vendorlib  %(eval "`%{__perl} -V:installvendorlib`"; echo $installvendorlib)
d35ea2
%perl_archlib    %(eval "`%{__perl} -V:installarchlib`"; echo $installarchlib)
d35ea2
%perl_privlib    %(eval "`%{__perl} -V:installprivlib`"; echo $installprivlib)
d35ea2
d35ea2
#############################################################################
d35ea2
# Filtering macro incantations
d35ea2
d35ea2
# keep track of what "revision" of the filtering we're at.  Each time we
d35ea2
# change the filter we should increment this.
d35ea2
d35ea2
%perl_default_filter_revision 3
d35ea2
d35ea2
# By default, for perl packages we want to filter all files in _docdir from 
d35ea2
# req/prov scanning.
d35ea2
# Filtering out any provides caused by private libs in vendorarch/archlib
d35ea2
# (vendor/core) is done by rpmbuild since Fedora 20
d35ea2
# <https://fedorahosted.org/fpc/ticket/353>.
d35ea2
#
d35ea2
# Note that this must be invoked in the spec file, preferably as 
d35ea2
# "%{?perl_default_filter}", before any %description block.
d35ea2
d35ea2
%perl_default_filter %{expand: \
d35ea2
%global __provides_exclude_from %{?__provides_exclude_from:%__provides_exclude_from|}^%{_docdir}
d35ea2
%global __requires_exclude_from %{?__requires_exclude_from:%__requires_exclude_from|}^%{_docdir}
d35ea2
%global __provides_exclude %{?__provides_exclude:%__provides_exclude|}^perl\\\\(VMS|^perl\\\\(Win32|^perl\\\\(DB\\\\)|^perl\\\\(UNIVERSAL\\\\)
d35ea2
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^perl\\\\(VMS|^perl\\\\(Win32
d35ea2
}
d35ea2
d35ea2
#############################################################################
d35ea2
# Macros to assist with generating a "-tests" subpackage in a semi-automatic
d35ea2
# manner.
d35ea2
#
d35ea2
# The following macros are still in a highly experimental stage and users
d35ea2
# should be aware that the interface and behaviour may change. 
d35ea2
#
d35ea2
# PLEASE, PLEASE CONDITIONALIZE THESE MACROS IF YOU USE THEM.
d35ea2
#
d35ea2
# See http://gist.github.com/284409
d35ea2
d35ea2
# These macros should be invoked as above, right before the first %description
d35ea2
# section, and conditionalized.  e.g., for the common case where all our tests
d35ea2
# are located under t/, the correct usage is:
d35ea2
#
d35ea2
#   %{?perl_default_subpackage_tests}
d35ea2
#
d35ea2
# If custom files/directories need to be specified, this can be done as such:
d35ea2
#
d35ea2
#   %{?perl_subpackage_tests:%perl_subpackage_tests t/ one/ three.sql}
d35ea2
#
d35ea2
# etc, etc.
d35ea2
d35ea2
%perl_version   %(eval "`%{__perl} -V:version`"; echo $version)
d35ea2
%perl_testdir   %{_libexecdir}/perl5-tests
d35ea2
%cpan_dist_name %(eval echo %{name} | %{__sed} -e 's/^perl-//')
d35ea2
d35ea2
# easily mark something as required by -tests and BR to the main package
d35ea2
%tests_req() %{expand:\
d35ea2
BuildRequires: %*\
d35ea2
%%tests_subpackage_requires %*\
d35ea2
}
d35ea2
d35ea2
# fixup (and create if needed) the shbang lines in tests, so they work and
d35ea2
# rpmlint doesn't (correctly) have a fit
d35ea2
%fix_shbang_line() \
d35ea2
TMPHEAD=`mktemp`\
d35ea2
TMPBODY=`mktemp`\
d35ea2
for file in %* ; do \
d35ea2
    head -1 $file > $TMPHEAD\
d35ea2
    tail -n +2 $file > $TMPBODY\
d35ea2
    %{__perl} -pi -e '$f = /^#!/ ? "" : "#!%{__perl}$/"; $_="$f$_"' $TMPHEAD\
d35ea2
    cat $TMPHEAD $TMPBODY > $file\
d35ea2
done\
d35ea2
%{__perl} -MExtUtils::MakeMaker -e "ExtUtils::MM_Unix->fixin(qw{%*})"\
d35ea2
%{__rm} $TMPHEAD $TMPBODY\
d35ea2
%{nil}
d35ea2
d35ea2
# additional -tests subpackage requires, if any
d35ea2
%tests_subpackage_requires() %{expand: \
d35ea2
%global __tests_spkg_req %{?__tests_spkg_req} %* \
d35ea2
}
d35ea2
d35ea2
# additional -tests subpackage provides, if any
d35ea2
%tests_subpackage_provides() %{expand: \
d35ea2
%global __tests_spkg_prov %{?__tests_spkg_prov} %* \
d35ea2
}
d35ea2
d35ea2
#
d35ea2
# Runs after the body of %check completes.
d35ea2
#
d35ea2
d35ea2
%__perl_check_pre %{expand: \
d35ea2
%{?__spec_check_pre} \
d35ea2
pushd %{buildsubdir} \
d35ea2
%define perl_br_testdir %{buildroot}%{perl_testdir}/%{cpan_dist_name} \
d35ea2
%{__mkdir_p} %{perl_br_testdir} \
d35ea2
%{__tar} -cf - %{__perl_test_dirs} | ( cd %{perl_br_testdir} && %{__tar} -xf - ) \
d35ea2
find . -maxdepth 1 -type f -name '*META*' -exec %{__cp} -vp {} %{perl_br_testdir} ';' \
d35ea2
find %{perl_br_testdir} -type f -exec %{__chmod} -c -x {} ';' \
d35ea2
T_FILES=`find %{perl_br_testdir} -type f -name '*.t'` \
d35ea2
%fix_shbang_line $T_FILES \
d35ea2
%{__chmod} +x $T_FILES \
d35ea2
%{_fixperms} %{perl_br_testdir} \
d35ea2
popd \
d35ea2
}
d35ea2
d35ea2
#
d35ea2
# The actual invoked macro
d35ea2
#
d35ea2
d35ea2
%perl_subpackage_tests() %{expand: \
d35ea2
%global __perl_package 1\
d35ea2
%global __perl_test_dirs %* \
d35ea2
%global __spec_check_pre %{expand:%{__perl_check_pre}} \
d35ea2
%package tests\
d35ea2
Summary: Test suite for package %{name}\
d35ea2
Group: Development/Debug\
d35ea2
Requires: %{name} = %{?epoch:%{epoch}:}%{version}-%{release}\
d35ea2
Requires: /usr/bin/prove \
d35ea2
%{?__tests_spkg_req:Requires: %__tests_spkg_req}\
d35ea2
%{?__tests_spkg_prov:Provides: %__tests_spkg_prov}\
d35ea2
AutoReqProv: 0 \
d35ea2
%description tests\
d35ea2
This package provides the test suite for package %{name}.\
d35ea2
%files tests\
d35ea2
%defattr(-,root,root,-)\
d35ea2
%{perl_testdir}\
d35ea2
}
d35ea2
d35ea2
# shortcut sugar
d35ea2
%perl_default_subpackage_tests %perl_subpackage_tests t/
d35ea2