[perl PATCH] Switch over to using Module::Build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The Module::Build system is nicer than ExtUtils::MakeMaker as it allows
for better cross-platform portability by only relying on Perl, rather
than both Perl and system 'make' binary.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 .gitignore                 |  17 +++----
 Build.PL                   | 102 +++++++++++++++++++++++++++++++++++++
 MANIFEST                   |  73 ++++++++++++++++++++++++++
 MANIFEST.SKIP              |  20 --------
 META.yml.PL                |  55 --------------------
 Makefile.PL                |  85 -------------------------------
 autobuild.sh               |  55 +++-----------------
 Virt.xs => lib/Sys/Virt.xs |   0
 perl-Sys-Virt.spec.PL      |  45 ++++++++--------
 t/030-api-coverage.t       |   2 +-
 10 files changed, 210 insertions(+), 244 deletions(-)
 create mode 100755 Build.PL
 create mode 100644 MANIFEST
 delete mode 100644 MANIFEST.SKIP
 delete mode 100644 META.yml.PL
 delete mode 100644 Makefile.PL
 rename Virt.xs => lib/Sys/Virt.xs (100%)

diff --git a/.gitignore b/.gitignore
index dc0ba62..3f08c79 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,12 @@
-*.swp
 *~
-MANIFEST
 META.yml
+META.json
 MYMETA.*
-Makefile
-Makefile.old
+Makefile.PL
 Sys-Virt-*.tar.gz
-Virt.bs
-Virt.c
-Virt.o
 blib/
-cover_db
 perl-Sys-Virt.spec
-pm_to_blib
-results.log
-tags
+lib/Sys/Virt\.c
+lib/Sys/Virt\.o
+_build/
+Build
diff --git a/Build.PL b/Build.PL
new file mode 100755
index 0000000..13a0e4f
--- /dev/null
+++ b/Build.PL
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+#
+# Copyright (C) 2009-2018 Red Hat, Inc.
+# Copyright (C) 2009 Daniel P. Berrange
+#
+# This program is free software; You can redistribute it and/or modify
+# it under the GNU General Public License as published by the Free
+# Software Foundation; either version 2, or (at your option) any
+# later version
+#
+# The file "LICENSE" distributed along with this file provides full
+# details of the terms and conditions
+#
+
+use Module::Build;
+
+use strict;
+use warnings;
+
+my $libvirtver = "4.4.0";
+my $stat = system "pkg-config --atleast-version=$libvirtver libvirt";
+die "cannot run pkg-config to check libvirt version" if $stat == -1;
+die "libvirt >= $libvirtver is required\n" unless $stat == 0;
+
+my $LIBVIRT_LIBS = `pkg-config --libs libvirt`;
+my $LIBVIRT_CFLAGS = `pkg-config --cflags libvirt`;
+
+my $GCC_CFLAGS = "";
+if ($ENV{TEST_MAINTAINER}) {
+    $GCC_CFLAGS = qq(
+ -W -Waddress -Wall -Warray-bounds -Wattributes
+ -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align
+ -Wchar-subscripts -Wclobbered -Wcomment -Wcomments
+ -Wcoverage-mismatch -Wcpp -Wdeprecated-declarations
+ -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion
+ -Wempty-body -Wendif-labels -Wextra -Wformat-contains-nul
+ -Wformat-extra-args -Wformat-security -Wformat-y2k
+ -Wformat-zero-length -Wformat=2 -Wfree-nonheap-object
+ -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration
+ -Wimplicit-int -Winit-self -Wint-to-pointer-cast
+ -Winvalid-memory-model -Winvalid-pch -Wjump-misses-init
+ -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmissing-braces
+ -Wmissing-declarations -Wmissing-field-initializers
+ -Wmissing-format-attribute -Wmissing-include-dirs
+ -Wmissing-noreturn -Wmissing-parameter-type
+ -Wmultichar -Wnarrowing -Wnonnull
+ -Wnormalized=nfc -Wold-style-declaration -Wold-style-definition
+ -Woverflow -Woverride-init -Wpacked-bitfield-compat -Wparentheses
+ -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas
+ -Wreturn-type -Wsequence-point -Wno-shadow -Wstrict-aliasing
+ -Wstrict-prototypes -Wsuggest-attribute=const
+ -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch
+ -Wsync-nand -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized
+ -Wunknown-pragmas -Wunused -Wunused-but-set-parameter
+ -Wunused-but-set-variable -Wunused-function -Wunused-label
+ -Wunused-local-typedefs -Wno-unused-parameter -Wunused-result
+ -Wunused-value -Wunused-variable -Wvariadic-macros
+ -Wvector-operation-performance -Wvolatile-register-var
+ -Wwrite-strings -Wno-sign-compare -Wjump-misses-init
+ -Wno-format-nonliteral -Wframe-larger-than=8192
+ -Wno-suggest-attribute=pure -Wno-suggest-attribute=const
+ -Wno-cast-function-type
+	);
+}
+
+my $b = Module::Build->new(
+    module_name => "Sys::Virt",
+    license => 'gpl',
+    configure_requires => {
+	'Module::Build' => 0,
+    },
+    create_makefile_pl => 'small',
+    dist_author => 'Daniel Berrange <dan@xxxxxxxxxxxx>',
+    dist_abstract => 'libvirt Perl API',
+    requires => {
+        'perl' => '5.8.0',
+    },
+    extra_compiler_flags => $GCC_CFLAGS . $LIBVIRT_CFLAGS,
+    extra_linker_flags => $LIBVIRT_LIBS,
+    build_requires => {
+	'ExtUtils::CBuilder' => 0,
+	'Sys::Hostname' => 0,
+	'Test::CPAN::Changes' => 0,
+	'Test::More' => 0,
+        'Test::Pod' => '0',
+	'Test::Pod::Coverage' => '0',
+	'Time::HiRes' => 0,
+	'XML::XPath' => 0,
+	'XML::XPath::XMLParser' => 0,
+    },
+    script_files => [],
+    meta_add => {
+        resources => {
+            license => "http://www.gnu.org/licenses/gpl.html";,
+            homepage =>  "http://libvirt.org/";,
+            repository => "https://libvirt.org/git/?p=libvirt-perl.git;a=summary";,
+            MailingList => "http://www.redhat.com/mailman/listinfo/libvir-list";,
+        },
+    },
+    PL_files => { 'perl-Sys-Virt.spec.PL' => 'perl-Sys-Virt.spec' },
+    );
+$b->create_build_script;
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..d425ef1
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,73 @@
+.gitignore
+.gitpublish
+AUTHORS
+Build.PL
+Changes
+HACKING
+INSTALL
+LICENSE
+README
+autobuild.sh
+examples/auth.pl
+examples/devices.pl
+examples/dhcp-leases.pl
+examples/dom-fsinfo.pl
+examples/dom-ifinfo.pl
+examples/dom-migrate.pl
+examples/dom-stats.pl
+examples/dump-info.pl
+examples/dump-xml.pl
+examples/emulator-pin.pl
+examples/events.pl
+examples/fs-freeze.pl
+examples/hv-stat.pl
+examples/iothreadinfo.pl
+examples/node-alloc.pl
+examples/node-cpu.pl
+examples/node-devlist.pl
+examples/node-info.pl
+examples/node-ksm.pl
+examples/open-console.pl
+examples/save-restore.pl
+examples/send-key.pl
+examples/vcpuinfo.pl
+examples/vol-download-all.pl
+examples/vol-download-nonblock.pl
+examples/vol-download.pl
+examples/vol-sparse.pl
+examples/vol-upload-all.pl
+examples/vol-upload-nonblock.pl
+examples/vol-upload.pl
+lib/Sys/Virt.pm
+lib/Sys/Virt.xs
+lib/Sys/Virt/Domain.pm
+lib/Sys/Virt/DomainSnapshot.pm
+lib/Sys/Virt/Error.pm
+lib/Sys/Virt/Event.pm
+lib/Sys/Virt/Interface.pm
+lib/Sys/Virt/NWFilter.pm
+lib/Sys/Virt/Network.pm
+lib/Sys/Virt/NodeDevice.pm
+lib/Sys/Virt/Secret.pm
+lib/Sys/Virt/StoragePool.pm
+lib/Sys/Virt/StorageVol.pm
+lib/Sys/Virt/Stream.pm
+perl-Sys-Virt.spec
+perl-Sys-Virt.spec.PL
+Makefile.PL
+t/005-pod.t
+t/010-pod-coverage.t
+t/015-changes.t
+t/020-constants.t
+t/030-api-coverage.t
+t/100-connect.t
+t/200-domains.t
+t/300-networks.t
+t/400-storage-pools.t
+t/500-storage-vols.t
+t/600-interfaces.t
+t/800-events.t
+typemap
+Makefile.PL
+META.yml
+META.json
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
deleted file mode 100644
index ebce958..0000000
--- a/MANIFEST.SKIP
+++ /dev/null
@@ -1,20 +0,0 @@
-pm_to_blib
-Virt\.o
-Virt\.c
-Virt\.bs
-Virt\.xsc
-.*.old
-Sys-Virt-
-blib
-.*\.bak
-CVS
-.cvsignore
-.*~
-.#.*
-#.*
-^Makefile$
-^cover_db/
-.hg
-.*\.orig
-.*\.sh
-\.git
diff --git a/META.yml.PL b/META.yml.PL
deleted file mode 100644
index 0467309..0000000
--- a/META.yml.PL
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (C) 2008 Daniel Berrange <dan@xxxxxxxxxxxx>
-
-use strict;
-use warnings;
-
-die unless (scalar @ARGV == 1);
-
-open SRC, "lib/Sys/Virt.pm"
-    or die "lib/Sys/Virt.pm: $!";
-
-our $VERSION;
-while (<SRC>) {
-    if (/\$VERSION\s*=\s*'(.*)'/) {
-	$VERSION=$1;
-    }
-}
-close SRC;
-
-local $/ = undef;
-$_ = <DATA>;
-s/\@VERSION\@/$VERSION/g;
-
-open SPEC, ">$ARGV[0]" or die "$!";
-print SPEC $_;
-close SPEC;
-__DATA__
---- #YAML:1.0
-name:         Sys-Virt
-abstract:     Extension for the libvirt library
-version:      @VERSION@
-author:
-  - Daniel P. Berrange <dan@xxxxxxxxxxxx>
-license: perl
-generated_by: ExtUtils::MakeMaker version 6.30
-build_requires:
-   Test::More:                    0
-   Test::Pod:                     0
-   Test::Pod::Coverage:           0
-   Test::CPAN::Changes:           0
-   XML::XPath:                    0
-   XML::XPath::XMLParser:         0
-   Sys::Hostname:                 0
-   Time::HiRes:                   0
-
-resources:
-  license: http://dev.perl.org/licenses/
-  homepage: http://libvirt.org/
-  repository: http://libvirt.org/git/?p=libvirt-perl.git;a=summary
-  MailingList: http://www.redhat.com/mailman/listinfo/libvir-list
-
-distribution_type: module
-
-meta-spec:
-   version: 1.3
-   url: http://module-build.sourceforge.net/META-spec-v1.3.html
diff --git a/Makefile.PL b/Makefile.PL
deleted file mode 100644
index f72e210..0000000
--- a/Makefile.PL
+++ /dev/null
@@ -1,85 +0,0 @@
-use 5.006;
-use ExtUtils::MakeMaker;
-# See lib/ExtUtils/MakeMaker.pm for details of how to influence
-# the contents of the Makefile that is written.
-
-my $libvirtver = "4.4.0";
-my $stat = system "pkg-config --atleast-version=$libvirtver libvirt";
-die "cannot run pkg-config to check libvirt version" if $stat == -1;
-die "libvirt >= $libvirtver is required\n" unless $stat == 0;
-
-my $LIBVIRT_LIBS = `pkg-config --libs libvirt`;
-my $LIBVIRT_CFLAGS = `pkg-config --cflags libvirt`;
-
-my $gccflags = "-W -Waddress -Wall -Warray-bounds -Wattributes \\
- -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align \\
- -Wchar-subscripts -Wclobbered -Wcomment -Wcomments \\
- -Wcoverage-mismatch -Wcpp -Wdeprecated-declarations \\
- -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion \\
- -Wempty-body -Wendif-labels -Wextra -Wformat-contains-nul \\
- -Wformat-extra-args -Wformat-security -Wformat-y2k \\
- -Wformat-zero-length -Wformat=2 -Wfree-nonheap-object \\
- -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration \\
- -Wimplicit-int -Winit-self -Wint-to-pointer-cast \\
- -Winvalid-memory-model -Winvalid-pch -Wjump-misses-init \\
- -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmissing-braces \\
- -Wmissing-declarations -Wmissing-field-initializers \\
- -Wmissing-format-attribute -Wmissing-include-dirs \\
- -Wmissing-noreturn -Wmissing-parameter-type \\
- -Wmultichar -Wnarrowing -Wnonnull \\
- -Wnormalized=nfc -Wold-style-declaration -Wold-style-definition \\
- -Woverflow -Woverride-init -Wpacked-bitfield-compat -Wparentheses \\
- -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas \\
- -Wreturn-type -Wsequence-point -Wno-shadow -Wstrict-aliasing \\
- -Wstrict-prototypes -Wsuggest-attribute=const \\
- -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch \\
- -Wsync-nand -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized \\
- -Wunknown-pragmas -Wunused -Wunused-but-set-parameter \\
- -Wunused-but-set-variable -Wunused-function -Wunused-label \\
- -Wunused-local-typedefs -Wno-unused-parameter -Wunused-result \\
- -Wunused-value -Wunused-variable -Wvariadic-macros \\
- -Wvector-operation-performance -Wvolatile-register-var \\
- -Wwrite-strings -Wno-sign-compare -Wjump-misses-init \\
- -Wno-format-nonliteral -Wframe-larger-than=8192 \\
- -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Werror";
-
-my $cflags;
-if ($ENV{TEST_MAINTAINER}) {
-    $cflags = $gccflags;
-} else {
-    $cflags = "-Wall";
-}
-
-WriteMakefile(
-	      'NAME' => 'Sys::Virt',
-	      'VERSION_FROM' => 'lib/Sys/Virt.pm',
-	      'PREREQ_PM' => {
-		  'Test::More'  => 0,
-		  'Test::Pod'  => 0,
-		  'Test::Pod::Coverage'  => 0,
-		  'Test::CPAN::Changes'  => 0,
-		  'Time::HiRes'  => 0,
-		  'XML::XPath' => 0,
-		  },
-	      'AUTHOR' => 'Daniel Berrange <dan@xxxxxxxxxxxx>',
-	      'LIBS' => [$LIBVIRT_LIBS],
-	      'INC' => "$cflags $LIBVIRT_CFLAGS",
-	      'depend' => {
-		  Sys-Virt.spec => '$(VERSION_FROM)',
-		  Makefile => '$(VERSION_FROM)',
-	      },
-              'NO_META' => 1,
-	      'realclean' => {
-		  FILES => 'Sys-Virt.spec',
-	      },
-);
-
-package MY;
-
-sub libscan
-  {
-    my ($self, $path) = @_;
-    ($path =~ /\~$/ || $path =~ m,/CVS/,) ? undef : $path;
-  }
-
-__END__
diff --git a/autobuild.sh b/autobuild.sh
index 8a6d102..597b9bf 100755
--- a/autobuild.sh
+++ b/autobuild.sh
@@ -7,53 +7,18 @@ NAME=Sys-Virt
 
 set -e
 
-test -n "$1" && RESULTS=$1 || RESULTS=results.log
-: ${AUTOBUILD_INSTALL_ROOT=$HOME/builder}
+rm -rf blib _build Build $NAME-*.tar.gz
 
-make -k realclean ||:
-rm -rf MANIFEST blib pm_to_blib
+test -z "$AUTOBUILD_INSTALL_ROOT" && AUTOBUILD_INSTALL_ROOT=$HOME/builder
 
 export TEST_MAINTAINER=1
 
-perl Makefile.PL  PREFIX=$AUTOBUILD_INSTALL_ROOT
+perl Build.PL install_base=$AUTOBUILD_INSTALL_ROOT
 
-rm -f MANIFEST
-
-# Build the RPM.
-make
-make manifest
-
-if [ -z "$USE_COVER" ]; then
-  perl -MDevel::Cover -e '' 1>/dev/null 2>&1 && USE_COVER=1 || USE_COVER=0
-fi
-
-if [ -z "$SKIP_TESTS" -o "$SKIP_TESTS" = "0" ]; then
-  if [ "$USE_COVER" = "1" ]; then
-    cover -delete
-    export HARNESS_PERL_SWITCHES=-MDevel::Cover
-  fi
-
-  # set -o pipefail is a bashism; this use of exec is the POSIX alternative
-  exec 3>&1
-  st=$(
-      exec 4>&1 >&3
-      { make test 2>&1 3>&- 4>&-; echo $? >&4; } | tee "$RESULTS"
-  )
-  exec 3>&-
-  test "$st" = 0
-
-  if [ "$USE_COVER" = "1" ]; then
-    cover
-    mkdir blib/coverage
-    cp -a cover_db/*.html cover_db/*.css blib/coverage
-    mv blib/coverage/coverage.html blib/coverage/index.html
-  fi
-fi
-
-make install
-
-rm -f $NAME-*.tar.gz
-make dist
+./Build
+./Build test
+./Build install
+./Build dist
 
 if [ -f /usr/bin/rpmbuild ]; then
   if [ -n "$AUTOBUILD_COUNTER" ]; then
@@ -65,10 +30,4 @@ if [ -f /usr/bin/rpmbuild ]; then
   rpmbuild --nodeps -ta --define "extra_release $EXTRA_RELEASE" --clean $NAME-*.tar.gz
 fi
 
-# Skip debian pkg for now
 exit 0
-
-if [ -f /usr/bin/fakeroot ]; then
-  fakeroot debian/rules clean
-  fakeroot debian/rules DESTDIR=$HOME/packages/debian binary
-fi
diff --git a/Virt.xs b/lib/Sys/Virt.xs
similarity index 100%
rename from Virt.xs
rename to lib/Sys/Virt.xs
diff --git a/perl-Sys-Virt.spec.PL b/perl-Sys-Virt.spec.PL
index dbb749d..e5140b6 100644
--- a/perl-Sys-Virt.spec.PL
+++ b/perl-Sys-Virt.spec.PL
@@ -6,15 +6,19 @@ use strict;
 
 die unless (scalar @ARGV == 1);
 
-unless (do './lib/Sys/Virt.pm')
-  {
-    if ($@) { die $@ };
-    die "lib/Sys/Virt.pm: $!";
-  }
+open PM, './lib/Sys/Virt.pm' or die "lib/Sys/Virt.pm: $!";
+my $ver;
+while (<PM>) {
+    if (/our \$VERSION = '(.*)'/) {
+        $ver = $1;
+	last;
+    }
+}
+die "cannot find version" unless $ver;
 
 local $/ = undef;
 $_ = <DATA>;
-s/\@VERSION\@/$Sys::Virt::VERSION/g;
+s/\@VERSION\@/$ver/g;
 
 open SPEC, ">$ARGV[0]" or die "$!";
 print SPEC $_;
@@ -29,9 +33,10 @@ Summary:        Represent and manage a libvirt hypervisor connection
 License:        GPLv2+ or Artistic
 Group:          Development/Libraries
 URL:            http://search.cpan.org/dist/Sys-Virt/
-Source0:        http://www.cpan.org/authors/id/D/DA/DANBERR/Sys-Virt-%{version}.tar.gz
+Source0:        http://www.cpan.org/authors/id/D/DA/DANBERR/Sys-Virt-v%{version}.tar.gz
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-BuildRequires:  perl(ExtUtils::MakeMaker)
+BuildRequires:  perl(ExtUtils::CBuilder)
+BuildRequires:  perl(Module::Build)
 BuildRequires:  perl(Test::Pod)
 BuildRequires:  perl(Test::Pod::Coverage)
 BuildRequires:  perl(Test::CPAN::Changes)
@@ -46,32 +51,24 @@ machine management APIs. This allows machines running within arbitrary
 virtualization containers to be managed with a consistent API.
 
 %prep
-%setup -q -n Sys-Virt-%{version}
+%setup -q -n Sys-Virt-v%{version}
 
-sed -i -e '/Sys-Virt\.spec/d' Makefile.PL
-sed -i -e '/\.spec\.PL$/d' MANIFEST
-rm -f *.spec.PL
 
 %build
-%{__perl} Makefile.PL INSTALLDIRS=vendor OPTIMIZE="$RPM_OPT_FLAGS"
-make %{?_smp_mflags}
+%{__perl} Build.PL installdirs=vendor
+./Build
 
 %install
-rm -rf $RPM_BUILD_ROOT
+./Build install destdir=$RPM_BUILD_ROOT create_packlist=0
 
-make pure_install PERL_INSTALL_ROOT=$RPM_BUILD_ROOT
-
-find $RPM_BUILD_ROOT -type f \( -name .packlist -o -name '*.bs' -empty \) |
-	xargs rm -f
-find $RPM_BUILD_ROOT -depth -type d -empty -exec rmdir {} \;
+#find $RPM_BUILD_ROOT -type f \( -name .packlist -o -name '*.bs' -empty \) |
+#	xargs rm -f
+#find $RPM_BUILD_ROOT -depth -type d -empty -exec rmdir {} \;
 
 %{_fixperms} $RPM_BUILD_ROOT/*
 
 %check
-make test
-
-%clean
-rm -rf $RPM_BUILD_ROOT
+./Build test
 
 %files
 %defattr(-,root,root,-)
diff --git a/t/030-api-coverage.t b/t/030-api-coverage.t
index 95bbd11..39d6146 100644
--- a/t/030-api-coverage.t
+++ b/t/030-api-coverage.t
@@ -48,7 +48,7 @@ foreach my $n ($set->get_nodelist) {
     push @macros, $n->getData();
 }
 
-open XS, "<Virt.xs" or die "cannot read Virt.xs: $!";
+open XS, "<lib/Sys/Virt.xs" or die "cannot read lib/Sys/Virt.xs: $!";
 
 my $xs;
 {
-- 
2.17.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux