From 22685bcfa8aa4b13bfd95a117320fc0bedfa6715 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 31 Mar 2018 17:47:14 +0200 Subject: build: Add CPAN distribution machinery Add a new dist-cpan target that takes care of preparing a perl distribution to be uploaded to CPAN. Only the modules are shipped, some of which do require dpkg tools being installed though. Closes: #821177 --- Makefile.am | 4 ++- configure.ac | 9 ++++++- cpan.am | 48 ++++++++++++++++++++++++++++++++++ debian/changelog | 1 + scripts/.gitignore | 1 + scripts/Build.PL.in | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/Test/Dpkg.pm | 20 +++++++++++--- 7 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 cpan.am create mode 100644 scripts/Build.PL.in diff --git a/Makefile.am b/Makefile.am index 31e82a7a8..4cd8376f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -179,9 +179,11 @@ update-po: $(MAKE) -C dselect/po update-po $(MAKE) -C man update-po +include $(top_srcdir)/cpan.am + # If we create the dist tarball from the git repository, make sure # that we're not forgetting some files... -dist-hook: +dist-hook: dist-cpan echo $(VERSION) >$(distdir)/.dist-version if [ -e .git ]; then \ for file in `git ls-files | grep -v .gitignore`; do \ diff --git a/configure.ac b/configure.ac index 2e09c63e1..822f6f654 100644 --- a/configure.ac +++ b/configure.ac @@ -3,8 +3,14 @@ m4_pattern_forbid([^_?DPKG_]) AC_PREREQ(2.60) -AC_INIT([dpkg], m4_esyscmd([./get-version]), [debian-dpkg@lists.debian.org]) +AC_INIT([dpkg], m4_esyscmd([./get-version]), [debian-dpkg@lists.debian.org], + [dpkg], [https://wiki.debian.org/Teams/Dpkg]) AC_SUBST([PACKAGE_COPYRIGHT_HOLDER], ['Dpkg Developers']) +AC_SUBST([PACKAGE_VCS_TYPE], [git]) +AC_SUBST([PACKAGE_VCS_URL], [https://anonscm.debian.org/git/dpkg/dpkg.git]) +AC_SUBST([PACKAGE_VCS_WEB], [https://anonscm.debian.org/cgit/dpkg/dpkg.git]) +AC_SUBST([PACKAGE_BUG_WEB], [https://bugs.debian.org/src:dpkg]) +AC_SUBST([PACKAGE_CPAN_NAME], [Dpkg]) AC_CONFIG_SRCDIR([lib/dpkg/dpkg.h]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([build-aux]) @@ -208,6 +214,7 @@ AC_CONFIG_FILES([ doc/Doxyfile man/Makefile po/Makefile.in + scripts/Build.PL scripts/Makefile scripts/mk/Makefile scripts/po/Makefile.in diff --git a/cpan.am b/cpan.am new file mode 100644 index 000000000..0cf4967ad --- /dev/null +++ b/cpan.am @@ -0,0 +1,48 @@ +CPAN_DIST_NAME = $(PACKAGE_CPAN_NAME) +CPAN_DIST_VERSION = $(PACKAGE_VERSION) +CPAN_DIST = $(CPAN_DIST_NAME)-$(CPAN_DIST_VERSION) +CPAN_DIST_ARCHIVE = $(CPAN_DIST).tar.gz + +dist-cpan: + : # Create the CPAN source tree. + mkdir -p $(CPAN_DIST) + mkdir -p $(CPAN_DIST)/lib + mkdir -p $(CPAN_DIST)/t + cp -fpR $(top_srcdir)/data $(CPAN_DIST) + cp -fpR $(top_srcdir)/t/* \ + $(top_srcdir)/scripts/t/Dpkg* \ + $(top_srcdir)/scripts/t/origins \ + $(CPAN_DIST)/t + $(do_perl_subst) <$(top_srcdir)/scripts/Dpkg.pm \ + >$(CPAN_DIST)/lib/Dpkg.pm + cp -fpR $(top_srcdir)/scripts/Dpkg.pm \ + $(top_srcdir)/scripts/Dpkg \ + $(CPAN_DIST)/lib/ + cp -fpR $(top_srcdir)/scripts/Test $(CPAN_DIST)/lib/ + cp -fpR $(top_srcdir)/scripts/Build.PL $(CPAN_DIST) + + : # Fix permissions of the distributed files. + chmod a+x $(CPAN_DIST)/Build.PL + find $(CPAN_DIST) \ + -type d ! -perm 755 -exec chmod u+rwx,go+rx {} ';' -o \ + ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; || \ + chmod -R a+r $(CPAN_DIST) + + : # Prepare the CPAN distribution. + cd $(CPAN_DIST) && ./Build.PL + cd $(CPAN_DIST) && ./Build manifest + cd $(CPAN_DIST) && ./Build distsign + + : # Pack the CPAN distribution. + $(TAR) -caf $(CPAN_DIST_ARCHIVE) -C $(CPAN_DIST) -Hustar \ + --sort=name --owner=root:0 --group=root:0 $(CPAN_DIST) + + : # Cleanup the CPAN source tree. + find $(CPAN_DIST) -type d ! -perm -200 -exec chmod u+w {} ';' + rm -rf $(CPAN_DIST) + +# Ignore the CPAN archive for distcleancheck. +distcleancheck_listfiles = \ + find -type f \( -name $(CPAN_DIST_ARCHIVE) -o -print \) diff --git a/debian/changelog b/debian/changelog index 59d2cffd6..372dcdcde 100644 --- a/debian/changelog +++ b/debian/changelog @@ -90,6 +90,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium instead of passing the positive form manually. - Enable clang -Wdocumentation warning if available. - Enable gcc-7 -Wregister warning if available. + - Add CPAN distribution machinery for the perl modules. Closes: #821177 * Packaging: - Install update-alternatives policykit-1 file. - Add Breaks to libdpkg-perl against pkg-kde-tools (<< 0.15.28~), as diff --git a/scripts/.gitignore b/scripts/.gitignore index 0d1f29ac9..a93412826 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1,3 +1,4 @@ +Build.PL dpkg-architecture dpkg-buildflags dpkg-buildpackage diff --git a/scripts/Build.PL.in b/scripts/Build.PL.in new file mode 100644 index 000000000..40de90e41 --- /dev/null +++ b/scripts/Build.PL.in @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Module::Build (); + +if (-e 'Build.PL.in') { + die "error: This is an in-tree build, not a proper perl distribution.\n" . + "To create one please configure normally and then run 'make dist'.\n"; +} + +my $class = Module::Build->subclass( + class => 'Module::Build::Dpkg', + code => q{ + BEGIN { + $ENV{DPKG_TEST_MODE} = 'cpan'; + $ENV{DPKG_DATADIR} = 'data'; + $ENV{DPKG_ORIGINS_DIR} = 't/origins'; + } + }, +); + +my $build = $class->new( + dist_name => '@PACKAGE_CPAN_NAME@', + dist_abstract => 'Debian Package Manager Perl modules', + dist_version => '@PACKAGE_VERSION@', + dist_author => '@PACKAGE_COPYRIGHT_HOLDER@ <@PACKAGE_BUGREPORT@>', + license => 'GPL_2', + + # Set only to avoid warnings. + module_name => '@PACKAGE_CPAN_NAME@', + + meta_merge => { + resources => { + homepage => '@PACKAGE_URL@', + repository => { + type => '@PACKAGE_VCS_TYPE@', + url => '@PACKAGE_VCS_URL@', + web => '@PACKAGE_VCS_WEB@', + }, + bugtracker => { + web => '@PACKAGE_BUG_WEB@', + }, + }, + keywords => [ qw(dpkg debian perl) ], + }, + + sign => 1, + dynamic_config => 0, + + configure_requires => { + 'Module::Build' => '0.4004', + }, + test_requires => { + 'TAP::Harness' => 0, + 'Test::More' => 0, + 'Test::Pod' => 0, + 'Test::Strict' => 0, + }, + recommands => { + 'Algorithm::Merge' => 0, + 'File::FcntlLock' => 0, + 'Locale::gettext' => 0, + + }, + requires => { + 'perl' => '@PERL_MIN_VERSION@', + }, +); + +$build->create_build_script(); + +1; diff --git a/scripts/Test/Dpkg.pm b/scripts/Test/Dpkg.pm index 5eea6184a..4900e1f91 100644 --- a/scripts/Test/Dpkg.pm +++ b/scripts/Test/Dpkg.pm @@ -54,6 +54,12 @@ use File::Path qw(make_path); use IPC::Cmd qw(can_run); use Test::More; +my $test_mode; + +BEGIN { + $test_mode = $ENV{DPKG_TEST_MODE} // 'dpkg'; +} + sub _test_get_caller_dir { my (undef, $path, undef) = caller 1; @@ -69,8 +75,12 @@ sub test_get_data_path my $path = shift; if (defined $path) { - my $srcdir = $ENV{srcdir} || '.'; - return "$srcdir/$path"; + if ($test_mode eq 'cpan') { + return $path; + } else { + my $srcdir = $ENV{srcdir} || '.'; + return "$srcdir/$path"; + } } else { return _test_get_caller_dir(); } @@ -87,7 +97,11 @@ sub test_get_temp_path sub test_get_perl_dirs { - return qw(t src/t lib utils/t scripts dselect); + if ($test_mode eq 'cpan') { + return qw(t lib); + } else { + return qw(t src/t lib utils/t scripts dselect); + } } sub all_perl_files -- cgit v1.2.3