|
| 1 | +# Dist::Zilla::Plugin::MakeMaker::Awesome 0.49. |
| 2 | +# Don't edit it but the dist.ini and plugins used to construct it. |
| 3 | + |
1 | 4 | use strict; |
2 | 5 | use warnings; |
3 | 6 |
|
4 | | -use 5.010; |
5 | | - |
6 | 7 | use ExtUtils::MakeMaker; |
7 | 8 |
|
| 9 | +use FindBin '$Bin'; |
| 10 | +use lib $Bin; |
| 11 | + |
| 12 | +$|++; |
| 13 | +my %requires; |
| 14 | +my %args; |
| 15 | +$args{LICENSE} = 'unrestricted'; |
| 16 | +# clean generated test files |
| 17 | +$args{clean} = {FILES => "t/test-dat*"}; |
| 18 | + |
| 19 | +# On Win32 (excluding cygwin) we know that IO::Socket::INET, |
| 20 | +# which is needed for keyserver stuff, doesn't work. In fact |
| 21 | +# it potentially hangs forever. So bail out with a N/A on |
| 22 | +# Win32. |
| 23 | +if ( $^O eq 'MSWin32' and 0 ) { |
| 24 | + print "Keyserver behaviour is dangerous unreliable on Win32\n"; |
| 25 | + print "Not installing on this platform.\n"; |
| 26 | + exit(255); |
| 27 | +} else { |
| 28 | + $requires{'IO::Socket::INET'} = 0; |
| 29 | +} |
| 30 | + |
| 31 | +# We will need something to handle SHA1/256 |
| 32 | +unless ( |
| 33 | + can_use('Digest::SHA') or |
| 34 | + can_use('Digest::SHA::PurePerl') or |
| 35 | + (can_use('Digest::SHA1') and can_use('Digest::SHA256')) |
| 36 | +) { |
| 37 | + # Nothing installed, we need to install a digest module |
| 38 | + if ( can_cc() ) { |
| 39 | + $requires{'Digest::SHA'} = 0; |
| 40 | + } else { |
| 41 | + $requires{'Digest::SHA::PurePerl'} = 0; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +# Is openpgp currently installed |
| 46 | +if ( can_use ('Crypt::OpenPGP') ) { |
| 47 | + # Crypt::OpenPGP installed/available, continue on... |
| 48 | +} elsif ( my $gpg = locate_gpg() ) { |
| 49 | + # We SHOULD have gpg, double-check formally |
| 50 | + requires_external_bin ($gpg); |
| 51 | +} elsif ( can_cc() and $ENV{AUTOMATED_TESTING} ) { |
| 52 | + # Dive headlong into a full Crypt::OpenPGP install. |
| 53 | + $requires{'Crypt::OpenPGP'} = 0; |
| 54 | +} else { |
| 55 | + # Ask the user what to do |
| 56 | + ask_user(); |
| 57 | +} |
| 58 | + |
| 59 | +unless ( can_run('diff') ) { |
| 60 | + # We know Text::Diff fails on Cygwin (for now) |
| 61 | + if ( $^O ne 'Cygwin' ) { |
| 62 | + $requires{'Algorithm::Diff'} = 0; |
| 63 | + $requires{'Text::Diff'} = 0; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | +##################################################################### |
| 68 | +# Support Functions |
| 69 | + |
| 70 | +sub locate_gpg { |
| 71 | + print "Looking for GNU Privacy Guard (gpg), a cryptographic signature tool...\n"; |
| 72 | + |
| 73 | + my ($gpg, $gpg_path); |
| 74 | + for my $gpg_bin ('gpg', 'gpg2', 'gnupg', 'gnupg2') { |
| 75 | + $gpg_path = can_run($gpg_bin); |
| 76 | + next unless $gpg_path; |
| 77 | + next unless `$gpg_bin --version` =~ /GnuPG/; |
| 78 | + next unless defined `$gpg_bin --list-public-keys`; |
| 79 | + |
| 80 | + $gpg = $gpg_bin; |
| 81 | + last; |
| 82 | + } |
| 83 | + unless ( $gpg ) { |
| 84 | + print "gpg not found.\n"; |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + print "GnuPG found ($gpg_path).\n"; |
| 89 | + |
| 90 | + return 1 if grep { /^--installdeps/} @ARGV; |
| 91 | + |
| 92 | + if ( prompt("Import PAUSE and author keys to GnuPG?", 'y' ) =~ /^y/i) { |
| 93 | + print 'Importing... '; |
| 94 | + system $gpg, '--quiet', '--import', qw[ AUDREYT2018.pub ANDK2020.pub PAUSE2022.pub NIKLASHOLM2018.pub TIMLEGGE2024.pub ]; |
| 95 | + print "done.\n"; |
| 96 | + } |
| 97 | + |
| 98 | + return $gpg; |
| 99 | +} |
| 100 | + |
| 101 | +sub ask_user { |
| 102 | + |
| 103 | + # Defined the prompt messages |
| 104 | + my $message1 = <<'END_MESSAGE'; |
| 105 | +
|
| 106 | +Could not auto-detect a signature utility on your system. |
| 107 | +
|
| 108 | +What do you want me to do? |
| 109 | +
|
| 110 | +1) Let you install GnuPG manually while I'm waiting for your answer; |
| 111 | + it is available at http://www.gnupg.org/download/ or may be available |
| 112 | + from your platforms packaging system (for Open Source platforms). |
| 113 | +
|
| 114 | +END_MESSAGE |
| 115 | + |
| 116 | + my $message2 = <<'END_MESSAGE'; |
| 117 | +
|
| 118 | +2) Automatically install Crypt::OpenPGP and the 20 modules it requires |
| 119 | + from CPAN, which will give the same functionality as GnuPG. |
| 120 | +
|
| 121 | +END_MESSAGE |
| 122 | + |
| 123 | + # Present the options |
| 124 | + print $message1; |
| 125 | + |
| 126 | + my $option3 = 2; |
| 127 | + if ( can_cc() ) { |
| 128 | + $option3 = 3; |
| 129 | + print $message2; |
| 130 | + } |
| 131 | + |
| 132 | + print <<"END_MESSAGE"; |
| 133 | +
|
| 134 | +$option3) Forget this cryptographic signature stuff for now. |
| 135 | +
|
| 136 | +END_MESSAGE |
| 137 | + |
| 138 | + my $choice; |
| 139 | + foreach ( 1 .. 3 ) { |
| 140 | + $choice = prompt("Your choice:", 3) || 3; |
| 141 | + last if $choice =~ /^[123]$/; |
| 142 | + print "Sorry, I cannot understand '$choice'.\n" |
| 143 | + } |
| 144 | + |
| 145 | + if ( $choice == 1 ) { |
| 146 | + # They claim to have installed gpg |
| 147 | + requires_external_bin ('gpg'); |
| 148 | + } elsif ( $choice == 2 and $option3 == 3 ) { |
| 149 | + # They want to install Crypt::OpenPGP |
| 150 | + $requires{'Crypt::OpenPGP'} = 0; |
| 151 | + } else { |
| 152 | + # Forget about it... |
| 153 | + print "Module::Signature is not wanted on this host.\n"; |
| 154 | + exit(0); |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | +# check if we can load some module |
| 159 | +### Upgrade this to not have to load the module if possible |
| 160 | +sub can_use { |
| 161 | + my ($mod, $ver) = @_; |
| 162 | + $mod =~ s{::|\\}{/}g; |
| 163 | + $mod .= '.pm' unless $mod =~ /\.pm$/i; |
| 164 | + my $pkg = $mod; |
| 165 | + $pkg =~ s{/}{::}g; |
| 166 | + $pkg =~ s{\.pm$}{}i; |
| 167 | + local $@; |
| 168 | + eval { require $mod; $pkg->VERSION($ver || 0); 1 }; |
| 169 | +} |
| 170 | + |
| 171 | +# Check if we can run some command |
| 172 | +sub can_run { |
| 173 | + my ($cmd) = @_; |
| 174 | + my $_cmd = $cmd; |
| 175 | + return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); |
| 176 | + for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { |
| 177 | + next if $dir eq ''; |
| 178 | + require File::Spec; |
| 179 | + my $abs = File::Spec->catfile($dir, $cmd); |
| 180 | + return $abs if (-x $abs or $abs = MM->maybe_command($abs)); |
| 181 | + } |
| 182 | + return; |
| 183 | +} |
| 184 | +# Can we locate a (the) C compiler |
| 185 | +sub can_cc { |
| 186 | + if ($^O eq 'VMS') { |
| 187 | + require ExtUtils::CBuilder; |
| 188 | + my $builder = ExtUtils::CBuilder->new( |
| 189 | + quiet => 1, |
| 190 | + ); |
| 191 | + return $builder->have_compiler; |
| 192 | + } |
| 193 | + my @chunks = split(/ /, $Config::Config{cc}) or return; |
| 194 | + # $Config{cc} may contain args; try to find out the program part |
| 195 | + while (@chunks) { |
| 196 | + return can_run("@chunks") || (pop(@chunks), next); |
| 197 | + } |
| 198 | + return; |
| 199 | +} |
| 200 | + |
| 201 | +sub requires_external_bin { |
| 202 | + my ($bin, $version) = @_; |
| 203 | + if ( $version ) { |
| 204 | + die "requires_external_bin does not support versions yet"; |
| 205 | + } |
| 206 | + # Load the package containing can_run early, |
| 207 | + # to avoid breaking the message below. |
| 208 | + # Locate the bin |
| 209 | + print "Locating bin:$bin..."; |
| 210 | + my $found_bin = can_run( $bin ); |
| 211 | + if ( $found_bin ) { |
| 212 | + print " found at $found_bin.\n"; |
| 213 | + } else { |
| 214 | + print " missing.\n"; |
| 215 | + print "Unresolvable missing external dependency.\n"; |
| 216 | + print "Please install '$bin' seperately and try again.\n"; |
| 217 | + print STDERR "NA: Unable to build distribution on this platform.\n"; |
| 218 | + exit(0); |
| 219 | + } |
| 220 | + # Once we have some way to specify external deps, do it here. |
| 221 | + # In the mean time, continue as normal. |
| 222 | + 1; |
| 223 | +} |
| 224 | + |
8 | 225 | my %WriteMakefileArgs = ( |
9 | 226 | "ABSTRACT" => "Module signature file manipulation", |
10 | 227 | "AUTHOR" => "Audrey Tang <cpan\@audreyt.org>", |
| 228 | + "BUILD_REQUIRES" => { |
| 229 | + "ExtUtils::MakeMaker" => "6.36", |
| 230 | + "IPC::Run" => 0, |
| 231 | + "Test::More" => 0 |
| 232 | + }, |
11 | 233 | "CONFIGURE_REQUIRES" => { |
12 | | - "ExtUtils::MakeMaker" => 0 |
| 234 | + "ExtUtils::MakeMaker" => "6.36" |
13 | 235 | }, |
14 | 236 | "DISTNAME" => "Module-Signature", |
15 | 237 | "LICENSE" => "perl", |
16 | | - "MIN_PERL_VERSION" => "5.010", |
17 | 238 | "NAME" => "Module::Signature", |
18 | 239 | "PREREQ_PM" => { |
19 | | - "Crypt::OpenPGP" => 0, |
20 | | - "Crypt::OpenPGP::KeyServer" => 0, |
21 | | - "Exporter" => 0, |
22 | | - "ExtUtils::Manifest" => 0, |
23 | | - "File::Spec" => 0, |
24 | | - "File::Temp" => 0, |
25 | | - "IO::Socket::INET" => 0, |
26 | | - "Text::Diff" => 0, |
27 | | - "constant" => 0, |
28 | | - "strict" => 0, |
29 | | - "vars" => 0, |
30 | | - "version" => 0, |
31 | | - "warnings" => 0 |
32 | | - }, |
33 | | - "TEST_REQUIRES" => { |
34 | | - "Data::Dumper" => 0, |
35 | | - "File::Basename" => 0, |
36 | | - "File::Path" => 0, |
37 | | - "FindBin" => 0, |
38 | | - "Getopt::Long" => 0, |
39 | | - "IPC::Run" => 0, |
40 | | - "Pod::Usage" => 0, |
41 | | - "Socket" => 0, |
42 | | - "Test::More" => 0, |
43 | | - "lib" => 0 |
| 240 | + "File::Temp" => 0 |
44 | 241 | }, |
45 | | - "VERSION" => "0.90", |
| 242 | + "VERSION" => "0.91", |
46 | 243 | "test" => { |
47 | 244 | "TESTS" => "t/*.t" |
48 | 245 | } |
49 | 246 | ); |
50 | 247 |
|
| 248 | +%WriteMakefileArgs = ( |
| 249 | + %WriteMakefileArgs, |
| 250 | + %args, |
| 251 | + PREREQ_PM => {%{$WriteMakefileArgs{PREREQ_PM}}, %requires}, |
| 252 | +); |
51 | 253 |
|
52 | 254 | my %FallbackPrereqs = ( |
53 | | - "Crypt::OpenPGP" => 0, |
54 | | - "Crypt::OpenPGP::KeyServer" => 0, |
55 | | - "Data::Dumper" => 0, |
56 | | - "Exporter" => 0, |
57 | | - "ExtUtils::Manifest" => 0, |
58 | | - "File::Basename" => 0, |
59 | | - "File::Path" => 0, |
60 | | - "File::Spec" => 0, |
| 255 | + "ExtUtils::MakeMaker" => "6.36", |
61 | 256 | "File::Temp" => 0, |
62 | | - "FindBin" => 0, |
63 | | - "Getopt::Long" => 0, |
64 | | - "IO::Socket::INET" => 0, |
65 | 257 | "IPC::Run" => 0, |
66 | | - "Pod::Usage" => 0, |
67 | | - "Socket" => 0, |
68 | | - "Test::More" => 0, |
69 | | - "Text::Diff" => 0, |
70 | | - "constant" => 0, |
71 | | - "lib" => 0, |
72 | | - "strict" => 0, |
73 | | - "vars" => 0, |
74 | | - "version" => 0, |
75 | | - "warnings" => 0 |
| 258 | + "Test::More" => 0 |
76 | 259 | ); |
77 | 260 |
|
78 | | - |
79 | | -unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { |
| 261 | +unless ( eval { ExtUtils::MakeMaker->VERSION('6.63_03') } ) { |
80 | 262 | delete $WriteMakefileArgs{TEST_REQUIRES}; |
81 | 263 | delete $WriteMakefileArgs{BUILD_REQUIRES}; |
82 | 264 | $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; |
|
0 commit comments