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