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