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