| 1 | 1 | ▶ | use v5.42.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | no source::encoding; # Avoid dying on v5.42.0 (non-ASCII char in POD). | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Object::Pad 0.825; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package App::cpan2arch::WritePkgbuild; # For toolchain compatibility. | ||||||||||||||||||||||||||||
| 10 | role App::cpan2arch::WritePkgbuild; | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use open qw< :std :encoding(UTF-8) >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Basename qw< basename >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Scalar::Util qw< looks_like_number >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use List::Util qw< | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | any | ||||||||||||||||||||||||||||
| 18 | first | ||||||||||||||||||||||||||||
| 19 | reduce | ||||||||||||||||||||||||||||
| 20 | uniq | ||||||||||||||||||||||||||||
| 21 | 1 | >; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | $|++; # Disable STDOUT buffering. | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | our $VERSION = 'v1.1.2'; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | field $_install_license; | |||||||||||||||||||||||||||
| 28 | 1 | field %_generated_meta; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | field %_pkgbuild :reader :writer; | ||||||||||||||||||||||||||
|
Subroutine
pkgbuild: not called CC=1 SCAR=4.1
Subroutine
set_pkgbuild: not called CC=1 SCAR=4.1
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Generate the PKGBUILD bash script. | ||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||
| 33 | # References: | ||||||||||||||||||||||||||||
| 34 | # https://wiki.archlinux.org/title/Perl_package_guidelines | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | method generate_pkgbuild () | ||||||||||||||||||||||||||
|
Subroutine
generate_pkgbuild: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | 0 | $self->_psub; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | $self->_get_pkgbuild_vars; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my %opts = $self->opts; | |||||||||||||||||||||||||||
| 42 | 0 | my %meta = $self->meta; | |||||||||||||||||||||||||||
| 43 | 0 | my $mb = false; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # build() | ||||||||||||||||||||||||||||
| 46 | 0 | my $build; | |||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 0 | my %arch_prereqs = $self->arch_prereqs; | |||||||||||||||||||||||||||
| 49 | 0 | my @has_mb; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Set the builder to use in PKGBUILD | ||||||||||||||||||||||||||||
| 52 | # (Prefer M::B or M::B::T and use EU::MM as fallback) | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( !$meta{has_module_install} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | @has_mb = grep { /\Aperl-module-build(?> -tiny)? (?> [<>=] | \z )/x } $arch_prereqs{makedepends}->@*; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | $mb = true if scalar @has_mb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $build = $mb | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | ? <<~'END' | ||||||||||||||||||||||||||||
| 61 | unset PERL_MB_OPT PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 62 | export PERL_MM_USE_DEFAULT=1 MODULEBUILDRC=/dev/null | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | /usr/bin/perl Build.PL --create_packlist=0 | ||||||||||||||||||||||||||||
| 65 | ./Build | ||||||||||||||||||||||||||||
| 66 | END | ||||||||||||||||||||||||||||
| 67 | : <<~'END'; | ||||||||||||||||||||||||||||
| 68 | unset PERL_MM_OPT PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 69 | export PERL_MM_USE_DEFAULT=1 | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | /usr/bin/perl Makefile.PL NO_PACKLIST=1 NO_PERLLOCAL=1 | ||||||||||||||||||||||||||||
| 72 | make | ||||||||||||||||||||||||||||
| 73 | END | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Do not auto-install prereqs with Module::Install. | ||||||||||||||||||||||||||||
| 76 | $build =~ s{( PERL_MM_USE_DEFAULT=1(?=\n))}{$1 PERL_AUTOINSTALL=--skipdeps} | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if $meta{has_module_install}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | chomp $build; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Module::Build::Tiny does not support PERL_MM_USE_DEFAULT and MODULEBUILDRC. | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $build =~ s{^ {4}+export [^\n]+\n}{}m | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @has_mb and $has_mb[0] =~ /tiny/u
MC/DC0%0/2
scalar @has_mb and $has_mb[0] =~ /tiny/u
scalar @has_mb
$has_mb[0] =~ /tiny/u
Truth table0%0/3
A and B
A= scalar @has_mbB= $has_mb[0] =~ /tiny/u
| |||||||||||||||||||||||||||||
| 83 | if scalar @has_mb && $has_mb[0] =~ /tiny/; | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # check() | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $test = $mb ? q{./Build test} : q{make test}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # package() | ||||||||||||||||||||||||||||
| 90 | 0 | my $install; | |||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $install = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | $mb | ||||||||||||||||||||||||||||
| 94 | ? q{./Build install --installdirs=vendor --destdir="$pkgdir"} | ||||||||||||||||||||||||||||
| 95 | : q{make install INSTALLDIRS=vendor DESTDIR="$pkgdir"}; | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | $self->_pdump( '$_install_license', \$_install_license, "\n" ); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # Install a license file if it exists. | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( $_install_license && $meta{has_license} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_install_license and $meta{"has_license"}
MC/DC0%0/2
$_install_license and $meta{"has_license"}
$_install_license
$meta{"has_license"}
Truth table0%0/3
A and B
A= $_install_licenseB= $meta{"has_license"}
| |||||||||||||||||||||||||||||
| 101 | 0 | my $cmd = qq{\n install -Dm644 $meta{has_license} -t "\$pkgdir/usr/share/licenses/\$pkgname/"}; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | $install | ||||||||||||||||||||||||||||
| 104 | .= $meta{has_multi_licenses} | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | ? qq{\n\n # Multiple licenses found; manual inspection is advised to install the\n # correct file.$cmd} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | : $cmd; | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | my $pkgbuild = <<~"END"; | |||||||||||||||||||||||||||
| 111 | _author=$_pkgbuild{author} | ||||||||||||||||||||||||||||
| 112 | _dist=$_pkgbuild{dist} | ||||||||||||||||||||||||||||
| 113 | pkgname=perl-\${_dist\@L} | ||||||||||||||||||||||||||||
| 114 | pkgver=$_pkgbuild{pkgver} | ||||||||||||||||||||||||||||
| 115 | pkgrel=1 | ||||||||||||||||||||||||||||
| 116 | pkgdesc=$_pkgbuild{pkgdesc} | ||||||||||||||||||||||||||||
| 117 | arch=$_pkgbuild{arch} | ||||||||||||||||||||||||||||
| 118 | url=$_pkgbuild{url} | ||||||||||||||||||||||||||||
| 119 | $_pkgbuild{license} | ||||||||||||||||||||||||||||
| 120 | depends=$_pkgbuild{depends} | ||||||||||||||||||||||||||||
| 121 | makedepends=$_pkgbuild{makedepends} | ||||||||||||||||||||||||||||
| 122 | checkdepends=$_pkgbuild{checkdepends} | ||||||||||||||||||||||||||||
| 123 | optdepends=$_pkgbuild{optdepends} | ||||||||||||||||||||||||||||
| 124 | options=('!emptydirs') | ||||||||||||||||||||||||||||
| 125 | source=("$_pkgbuild{source}") | ||||||||||||||||||||||||||||
| 126 | sha256sums=('$_pkgbuild{sha256sums}') | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | build() | ||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||
| 130 | cd "\$_dist-\$pkgver" | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | $build | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | check() | ||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | cd "\$_dist-\$pkgver" | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | unset PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | $test | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | package() | ||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | cd "\$_dist-\$pkgver" | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | unset PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | $install | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | END | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # No need to set maintainer attribution on --update. | ||||||||||||||||||||||||||||
| 155 | $pkgbuild =~ s{\A}{# Maintainer: $_pkgbuild{packager}\n\n} | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | unless defined $opts{update}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # Warn the packager if the dist is an Alien. | ||||||||||||||||||||||||||||
| 159 | # See https://metacpan.org/pod/Alien. | ||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||
| 161 | 0 | my $NOTE_ALIEN = <<~'END'; | |||||||||||||||||||||||||||
| 162 | # Alien dists may have dynamic dependencies not listed in metadata; manual inspection | ||||||||||||||||||||||||||||
| 163 | # and clean chroot builds are advised. | ||||||||||||||||||||||||||||
| 164 | END | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ( $_pkgbuild{dist} =~ /\AAlien-/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 0 | $pkgbuild =~ s{^(?= _dist= )}{$NOTE_ALIEN}mx; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Strip empty deps arrays. | ||||||||||||||||||||||||||||
| 172 | 0 | $pkgbuild =~ s{^(?> make | check | opt )depends=\n}{}gmx; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | $_pkgbuild{output} = $pkgbuild; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | return $self; | |||||||||||||||||||||||||||
| 177 | 1 | } | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | # Map PKGBUILD variables for its generation. | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | method _get_pkgbuild_vars () | ||||||||||||||||||||||||||
|
Subroutine
_get_pkgbuild_vars: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||
| 182 | 0 | $self->_psub; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | my %env = $self->env; | |||||||||||||||||||||||||||
| 185 | 0 | my %opts = $self->opts; | |||||||||||||||||||||||||||
| 186 | 0 | my %meta = $self->meta; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | %_pkgbuild = ( | ||||||||||||||||||||||||||||
| 189 | packager => $env{packager}, | ||||||||||||||||||||||||||||
| 190 | author => $meta{author}, | ||||||||||||||||||||||||||||
| 191 | dist => $meta{dist}, | ||||||||||||||||||||||||||||
| 192 | pkgver => $meta{version}, | ||||||||||||||||||||||||||||
| 193 | pkgdesc => do { | ||||||||||||||||||||||||||||
| 194 | # Trim + escape single quotes with ANSI-C quoting. | ||||||||||||||||||||||||||||
| 195 | 0 | my $desc = trim( $meta{abstract} =~ s{'}{\\'}gr ); | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | $desc =~ /'/ ? qq{\$'$desc'} : qq{'$desc'}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 197 | }, | ||||||||||||||||||||||||||||
| 198 | arch => $meta{has_xs} | ||||||||||||||||||||||||||||
| 199 | ? q{('x86_64') # XS modules might depend on external libs; manual inspection is advised.} | ||||||||||||||||||||||||||||
| 200 | : q{('any')}, | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | url => 'https://metacpan.org/dist/$_dist', | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | license => $self->_build_license_array, | ||||||||||||||||||||||||||||
| 205 | depends => $self->_build_deps_array('depends'), | ||||||||||||||||||||||||||||
| 206 | makedepends => $self->_build_deps_array('makedepends'), | ||||||||||||||||||||||||||||
| 207 | checkdepends => $self->_build_deps_array('checkdepends'), | ||||||||||||||||||||||||||||
| 208 | optdepends => $self->_build_deps_array('optdepends'), | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | source => $meta{download_url} =~ s{ | ||||||||||||||||||||||||||||
| 211 | \A | ||||||||||||||||||||||||||||
| 212 | https://cpan\.metacpan\.org/authors/id/ | ||||||||||||||||||||||||||||
| 213 | \K | ||||||||||||||||||||||||||||
| 214 | [A-Z] / [A-Z]{2} / [A-Z]{3,9} / \Q$meta{name}\E | ||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | {\${_author::1}/\${_author::2}/\$_author/\$_dist-\$pkgver}rx, | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | sha256sums => $meta{checksum}, | ||||||||||||||||||||||||||||
| 219 | 0 | ); | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | $self->_pdump( '%_pkgbuild', \%_pkgbuild, "\n" ); | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 0 | return $self; | |||||||||||||||||||||||||||
| 224 | 1 | } | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | # Construct PKGBUILD's license array. | ||||||||||||||||||||||||||||
| 227 | # | ||||||||||||||||||||||||||||
| 228 | # NOTE: | ||||||||||||||||||||||||||||
| 229 | # Licenses not found in the licenses package must be installed at /usr/share/licenses/$pkgname/. | ||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||
| 231 | # CPAN Meta only covers few licenses and some of them are deprecated because | ||||||||||||||||||||||||||||
| 232 | # of its SPDX ID (e.g. AGPL-3.0), but the license text is the same and exist | ||||||||||||||||||||||||||||
| 233 | # at /usr/share/licenses/spdx under a different SPDX ID. | ||||||||||||||||||||||||||||
| 234 | # | ||||||||||||||||||||||||||||
| 235 | # References: | ||||||||||||||||||||||||||||
| 236 | # https://metacpan.org/pod/CPAN::Meta::Spec#license | ||||||||||||||||||||||||||||
| 237 | # https://wiki.archlinux.org/title/PKGBUILD#license | ||||||||||||||||||||||||||||
| 238 | # https://lists.archlinux.org/hyperkitty/list/arch-dev-public@lists.archlinux.org/thread/NFSB7734U2VVDULPRY65ECXDE3XGNZXM/ | ||||||||||||||||||||||||||||
| 239 | # https://spdx.github.io/spdx-spec/latest/annexes/spdx-license-expressions/ | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | method _build_license_array () | ||||||||||||||||||||||||||
|
Subroutine
_build_license_array: not called CC=26 SCAR=64.9
| |||||||||||||||||||||||||||||
| 241 | { | ||||||||||||||||||||||||||||
| 242 | 0 | $self->_psub; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | my $prog = $self->prog; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # Get the licenses from licenses package. | ||||||||||||||||||||||||||||
| 247 | 0 | my %arch_licenses; | |||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||
| 249 | 0 | my $SPDX_PATH = '/usr/share/licenses/spdx'; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ( -d $SPDX_PATH ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | %arch_licenses = map { basename( s{\.txt\z}{}r ) => 1 } glob "$SPDX_PATH/*.txt"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | # Fallback to its hardcoded licenses. | ||||||||||||||||||||||||||||
| 255 | else { | ||||||||||||||||||||||||||||
| 256 | 0 | $self->_pdbg("$SPDX_PATH does not exist\n"); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | # NOTE: | ||||||||||||||||||||||||||||
| 259 | # This is necessary for the CI tests since they do not ship with | ||||||||||||||||||||||||||||
| 260 | # Arch, so may be outdated. | ||||||||||||||||||||||||||||
| 261 | 0 | %arch_licenses = ( | |||||||||||||||||||||||||||
| 262 | 'AGPL-3.0-only' => 1, | ||||||||||||||||||||||||||||
| 263 | 'AGPL-3.0-or-later' => 1, | ||||||||||||||||||||||||||||
| 264 | 'Apache-2.0' => 1, | ||||||||||||||||||||||||||||
| 265 | 'Artistic-1.0-Perl' => 1, | ||||||||||||||||||||||||||||
| 266 | 'Artistic-2.0' => 1, | ||||||||||||||||||||||||||||
| 267 | 'BSL-1.0' => 1, | ||||||||||||||||||||||||||||
| 268 | 'CC-BY-1.0' => 1, | ||||||||||||||||||||||||||||
| 269 | 'CC-BY-2.0' => 1, | ||||||||||||||||||||||||||||
| 270 | 'CC-BY-2.5' => 1, | ||||||||||||||||||||||||||||
| 271 | 'CC-BY-3.0' => 1, | ||||||||||||||||||||||||||||
| 272 | 'CC-BY-3.0-AT' => 1, | ||||||||||||||||||||||||||||
| 273 | 'CC-BY-3.0-US' => 1, | ||||||||||||||||||||||||||||
| 274 | 'CC-BY-4.0' => 1, | ||||||||||||||||||||||||||||
| 275 | 'CC-BY-NC-1.0' => 1, | ||||||||||||||||||||||||||||
| 276 | 'CC-BY-NC-2.0' => 1, | ||||||||||||||||||||||||||||
| 277 | 'CC-BY-NC-2.5' => 1, | ||||||||||||||||||||||||||||
| 278 | 'CC-BY-NC-3.0' => 1, | ||||||||||||||||||||||||||||
| 279 | 'CC-BY-NC-4.0' => 1, | ||||||||||||||||||||||||||||
| 280 | 'CC-BY-NC-ND-1.0' => 1, | ||||||||||||||||||||||||||||
| 281 | 'CC-BY-NC-ND-2.0' => 1, | ||||||||||||||||||||||||||||
| 282 | 'CC-BY-NC-ND-2.5' => 1, | ||||||||||||||||||||||||||||
| 283 | 'CC-BY-NC-ND-3.0' => 1, | ||||||||||||||||||||||||||||
| 284 | 'CC-BY-NC-ND-3.0-IGO' => 1, | ||||||||||||||||||||||||||||
| 285 | 'CC-BY-NC-ND-4.0' => 1, | ||||||||||||||||||||||||||||
| 286 | 'CC-BY-NC-SA-1.0' => 1, | ||||||||||||||||||||||||||||
| 287 | 'CC-BY-NC-SA-2.0' => 1, | ||||||||||||||||||||||||||||
| 288 | 'CC-BY-NC-SA-2.5' => 1, | ||||||||||||||||||||||||||||
| 289 | 'CC-BY-NC-SA-3.0' => 1, | ||||||||||||||||||||||||||||
| 290 | 'CC-BY-NC-SA-4.0' => 1, | ||||||||||||||||||||||||||||
| 291 | 'CC-BY-ND-1.0' => 1, | ||||||||||||||||||||||||||||
| 292 | 'CC-BY-ND-2.0' => 1, | ||||||||||||||||||||||||||||
| 293 | 'CC-BY-ND-2.5' => 1, | ||||||||||||||||||||||||||||
| 294 | 'CC-BY-ND-3.0' => 1, | ||||||||||||||||||||||||||||
| 295 | 'CC-BY-ND-4.0' => 1, | ||||||||||||||||||||||||||||
| 296 | 'CC-BY-SA-1.0' => 1, | ||||||||||||||||||||||||||||
| 297 | 'CC-BY-SA-2.0' => 1, | ||||||||||||||||||||||||||||
| 298 | 'CC-BY-SA-2.0-UK' => 1, | ||||||||||||||||||||||||||||
| 299 | 'CC-BY-SA-2.1-JP' => 1, | ||||||||||||||||||||||||||||
| 300 | 'CC-BY-SA-2.5' => 1, | ||||||||||||||||||||||||||||
| 301 | 'CC-BY-SA-3.0' => 1, | ||||||||||||||||||||||||||||
| 302 | 'CC-BY-SA-3.0-AT' => 1, | ||||||||||||||||||||||||||||
| 303 | 'CC-BY-SA-4.0' => 1, | ||||||||||||||||||||||||||||
| 304 | 'CC-PDDC' => 1, | ||||||||||||||||||||||||||||
| 305 | 'CC0-1.0' => 1, | ||||||||||||||||||||||||||||
| 306 | 'CDDL-1.0' => 1, | ||||||||||||||||||||||||||||
| 307 | 'CDDL-1.1' => 1, | ||||||||||||||||||||||||||||
| 308 | 'CPL-1.0' => 1, | ||||||||||||||||||||||||||||
| 309 | 'EPL-1.0' => 1, | ||||||||||||||||||||||||||||
| 310 | 'EPL-2.0' => 1, | ||||||||||||||||||||||||||||
| 311 | 'FSFAP' => 1, | ||||||||||||||||||||||||||||
| 312 | 'GFDL-1.1-invariants-only' => 1, | ||||||||||||||||||||||||||||
| 313 | 'GFDL-1.1-invariants-or-later' => 1, | ||||||||||||||||||||||||||||
| 314 | 'GFDL-1.1-no-invariants-only' => 1, | ||||||||||||||||||||||||||||
| 315 | 'GFDL-1.1-no-invariants-or-later' => 1, | ||||||||||||||||||||||||||||
| 316 | 'GFDL-1.1-only' => 1, | ||||||||||||||||||||||||||||
| 317 | 'GFDL-1.1-or-later' => 1, | ||||||||||||||||||||||||||||
| 318 | 'GFDL-1.2-invariants-only' => 1, | ||||||||||||||||||||||||||||
| 319 | 'GFDL-1.2-invariants-or-later' => 1, | ||||||||||||||||||||||||||||
| 320 | 'GFDL-1.2-no-invariants-only' => 1, | ||||||||||||||||||||||||||||
| 321 | 'GFDL-1.2-no-invariants-or-later' => 1, | ||||||||||||||||||||||||||||
| 322 | 'GFDL-1.2-only' => 1, | ||||||||||||||||||||||||||||
| 323 | 'GFDL-1.2-or-later' => 1, | ||||||||||||||||||||||||||||
| 324 | 'GFDL-1.3-invariants-only' => 1, | ||||||||||||||||||||||||||||
| 325 | 'GFDL-1.3-invariants-or-later' => 1, | ||||||||||||||||||||||||||||
| 326 | 'GFDL-1.3-no-invariants-only' => 1, | ||||||||||||||||||||||||||||
| 327 | 'GFDL-1.3-no-invariants-or-later' => 1, | ||||||||||||||||||||||||||||
| 328 | 'GFDL-1.3-only' => 1, | ||||||||||||||||||||||||||||
| 329 | 'GFDL-1.3-or-later' => 1, | ||||||||||||||||||||||||||||
| 330 | 'GPL-1.0-only' => 1, | ||||||||||||||||||||||||||||
| 331 | 'GPL-1.0-or-later' => 1, | ||||||||||||||||||||||||||||
| 332 | 'GPL-2.0-only' => 1, | ||||||||||||||||||||||||||||
| 333 | 'GPL-2.0-or-later' => 1, | ||||||||||||||||||||||||||||
| 334 | 'GPL-3.0-only' => 1, | ||||||||||||||||||||||||||||
| 335 | 'GPL-3.0-or-later' => 1, | ||||||||||||||||||||||||||||
| 336 | 'GPL-CC-1.0' => 1, | ||||||||||||||||||||||||||||
| 337 | 'LGPL-2.0-only' => 1, | ||||||||||||||||||||||||||||
| 338 | 'LGPL-2.0-or-later' => 1, | ||||||||||||||||||||||||||||
| 339 | 'LGPL-2.1-only' => 1, | ||||||||||||||||||||||||||||
| 340 | 'LGPL-2.1-or-later' => 1, | ||||||||||||||||||||||||||||
| 341 | 'LGPL-3.0-only' => 1, | ||||||||||||||||||||||||||||
| 342 | 'LGPL-3.0-or-later' => 1, | ||||||||||||||||||||||||||||
| 343 | 'LGPLLR' => 1, | ||||||||||||||||||||||||||||
| 344 | 'LPPL-1.0' => 1, | ||||||||||||||||||||||||||||
| 345 | 'LPPL-1.1' => 1, | ||||||||||||||||||||||||||||
| 346 | 'LPPL-1.2' => 1, | ||||||||||||||||||||||||||||
| 347 | 'LPPL-1.3a' => 1, | ||||||||||||||||||||||||||||
| 348 | 'LPPL-1.3c' => 1, | ||||||||||||||||||||||||||||
| 349 | 'MPL-1.0' => 1, | ||||||||||||||||||||||||||||
| 350 | 'MPL-1.1' => 1, | ||||||||||||||||||||||||||||
| 351 | 'MPL-2.0' => 1, | ||||||||||||||||||||||||||||
| 352 | 'PHP-3.01' => 1, | ||||||||||||||||||||||||||||
| 353 | 'PHP-3.0' => 1, | ||||||||||||||||||||||||||||
| 354 | 'PSF-2.0' => 1, | ||||||||||||||||||||||||||||
| 355 | 'Ruby' => 1, | ||||||||||||||||||||||||||||
| 356 | 'Unlicense' => 1, | ||||||||||||||||||||||||||||
| 357 | 'W3C' => 1, | ||||||||||||||||||||||||||||
| 358 | 'WTFPL' => 1, | ||||||||||||||||||||||||||||
| 359 | 'ZPL-1.1' => 1, | ||||||||||||||||||||||||||||
| 360 | 'ZPL-2.0' => 1, | ||||||||||||||||||||||||||||
| 361 | 'ZPL-2.1' => 1, | ||||||||||||||||||||||||||||
| 362 | ); | ||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | $self->_pdump( '%arch_licenses', \%arch_licenses, "\n" ); | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 0 | my %opts = $self->opts; | |||||||||||||||||||||||||||
| 369 | 0 | my %meta = $self->meta; | |||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | # Prefer x_spdx_expression string over license array in metadata. | ||||||||||||||||||||||||||||
| 372 | { | ||||||||||||||||||||||||||||
| 373 | 0 | my $x_spdx = $meta{spdx_expression}; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ( defined $x_spdx ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | # Install license file whether IDs from SPDX expression exist in licenses package. | ||||||||||||||||||||||||||||
| 377 | 0 | foreach my $id ( split /\s+(?> AND | OR )\s+/x, $x_spdx ) { | |||||||||||||||||||||||||||
| 378 | 0 | ▶ | $_install_license = true unless exists $arch_licenses{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 0 | ▶ | push $_generated_meta{license}->@*, $x_spdx if defined $opts{update}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 0 | return "license=('$x_spdx')"; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | # Process metadata's license array. | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 0 | my $nl = ''; | |||||||||||||||||||||||||||
| 390 | 0 | my $indent = ''; | |||||||||||||||||||||||||||
| 391 | 0 | my $SPACE = q{ }; | |||||||||||||||||||||||||||
| 392 | 0 | my $START = '('; | |||||||||||||||||||||||||||
| 393 | 0 | my $END = ')'; | |||||||||||||||||||||||||||
| 394 | 0 | my $array = $START; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | # Multiline and indent the array string. | ||||||||||||||||||||||||||||
| 397 | 0 | ▶ | my sub multiline_array () | ||||||||||||||||||||||||||
|
Subroutine
multiline_array: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||
| 399 | 0 | $nl = "\n"; | |||||||||||||||||||||||||||
| 400 | 0 | $indent = $SPACE x 4; | |||||||||||||||||||||||||||
| 401 | 0 | $array = "${START}$nl"; | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 0 | ▶ | multiline_array() if scalar $meta{license}->@* > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | # Pre-process licenses to get their info. | ||||||||||||||||||||||||||||
| 407 | 0 | my @licenses; | |||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||
| 409 | 0 | my $NOTE = 'Unknown SPDX ID; manual inspection is advised.'; | |||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 0 | foreach my ( $idx, $license ) ( indexed $meta{license}->@* ) { | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $desc = | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 413 | $license eq 'open_source' ? 'Other Open Source Initiative (OSI) approved license.' | ||||||||||||||||||||||||||||
| 414 | : $license eq 'restricted' ? 'Requires special permission from copyright holder.' | ||||||||||||||||||||||||||||
| 415 | : $license eq 'unrestricted' ? 'Not an OSI approved license, but not restricted.' | ||||||||||||||||||||||||||||
| 416 | : $license eq 'unknown' ? 'License not provided in metadata.' | ||||||||||||||||||||||||||||
| 417 | : (); | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ( defined $desc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | 0 | ▶ | multiline_array() if $idx == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 0 | $_install_license = true; | |||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 0 | push @licenses, { | |||||||||||||||||||||||||||
| 425 | name => q{'unknown'}, | ||||||||||||||||||||||||||||
| 426 | desc => $desc, | ||||||||||||||||||||||||||||
| 427 | note => $NOTE, | ||||||||||||||||||||||||||||
| 428 | }; | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 0 | next; | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | # Guess license | ||||||||||||||||||||||||||||
| 434 | 0 | my @guesses; | |||||||||||||||||||||||||||
| 435 | { | ||||||||||||||||||||||||||||
| 436 | 0 | require Software::LicenseUtils; | |||||||||||||||||||||||||||
| 437 | 0 | Software::LicenseUtils->VERSION('0.104007'); | |||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | @guesses = Software::LicenseUtils->guess_license_from_meta_key($license); | |||||||||||||||||||||||||||
| 440 | 0 | $self->_pdump( '@guesses', \@guesses, "\n" ); | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | my $spdx = $guesses[0]->spdx_expression; | |||||||||||||||||||||||||||
| 444 | 0 | $self->_pdump( '$spdx', \$spdx, "\n" ); | |||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ( !defined $spdx ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 0 | $_install_license = true; | |||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 0 | push @licenses, { | |||||||||||||||||||||||||||
| 450 | name => q{'unknown'}, | ||||||||||||||||||||||||||||
| 451 | note => $NOTE, | ||||||||||||||||||||||||||||
| 452 | }; | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | 0 | next; | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | 0 | ▶ | if ( exists $arch_licenses{$spdx} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 458 | # Do not install license. | ||||||||||||||||||||||||||||
| 459 | 0 | push @licenses, { name => qq{'$spdx'} }; | |||||||||||||||||||||||||||
| 460 | 0 | next; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | # License text exists in licenses package under a different SPDX ID. | ||||||||||||||||||||||||||||
| 463 | elsif ( $spdx =~ /\A( AGPL-3\.0 | LGPL-(?> 2\.1 | 3\.0) )\z/x ) { | ||||||||||||||||||||||||||||
| 464 | 0 | ▶ | multiline_array() if $idx == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | push @licenses, { | |||||||||||||||||||||||||||
| 467 | name => qq{'$spdx'}, | ||||||||||||||||||||||||||||
| 468 | desc => "Deprecated by $1-only and $1-or-later.", | ||||||||||||||||||||||||||||
| 469 | note => 'License text is identical; manual inspection is advised.', | ||||||||||||||||||||||||||||
| 470 | }; | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 0 | next; | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | else { | ||||||||||||||||||||||||||||
| 475 | # Install license file whether IDs from SPDX expression exist in licenses package. | ||||||||||||||||||||||||||||
| 476 | 0 | foreach my $id ( split /\s+(?> AND | OR )\s+/x, $spdx ) { | |||||||||||||||||||||||||||
| 477 | 0 | ▶ | $_install_license = true unless exists $arch_licenses{$id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 0 | push @licenses, { name => qq{'$spdx'} }; | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 0 | $self->_pdump( '@licenses', \@licenses, "\n" ); | |||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 0 | ▶ | if ( defined $opts{update} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | 0 | foreach my $license (@licenses) { | |||||||||||||||||||||||||||
| 489 | 0 | push $_generated_meta{license}->@*, $license->{name} =~ s{\A' | '\z}{}grx; | |||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | # Post-process licenses and build the license array string. | ||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||
| 495 | 0 | my $max_str = 0; | |||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | # Get the maximum length string to align comments. | ||||||||||||||||||||||||||||
| 498 | $max_str = | ||||||||||||||||||||||||||||
| 499 | 0 | ▶ | length reduce { length $a > length $b ? $a : $b } map { $_->{name} } @licenses; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 0 | foreach my $info (@licenses) { | |||||||||||||||||||||||||||
| 502 | 0 | my ( $name, $desc, $note ) = $info->@{ qw< name desc note > }; | |||||||||||||||||||||||||||
| 503 | 0 | my $pad1 = $SPACE x 2; | |||||||||||||||||||||||||||
| 504 | 0 | my $pad2 = $pad1; | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | my ( $len_indent, $len_name, $len_pad1, $len_pad2 ) = | ||||||||||||||||||||||||||||
| 507 | 0 | map { length } ( $indent, $name, $pad1, $pad2 ); | |||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if ( $len_name < $max_str ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | 0 | $pad1 = $SPACE x ( $max_str - $len_name + $len_pad1 ); | |||||||||||||||||||||||||||
| 511 | 0 | $pad2 = $SPACE x ( $len_indent + $len_name + $len_pad2 + ( $max_str - $len_name ) ); | |||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||
| 513 | else { | ||||||||||||||||||||||||||||
| 514 | 0 | $pad2 = $SPACE x ( $len_indent + $len_name + $len_pad2 ); | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 0 | ▶ | if ( defined $desc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 518 | 0 | chomp( $array .= <<~"END" ); | |||||||||||||||||||||||||||
| 519 | ${indent}${name}$pad1# $desc | ||||||||||||||||||||||||||||
| 520 | $pad2# ${note}$nl | ||||||||||||||||||||||||||||
| 521 | END | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 0 | next; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 0 | $array .= "${indent}${name}$nl"; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 0 | $array .= $END; | |||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 0 | my $multi_note = ''; | |||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | # Warn the packager when multiple licenses are listed in metadata. | ||||||||||||||||||||||||||||
| 534 | 0 | ▶ | if ( scalar $meta{license}->@* > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | 0 | $multi_note = <<~'END'; | |||||||||||||||||||||||||||
| 536 | # Multiple licenses listed in metadata; manual inspection is advised to | ||||||||||||||||||||||||||||
| 537 | # construct a proper SPDX expression. | ||||||||||||||||||||||||||||
| 538 | END | ||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | 0 | $array = "${multi_note}license=$array"; | |||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 0 | $self->_pdbg( '$array = ' . $array . "\n\n" ); | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 0 | return $array; | |||||||||||||||||||||||||||
| 547 | 1 | } | |||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | # Construct PKGBUILD's dependencies array. | ||||||||||||||||||||||||||||
| 550 | 0 | ▶ | method _build_deps_array ($var) | ||||||||||||||||||||||||||
|
Subroutine
_build_deps_array: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||
| 551 | { | ||||||||||||||||||||||||||||
| 552 | 0 | $self->_psub; | |||||||||||||||||||||||||||
| 553 | 0 | $self->_pdump( '$var', \$var, "\n" ); | |||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | 0 | my %arch_prereqs = $self->arch_prereqs; | |||||||||||||||||||||||||||
| 556 | 0 | ▶ | return '' unless exists $arch_prereqs{$var}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | 0 | my $nl = ''; | |||||||||||||||||||||||||||
| 559 | 0 | my $indent = ''; | |||||||||||||||||||||||||||
| 560 | 0 | my $SPACE = q{ }; | |||||||||||||||||||||||||||
| 561 | 0 | my $START = '('; | |||||||||||||||||||||||||||
| 562 | 0 | my $END = ')'; | |||||||||||||||||||||||||||
| 563 | 0 | my $max_str = 0; | |||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | # Multiline and indent the array on multiple packages. | ||||||||||||||||||||||||||||
| 566 | 0 | ▶ | if ( scalar $arch_prereqs{$var}->@* > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 567 | 0 | $nl = "\n"; | |||||||||||||||||||||||||||
| 568 | 0 | $indent = $SPACE x 4; | |||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | # Get the maximum length from string for comments alignment. | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | my @normalize = | ||||||||||||||||||||||||||||
| 573 | 0 | ▶ | map { defined reftype $_ && reftype $_ eq 'HASH' ? keys $_->%* : $_ } $arch_prereqs{$var}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined builtin::reftype($_) and builtin::reftype($_) eq "HASH"
MC/DC0%0/2
defined builtin::reftype($_) and builtin::reftype($_) eq "HASH"
defined builtin::reftype($_)
builtin::reftype($_) eq "HASH"
Truth table0%0/3
A and B
A= defined builtin::reftype($_)B= builtin::reftype($_) eq "HASH"
| |||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 0 | ▶ | $max_str = length reduce { length $a > length $b ? $a : $b } @normalize; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 0 | my $array = "${START}$nl"; | |||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | 0 | foreach my $dep ( $arch_prereqs{$var}->@* ) { | |||||||||||||||||||||||||||
| 581 | 0 | ▶ | my $deptype = reftype $dep // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
builtin::reftype($dep) // ""
MC/DC0%0/1
builtin::reftype($dep) // ""
builtin::reftype($dep)
Truth table0%0/2
A
A= builtin::reftype($dep)
| |||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | # Append a comment for packages that are flagged or not found in the Official/AUR repos. | ||||||||||||||||||||||||||||
| 584 | 0 | ▶ | if ( $deptype eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 585 | 0 | my $pad = $SPACE x 2; | |||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | 0 | foreach my ( $pkg, $status ) ( $dep->%* ) { | |||||||||||||||||||||||||||
| 588 | 0 | my ( $failed, $missing, $date ) = $status->@{ qw< failed missing flag_date > }; | |||||||||||||||||||||||||||
| 589 | 0 | ▶ | my $version = $status->{version} ? " (version: $status->{version})" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 0 | ▶ | my $comment = | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 592 | defined $failed ? "Failed to fetch $pkg module$version.$nl" | ||||||||||||||||||||||||||||
| 593 | : defined $missing ? "Package for $missing is missing.$nl" | ||||||||||||||||||||||||||||
| 594 | : defined $date ? "Package is flagged out-of-date on $date.$nl" | ||||||||||||||||||||||||||||
| 595 | : (); | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 0 | ▶ | $pkg = '?' if defined $failed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 0 | my $len_pkg = length $pkg; | |||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 0 | ▶ | $pad = $SPACE x ( $max_str - $len_pkg + length $pad ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | if $len_pkg < $max_str; | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | # Escape single quotes with ANSI-C quoting (for optdepends descriptions). | ||||||||||||||||||||||||||||
| 605 | 0 | ▶ | my $ansi = $pkg =~ /'/ ? '$' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | 0 | $array .= "${indent}$ansi'$pkg'$pad# $comment"; | |||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | 0 | $self->_pdbg("found commented pkg\n"); | |||||||||||||||||||||||||||
| 610 | 0 | $self->_pdump( '$dep', $dep, "\n" ); | |||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | else { | ||||||||||||||||||||||||||||
| 614 | 0 | ▶ | my $ansi = $dep =~ /'/ ? '$' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 615 | 0 | $array .= "${indent}$ansi'$dep'$nl"; | |||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 0 | $array .= $END; | |||||||||||||||||||||||||||
| 620 | 0 | $self->_pdbg( '$array = ' . $array . "\n\n" ); | |||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 0 | return $array; | |||||||||||||||||||||||||||
| 623 | 1 | } | |||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | # Write the generated PKBUILD to STDOUT or its file in the current dir. | ||||||||||||||||||||||||||||
| 626 | 0 | ▶ | method write_pkgbuild () | ||||||||||||||||||||||||||
|
Subroutine
write_pkgbuild: not called CC=86 SCAR=89.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 627 | { | ||||||||||||||||||||||||||||
| 628 | 0 | $self->_psub; | |||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 0 | ▶ | return 0 unless defined $_pkgbuild{output}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | 0 | my %opts = $self->opts; | |||||||||||||||||||||||||||
| 633 | 0 | my $prog = $self->prog; | |||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | 0 | ▶ | if ( defined $opts{update} || defined $opts{write} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{"update"} or defined $opts{"write"}
MC/DC0%0/2
defined $opts{"update"} or defined $opts{"write"}
defined $opts{"update"}
defined $opts{"write"}
Truth table0%0/3
A or B
A= defined $opts{"update"}B= defined $opts{"write"}
| |||||||||||||||||||||||||||||
| 636 | 0 | require Path::Tiny; | |||||||||||||||||||||||||||
| 637 | 0 | Path::Tiny->VERSION('0.150'); | |||||||||||||||||||||||||||
| 638 | 0 | Path::Tiny->import( qw< path > ); | |||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | 0 | my %FILES = ( | |||||||||||||||||||||||||||
| 642 | outfile => 'PKGBUILD', | ||||||||||||||||||||||||||||
| 643 | metadata => '.SRCINFO', | ||||||||||||||||||||||||||||
| 644 | ); | ||||||||||||||||||||||||||||
| 645 | 0 | $self->_pdump( '%FILES', \%FILES, "\n" ); | |||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | # --update | ||||||||||||||||||||||||||||
| 648 | 0 | ▶ | if ( defined $opts{update} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 649 | 0 | foreach my ( $k, $fname ) (%FILES) { | |||||||||||||||||||||||||||
| 650 | 0 | ▶ | if ( !-f $fname ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 651 | 0 | warn "$prog: $fname does not exist\n"; | |||||||||||||||||||||||||||
| 652 | 0 | return 1; | |||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 0 | my %env = $self->env; | |||||||||||||||||||||||||||
| 657 | 0 | my %meta = $self->meta; | |||||||||||||||||||||||||||
| 658 | 0 | my $pkgname = lc "perl-$_pkgbuild{dist}"; | |||||||||||||||||||||||||||
| 659 | 0 | my $gen_output = $_pkgbuild{output}; | |||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | # Get .SRCINFO data. | ||||||||||||||||||||||||||||
| 662 | 0 | my %srcinfo_meta; | |||||||||||||||||||||||||||
| 663 | { | ||||||||||||||||||||||||||||
| 664 | 0 | my @srcinfo = path( $FILES{metadata} )->lines_utf8( { chomp => 1 } ); | |||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | 0 | ▶ | if ( scalar @srcinfo ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 667 | # Split packages do not make sense in Perl packages. | ||||||||||||||||||||||||||||
| 668 | 0 | ▶ | my $index = first { $srcinfo[$_] =~ /\Apkgname = / } 0 .. $#srcinfo; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 669 | 0 | ▶ | splice @srcinfo, $index if defined $index; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | 0 | $self->_pdump( '@srcinfo', \@srcinfo, "\n" ); | |||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | 0 | my @VARS = ( | |||||||||||||||||||||||||||
| 675 | qw< | ||||||||||||||||||||||||||||
| 676 | pkgbase | ||||||||||||||||||||||||||||
| 677 | pkgver | ||||||||||||||||||||||||||||
| 678 | pkgrel | ||||||||||||||||||||||||||||
| 679 | epoch | ||||||||||||||||||||||||||||
| 680 | pkgdesc | ||||||||||||||||||||||||||||
| 681 | url | ||||||||||||||||||||||||||||
| 682 | install | ||||||||||||||||||||||||||||
| 683 | changelog | ||||||||||||||||||||||||||||
| 684 | > | ||||||||||||||||||||||||||||
| 685 | ); | ||||||||||||||||||||||||||||
| 686 | 0 | my @NEEDED_VARS = ( | |||||||||||||||||||||||||||
| 687 | qw< | ||||||||||||||||||||||||||||
| 688 | pkgbase | ||||||||||||||||||||||||||||
| 689 | pkgver | ||||||||||||||||||||||||||||
| 690 | pkgrel | ||||||||||||||||||||||||||||
| 691 | > | ||||||||||||||||||||||||||||
| 692 | ); | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | # References: | ||||||||||||||||||||||||||||
| 695 | # https://wiki.archlinux.org/title/.SRCINFO | ||||||||||||||||||||||||||||
| 696 | # https://man.archlinux.org/man/SRCINFO.5 | ||||||||||||||||||||||||||||
| 697 | # https://man.archlinux.org/man/alpm-pkgver.7 | ||||||||||||||||||||||||||||
| 698 | # https://man.archlinux.org/man/alpm-pkgrel.7 | ||||||||||||||||||||||||||||
| 699 | 0 | foreach my $line (@srcinfo) { | |||||||||||||||||||||||||||
| 700 | 0 | ▶ | next if $line eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | 0 | my ( $key, $val ) = split / = /, $line; | |||||||||||||||||||||||||||
| 703 | 0 | ▶ | next unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 704 | 0 | $key =~ s{\A\t}{}; | |||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | 0 | ▶ | if ( any { $key eq $_ } @VARS ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 707 | 0 | $srcinfo_meta{$key} = $val; | |||||||||||||||||||||||||||
| 708 | 0 | next; | |||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | 0 | push $srcinfo_meta{$key}->@*, $val; | |||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | 0 | $self->_pdump( '%srcinfo_meta', \%srcinfo_meta, "\n" ); | |||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||
| 716 | 0 | foreach my ($var) (@NEEDED_VARS) { | |||||||||||||||||||||||||||
| 717 | 0 | ▶ | if ( !exists $srcinfo_meta{$var} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 718 | 0 | warn "$prog: $var is not declared in $FILES{metadata}\n"; | |||||||||||||||||||||||||||
| 719 | 0 | return 1; | |||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | 0 | ▶ | if ( $pkgname ne $srcinfo_meta{pkgbase} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 724 | 0 | warn "$prog: $FILES{metadata} package ($srcinfo_meta{pkgbase}) is different than $pkgname\n"; | |||||||||||||||||||||||||||
| 725 | 0 | return 1; | |||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | # .SRCINFO pkgver must not be newer than generated PKGBUILD pkgver. | ||||||||||||||||||||||||||||
| 730 | { | ||||||||||||||||||||||||||||
| 731 | 0 | my $ret = $self->_comp_vers( $_pkgbuild{pkgver}, $srcinfo_meta{pkgver}, '<' ); | |||||||||||||||||||||||||||
| 732 | 0 | ▶ | return 1 if defined $ret && $ret == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ret and $ret == 1
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret
$ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
| |||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||
| 734 | 0 | ▶ | if ( defined $ret && $ret == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ret and $ret == 0
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret
$ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
| |||||||||||||||||||||||||||||
| 735 | 0 | warn "$prog: $FILES{metadata} version ($srcinfo_meta{pkgver}) is newer than $_pkgbuild{pkgver}\n"; | |||||||||||||||||||||||||||
| 736 | 0 | return 1; | |||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | 0 | ▶ | if ( !looks_like_number( $srcinfo_meta{pkgrel} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 741 | 0 | warn "$prog: pkgrel $srcinfo_meta{pkgrel} is not a number\n"; | |||||||||||||||||||||||||||
| 742 | 0 | return 1; | |||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | # Add epoch if newer version breaks pacman's version comparison logic. | ||||||||||||||||||||||||||||
| 746 | # | ||||||||||||||||||||||||||||
| 747 | # References: | ||||||||||||||||||||||||||||
| 748 | # https://wiki.archlinux.org/title/PKGBUILD#epoch | ||||||||||||||||||||||||||||
| 749 | # https://man.archlinux.org/man/core/pacman/PKGBUILD.5.en#:~:text=epoch | ||||||||||||||||||||||||||||
| 750 | # https://man.archlinux.org/man/alpm-epoch.7 | ||||||||||||||||||||||||||||
| 751 | # https://man.archlinux.org/man/vercmp.8 | ||||||||||||||||||||||||||||
| 752 | # https://gitlab.archlinux.org/pacman/pacman/-/blob/master/lib/libalpm/version.c | ||||||||||||||||||||||||||||
| 753 | 0 | my $has_epoch = false; | |||||||||||||||||||||||||||
| 754 | { | ||||||||||||||||||||||||||||
| 755 | 0 | my $ret = $self->_comp_vers( $_pkgbuild{pkgver}, $srcinfo_meta{pkgver}, '>' ); | |||||||||||||||||||||||||||
| 756 | 0 | ▶ | return 1 if defined $ret && $ret == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ret and $ret == 1
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret
$ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
| |||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||
| 758 | 0 | ▶ | if ( defined $ret && $ret == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ret and $ret == 0
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret
$ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
| |||||||||||||||||||||||||||||
| 759 | 0 | require Devel::CheckBin; | |||||||||||||||||||||||||||
| 760 | 0 | Devel::CheckBin->VERSION('0.04'); | |||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||
| 762 | 0 | my $cmd_path = Devel::CheckBin::can_run('vercmp'); | |||||||||||||||||||||||||||
| 763 | 0 | $self->_pdump( '$cmd_path', \$cmd_path, '' ); | |||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||
| 765 | 0 | ▶ | if ( defined $cmd_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 766 | 0 | require Capture::Tiny; | |||||||||||||||||||||||||||
| 767 | 0 | Capture::Tiny->VERSION('0.50'); | |||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | my ( $stdout, $stderr, $exit ) = Capture::Tiny::capture( | ||||||||||||||||||||||||||||
| 770 | 0 | ▶ | sub { system( $cmd_path, $_pkgbuild{pkgver}, $srcinfo_meta{pkgver} ) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 771 | 0 | ); | |||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||
| 773 | 0 | $self->_pdump( '$stdout', \$stdout, '' ); | |||||||||||||||||||||||||||
| 774 | 0 | $self->_pdump( '$stderr', \$stderr, '' ); | |||||||||||||||||||||||||||
| 775 | 0 | $self->_pdump( '$exit', \$exit, '' ); | |||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||
| 777 | 0 | ▶ | if ( $exit != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 778 | 0 | warn $stderr; | |||||||||||||||||||||||||||
| 779 | 0 | warn "$prog: failed to run vercmp\n"; | |||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||
| 781 | 0 | return 1; | |||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||
| 784 | # New version breaks vercmp logic. | ||||||||||||||||||||||||||||
| 785 | 0 | ▶ | if ( $stdout < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 786 | 0 | ▶ | my $epoch = $srcinfo_meta{epoch} // 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$srcinfo_meta{"epoch"} // 1
MC/DC0%0/1
$srcinfo_meta{"epoch"} // 1
$srcinfo_meta{"epoch"}
Truth table0%0/2
A
A= $srcinfo_meta{"epoch"}
| |||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | 0 | ▶ | if ( exists $srcinfo_meta{epoch} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 789 | 0 | ++$epoch; | |||||||||||||||||||||||||||
| 790 | 0 | $self->_pdbg("bump epoch to $epoch\n"); | |||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||
| 793 | 0 | ▶ | if ( $gen_output =~ s{^pkgrel=[^\n]+\n\K}{epoch=$epoch\n}m ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 794 | 0 | $has_epoch = true; | |||||||||||||||||||||||||||
| 795 | 0 | $self->_pdbg("add epoch\n"); | |||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||
| 799 | 0 | $self->_pdbg("\n"); | |||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||
| 801 | else { | ||||||||||||||||||||||||||||
| 802 | 0 | warn "$prog: vercmp is not installed\n"; | |||||||||||||||||||||||||||
| 803 | 0 | return 1; | |||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | # Sort metadatas for proper comparison. | ||||||||||||||||||||||||||||
| 809 | 0 | my %meta_a; # .SRCINFO | |||||||||||||||||||||||||||
| 810 | my %meta_b; # Generated PKGBUILD | ||||||||||||||||||||||||||||
| 811 | { | ||||||||||||||||||||||||||||
| 812 | 0 | ▶ | my sub sort_meta (%m) | ||||||||||||||||||||||||||
|
Subroutine
sort_meta: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 813 | { | ||||||||||||||||||||||||||||
| 814 | 0 | my %sorted; | |||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||
| 816 | 0 | foreach my ( $var, $deps ) (%m) { | |||||||||||||||||||||||||||
| 817 | 0 | my $type = reftype $deps; | |||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||
| 819 | 0 | ▶ | if ( defined $type && $type eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $type and $type eq "ARRAY"
MC/DC0%0/2
defined $type and $type eq "ARRAY"
defined $type
$type eq "ARRAY"
Truth table0%0/3
A and B
A= defined $typeB= $type eq "ARRAY"
| |||||||||||||||||||||||||||||
| 820 | 0 | push $sorted{$var}->@*, sort $deps->@*; | |||||||||||||||||||||||||||
| 821 | 0 | next; | |||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||
| 824 | 0 | $sorted{$var} = $deps; | |||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||
| 827 | 0 | return %sorted; | |||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||
| 830 | # Build the generated PKGBUILD metadata hash for sorting. | ||||||||||||||||||||||||||||
| 831 | { | ||||||||||||||||||||||||||||
| 832 | 0 | my %arch_prereqs = $self->arch_prereqs; | |||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||
| 834 | 0 | foreach my ( $var, $pkgs ) (%arch_prereqs) { | |||||||||||||||||||||||||||
| 835 | 0 | foreach my $pkg ( $pkgs->@* ) { | |||||||||||||||||||||||||||
| 836 | 0 | my $pkgtype = reftype $pkg; | |||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||
| 838 | # Normalize pkgs. | ||||||||||||||||||||||||||||
| 839 | 0 | ▶ | push $_generated_meta{$var}->@*, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $pkgtype and $pkgtype eq "HASH"
MC/DC0%0/2
defined $pkgtype and $pkgtype eq "HASH"
defined $pkgtype
$pkgtype eq "HASH"
Truth table0%0/3
A and B
A= defined $pkgtypeB= $pkgtype eq "HASH"
| |||||||||||||||||||||||||||||
| 840 | defined $pkgtype && $pkgtype eq 'HASH' | ||||||||||||||||||||||||||||
| 841 | ? keys $pkg->%* | ||||||||||||||||||||||||||||
| 842 | : $pkg; | ||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||
| 846 | 0 | $_generated_meta{pkgbase} = $pkgname; | |||||||||||||||||||||||||||
| 847 | 0 | $_generated_meta{pkgver} = $meta{version}; | |||||||||||||||||||||||||||
| 848 | 0 | $_generated_meta{pkgrel} = 1; | |||||||||||||||||||||||||||
| 849 | 0 | $_generated_meta{pkgdesc} = $meta{abstract}; | |||||||||||||||||||||||||||
| 850 | 0 | $_generated_meta{url} = "https://metacpan.org/dist/$meta{dist}"; | |||||||||||||||||||||||||||
| 851 | 0 | ▶ | push $_generated_meta{arch}->@*, $meta{has_xs} ? 'x86_64' : 'any'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 852 | 0 | push $_generated_meta{options}->@*, '!emptydirs'; | |||||||||||||||||||||||||||
| 853 | 0 | push $_generated_meta{source}->@*, $meta{download_url}; | |||||||||||||||||||||||||||
| 854 | 0 | push $_generated_meta{sha256sums}->@*, $meta{checksum}; | |||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||
| 856 | #$self->_pdump( '%_generated_meta', \%_generated_meta, "\n" ); | ||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||
| 859 | 0 | %meta_a = sort_meta(%srcinfo_meta); | |||||||||||||||||||||||||||
| 860 | 0 | %meta_b = sort_meta(%_generated_meta); | |||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||
| 862 | 0 | $self->_pdump( '%meta_a', \%meta_a, "\n" ); | |||||||||||||||||||||||||||
| 863 | 0 | $self->_pdump( '%meta_b', \%meta_b, "\n" ); | |||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||
| 866 | # Compare and show metadata differences. | ||||||||||||||||||||||||||||
| 867 | 0 | my $is_diff = false; | |||||||||||||||||||||||||||
| 868 | { | ||||||||||||||||||||||||||||
| 869 | 0 | require List::Compare; | |||||||||||||||||||||||||||
| 870 | 0 | List::Compare->VERSION('0.55'); | |||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||
| 872 | 0 | require Term::Table; | |||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||
| 874 | 0 | my %compare_data = ( | |||||||||||||||||||||||||||
| 875 | missing => { | ||||||||||||||||||||||||||||
| 876 | meta_a => undef, | ||||||||||||||||||||||||||||
| 877 | meta_b => undef, | ||||||||||||||||||||||||||||
| 878 | }, | ||||||||||||||||||||||||||||
| 879 | unique => { | ||||||||||||||||||||||||||||
| 880 | meta_a => undef, | ||||||||||||||||||||||||||||
| 881 | meta_b => undef, | ||||||||||||||||||||||||||||
| 882 | }, | ||||||||||||||||||||||||||||
| 883 | different => { | ||||||||||||||||||||||||||||
| 884 | meta_a => undef, | ||||||||||||||||||||||||||||
| 885 | meta_b => undef, | ||||||||||||||||||||||||||||
| 886 | }, | ||||||||||||||||||||||||||||
| 887 | ); | ||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||
| 889 | # Get missing vars from both metadatas. | ||||||||||||||||||||||||||||
| 890 | # | ||||||||||||||||||||||||||||
| 891 | # NOTE: | ||||||||||||||||||||||||||||
| 892 | # pkgrel and epoch must not be in the comparison since the generated | ||||||||||||||||||||||||||||
| 893 | # pkgrel value is always 1 and epoch is never generated. | ||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||
| 895 | 0 | my @vars_a; | |||||||||||||||||||||||||||
| 896 | my @vars_b; | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | 0 | foreach my $var ( sort keys %meta_a ) { | |||||||||||||||||||||||||||
| 899 | 0 | ▶ | next if $var eq 'pkgrel' || $var eq 'epoch'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$var eq "pkgrel" or $var eq "epoch"
MC/DC0%0/2
$var eq "pkgrel" or $var eq "epoch"
$var eq "pkgrel"
$var eq "epoch"
Truth table0%0/3
A or B
A= $var eq "pkgrel"B= $var eq "epoch"
| |||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | 0 | ▶ | if ( !exists $meta_b{$var} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 902 | 0 | $is_diff = true; | |||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||
| 904 | 0 | $meta_b{$var} = []; | |||||||||||||||||||||||||||
| 905 | 0 | push $compare_data{missing}{meta_b}->@*, $var; | |||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||
| 908 | 0 | push @vars_a, $var; | |||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||
| 911 | 0 | foreach my $var ( sort keys %meta_b ) { | |||||||||||||||||||||||||||
| 912 | 0 | ▶ | next if $var eq 'pkgrel' || $var eq 'epoch'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$var eq "pkgrel" or $var eq "epoch"
MC/DC0%0/2
$var eq "pkgrel" or $var eq "epoch"
$var eq "pkgrel"
$var eq "epoch"
Truth table0%0/3
A or B
A= $var eq "pkgrel"B= $var eq "epoch"
| |||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||
| 914 | 0 | ▶ | if ( !exists $meta_a{$var} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 915 | 0 | $is_diff = true; | |||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | 0 | $meta_a{$var} = []; | |||||||||||||||||||||||||||
| 918 | 0 | push $compare_data{missing}{meta_a}->@*, $var; | |||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||
| 921 | 0 | push @vars_b, $var; | |||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||
| 924 | 0 | my @vars = uniq @vars_a, @vars_b; | |||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||
| 926 | # Compare both metadatas to get their unique and different vars. | ||||||||||||||||||||||||||||
| 927 | 0 | foreach my $var (@vars) { | |||||||||||||||||||||||||||
| 928 | 0 | ▶ | my $type_a = reftype $meta_a{$var} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
builtin::reftype($meta_a{$var}) // ""
MC/DC0%0/1
builtin::reftype($meta_a{$var}) // ""
builtin::reftype($meta_a{$var})
Truth table0%0/2
A
A= builtin::reftype($meta_a{$var})
| |||||||||||||||||||||||||||||
| 929 | 0 | ▶ | my $type_b = reftype $meta_b{$var} // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
builtin::reftype($meta_b{$var}) // ""
MC/DC0%0/1
builtin::reftype($meta_b{$var}) // ""
builtin::reftype($meta_b{$var})
Truth table0%0/2
A
A= builtin::reftype($meta_b{$var})
| |||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||
| 931 | # Unique | ||||||||||||||||||||||||||||
| 932 | 0 | ▶ | if ( $type_a eq 'ARRAY' && $type_b eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type_a eq "ARRAY" and $type_b eq "ARRAY"
MC/DC0%0/2
$type_a eq "ARRAY" and $type_b eq "ARRAY"
$type_a eq "ARRAY"
$type_b eq "ARRAY"
Truth table0%0/3
A and B
A= $type_a eq "ARRAY"B= $type_b eq "ARRAY"
| |||||||||||||||||||||||||||||
| 933 | 0 | my $lc = List::Compare->new( \$meta_a{$var}->@*, \$meta_b{$var}->@* ); | |||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | 0 | ▶ | if ( !$lc->is_LequivalentR ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 936 | 0 | my @lonly = $lc->get_Lonly; | |||||||||||||||||||||||||||
| 937 | 0 | my @ronly = $lc->get_Ronly; | |||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | 0 | ▶ | if ( scalar @lonly ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 940 | 0 | $is_diff = true; | |||||||||||||||||||||||||||
| 941 | 0 | push $compare_data{unique}{meta_a}{$var}->@*, @lonly; | |||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||
| 944 | 0 | ▶ | if ( scalar @ronly ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 945 | 0 | $is_diff = true; | |||||||||||||||||||||||||||
| 946 | 0 | push $compare_data{unique}{meta_b}{$var}->@*, @ronly; | |||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||
| 950 | # Different | ||||||||||||||||||||||||||||
| 951 | else { | ||||||||||||||||||||||||||||
| 952 | 0 | ▶ | my $str_a = $type_a eq 'ARRAY' ? 'N/A' : $meta_a{$var}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 953 | 0 | ▶ | my $str_b = $type_b eq 'ARRAY' ? 'N/A' : $meta_b{$var}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||
| 955 | 0 | ▶ | if ( $str_a ne $str_b ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 956 | 0 | $is_diff = true; | |||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||
| 958 | 0 | $compare_data{different}{meta_a}{$var} = $str_a; | |||||||||||||||||||||||||||
| 959 | 0 | $compare_data{different}{meta_b}{$var} = $str_b; | |||||||||||||||||||||||||||
| 960 | } | ||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||
| 964 | 0 | $self->_pdump( '%compare_data', \%compare_data, "\n" ); | |||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||
| 966 | # Show comparison in a table. | ||||||||||||||||||||||||||||
| 967 | 0 | ▶ | if ($is_diff) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 968 | 0 | warn "$prog: $FILES{metadata} is different than generated metadata\n"; | |||||||||||||||||||||||||||
| 969 | 0 | warn "\nMetadata comparison\n"; | |||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||
| 971 | 0 | my @rows; | |||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||
| 973 | 0 | foreach my $meta ( sort keys $compare_data{missing}->%* ) { | |||||||||||||||||||||||||||
| 974 | 0 | foreach my $var ( $compare_data{missing}{$meta}->@* ) { | |||||||||||||||||||||||||||
| 975 | 0 | ▶ | push @rows, [ $var, 'N/A', '-', "Missing from $FILES{metadata}" ] if $meta eq 'meta_a'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 976 | 0 | ▶ | push @rows, [ $var, '-', 'N/A', 'Missing from Generated' ] if $meta eq 'meta_b'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||
| 980 | 0 | foreach my $meta ( sort keys $compare_data{unique}->%* ) { | |||||||||||||||||||||||||||
| 981 | 0 | foreach my $var ( sort keys $compare_data{unique}{$meta}->%* ) { | |||||||||||||||||||||||||||
| 982 | 0 | my $pkgs = join ', ', $compare_data{unique}{$meta}{$var}->@*; | |||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||
| 984 | 0 | ▶ | push @rows, [ $var, $pkgs, '-', "Only in $FILES{metadata}" ] if $meta eq 'meta_a'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 985 | 0 | ▶ | push @rows, [ $var, '-', $pkgs, 'Only in Generated' ] if $meta eq 'meta_b'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 986 | } | ||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||
| 989 | 0 | ▶ | if ( keys $compare_data{different}{meta_a}->%* ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 990 | 0 | foreach my $var ( sort keys $compare_data{different}{meta_a}->%* ) { | |||||||||||||||||||||||||||
| 991 | 0 | my $str_a = $compare_data{different}{meta_a}{$var}; | |||||||||||||||||||||||||||
| 992 | 0 | my $str_b = $compare_data{different}{meta_b}{$var}; | |||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||
| 994 | 0 | push @rows, [ $var, $str_a, $str_b, 'Differs' ]; | |||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||
| 998 | #$self->_pdump( '@rows', \@rows, "\n" ); | ||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||
| 1000 | 0 | my $table = Term::Table->new( | |||||||||||||||||||||||||||
| 1001 | collapse => 1, | ||||||||||||||||||||||||||||
| 1002 | header => [ 'Variable', '.SRCINFO', 'Generated', 'Status' ], | ||||||||||||||||||||||||||||
| 1003 | rows => \@rows, | ||||||||||||||||||||||||||||
| 1004 | ); | ||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||
| 1006 | 0 | print STDERR $_, "\n" foreach $table->render; | |||||||||||||||||||||||||||
| 1007 | 0 | $self->_pdbg("\n"); | |||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||
| 1011 | # Preserve the PKGBUILD contributor attributions. | ||||||||||||||||||||||||||||
| 1012 | 0 | my @file_contents; | |||||||||||||||||||||||||||
| 1013 | my @contributors; | ||||||||||||||||||||||||||||
| 1014 | { | ||||||||||||||||||||||||||||
| 1015 | 0 | @file_contents = path( $FILES{outfile} )->lines_utf8( { chomp => 1 } ); | |||||||||||||||||||||||||||
| 1016 | @contributors = | ||||||||||||||||||||||||||||
| 1017 | 0 | grep { /\A \# \s* (?> (?> Co-)?Mai?ntainer | Contributor )\s*:\s*[^\n]+\z/ix } @file_contents; | |||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||
| 1019 | 0 | $self->_pdump( '@file_contents', \@file_contents, "\n" ); | |||||||||||||||||||||||||||
| 1020 | 0 | $self->_pdump( '@contributors', \@contributors, "\n" ); | |||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||
| 1023 | # Set past maintainer/contributor attributions. | ||||||||||||||||||||||||||||
| 1024 | { | ||||||||||||||||||||||||||||
| 1025 | # Whether PACKAGER is the current maintainer. | ||||||||||||||||||||||||||||
| 1026 | 0 | my $has_packager = false; | |||||||||||||||||||||||||||
| 1027 | 0 | ▶ | if ( defined $contributors[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1028 | 0 | ▶ | $has_packager = true | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1029 | if $contributors[0] =~ /\b$env{packager}\z/; | ||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||
| 1032 | 0 | ▶ | $contributors[0] = "# Maintainer: $env{packager}" if $has_packager; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||
| 1034 | 0 | ▶ | if ( !scalar @contributors || !$has_packager ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @contributors and $has_packager
MC/DC0%0/2
scalar @contributors and $has_packager
scalar @contributors
$has_packager
Truth table0%0/3
A and B
A= scalar @contributorsB= $has_packager
| |||||||||||||||||||||||||||||
| 1035 | # Update maintainer anyway. | ||||||||||||||||||||||||||||
| 1036 | 0 | unshift @contributors, "# Maintainer: $env{packager}"; | |||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||
| 1039 | 0 | my $maintainer = shift @contributors; | |||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | # Preserve co-maintainers if PACKAGER is the current maintainer. | ||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | if ($has_packager) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1043 | 0 | my @preserved; | |||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||
| 1045 | 0 | foreach my $contrib (@contributors) { | |||||||||||||||||||||||||||
| 1046 | 0 | ▶ | if ( $contrib =~ s{\A \# \s* (?> Co-)?Mai?ntainer\s*:\s*}{# Maintainer: }ix ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1047 | 0 | push @preserved, $contrib; | |||||||||||||||||||||||||||
| 1048 | 0 | next; | |||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||
| 1050 | 0 | push @preserved, $contrib =~ s{\A[^:]+:\s*}{# Contributor: }r; | |||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||
| 1053 | 0 | @contributors = @preserved; | |||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||
| 1055 | else { | ||||||||||||||||||||||||||||
| 1056 | 0 | @contributors = map { s{\A[^:]+:\s*}{# Contributor: }r } @contributors; | |||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||
| 1059 | 0 | my $attributions = join "\n", $maintainer, @contributors; | |||||||||||||||||||||||||||
| 1060 | 0 | $gen_output =~ s{\A}{$attributions\n\n}; | |||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||
| 1063 | # Bump pkgrel only when pkgver numbers are equal. | ||||||||||||||||||||||||||||
| 1064 | { | ||||||||||||||||||||||||||||
| 1065 | 0 | my $ret = $self->_comp_vers( $srcinfo_meta{pkgver}, $_generated_meta{pkgver}, '==' ); | |||||||||||||||||||||||||||
| 1066 | 0 | ▶ | return 1 if defined $ret && $ret == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ret and $ret == 1
MC/DC0%0/2
defined $ret and $ret == 1
defined $ret
$ret == 1
Truth table0%0/3
A and B
A= defined $retB= $ret == 1
| |||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||
| 1068 | 0 | ▶ | if ( defined $ret && $ret == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ret and $ret == 0
MC/DC0%0/2
defined $ret and $ret == 0
defined $ret
$ret == 0
Truth table0%0/3
A and B
A= defined $retB= $ret == 0
| |||||||||||||||||||||||||||||
| 1069 | 0 | my $pkgrel = ++$srcinfo_meta{pkgrel}; | |||||||||||||||||||||||||||
| 1070 | 0 | $gen_output =~ s{^pkgrel=\K[^\n]+$}{$pkgrel}m; | |||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||
| 1072 | 0 | $self->_pdbg("bump pkgrel to $pkgrel\n\n"); | |||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||
| 1074 | 0 | ▶ | if ( !$is_diff ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1075 | 0 | warn "$prog: $FILES{metadata} is the same as generated metadata;" | |||||||||||||||||||||||||||
| 1076 | . " maybe pkgrel shouldn't have been bumped?\n"; | ||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||
| 1078 | 0 | $self->_pdbg("\n"); | |||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||
| 1080 | } | ||||||||||||||||||||||||||||
| 1081 | } | ||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||
| 1083 | # Preserve epoch | ||||||||||||||||||||||||||||
| 1084 | 0 | ▶ | if ( exists $srcinfo_meta{epoch} && !$has_epoch ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $srcinfo_meta{"epoch"} and not $has_epoch
MC/DC0%0/2
exists $srcinfo_meta{"epoch"} and not $has_epoch
exists $srcinfo_meta{"epoch"}
not $has_epoch
Truth table0%0/3
A and not(B)
A= exists $srcinfo_meta{"epoch"}B= not $has_epoch
| |||||||||||||||||||||||||||||
| 1085 | 0 | $gen_output =~ s{^pkgrel=[^\n]+\n\K}{epoch=$srcinfo_meta{epoch}\n}m; | |||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||
| 1088 | # Update | ||||||||||||||||||||||||||||
| 1089 | { | ||||||||||||||||||||||||||||
| 1090 | 0 | my $file_output = join "\n", @file_contents; | |||||||||||||||||||||||||||
| 1091 | 0 | $file_output .= "\n"; | |||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||
| 1093 | # Avoid writing needlessly. | ||||||||||||||||||||||||||||
| 1094 | 0 | ▶ | if ( $gen_output ne $file_output ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1095 | 0 | path( $FILES{outfile} )->spew_utf8($gen_output); | |||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||
| 1097 | 0 | $self->_pdbg("update $FILES{outfile}\n"); | |||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||
| 1101 | # --write | ||||||||||||||||||||||||||||
| 1102 | elsif ( defined $opts{write} ) { | ||||||||||||||||||||||||||||
| 1103 | 0 | ▶ | if ( -f $FILES{outfile} && !$opts{force} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $FILES{"outfile"} and not $opts{"force"}
MC/DC0%0/2
-f $FILES{"outfile"} and not $opts{"force"}
-f $FILES{"outfile"}
not $opts{"force"}
Truth table0%0/3
A and not(B)
A= -f $FILES{"outfile"}B= not $opts{"force"}
| |||||||||||||||||||||||||||||
| 1104 | 0 | warn "$prog: $FILES{outfile} file exists; use --force to overwrite it\n"; | |||||||||||||||||||||||||||
| 1105 | 0 | return 1; | |||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||
| 1108 | 0 | path( $FILES{outfile} )->spew_utf8( $_pkgbuild{output} ); | |||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||
| 1110 | 0 | $self->_pdbg("write to $FILES{outfile}\n"); | |||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||
| 1112 | else { | ||||||||||||||||||||||||||||
| 1113 | 0 | print $_pkgbuild{output}; | |||||||||||||||||||||||||||
| 1114 | } | ||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||
| 1116 | 0 | return 0; | |||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||
| 1119 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||
| 1121 | =for highlighter language=perl | ||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||
| 1123 | =head1 NAME | ||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||
| 1125 | App::cpan2arch::WritePkgbuild - generate and output PKGBUILD | ||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||
| 1127 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||
| 1129 | use App::cpan2arch; | ||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||
| 1131 | my $cpan2arch = App::cpan2arch->new; | ||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||
| 1133 | ... | ||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||
| 1135 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||
| 1137 | This role handles the generation and output of the C<PKGBUILD> for the module/distribution. | ||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||
| 1139 | =head1 METHODS | ||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||
| 1141 | =head2 generate_pkgbuild | ||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||
| 1143 | $cpan2arch->generate_pkgbuild; | ||||||||||||||||||||||||||||
| 1144 | |||||||||||||||||||||||||||||
| 1145 | Takes no arguments and returns C<self>. | ||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||
| 1147 | =head2 write_pkgbuild | ||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||
| 1149 | $cpan2arch->write_pkgbuild; | ||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||
| 1151 | Takes no arguments and returns C<0> on success. | ||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||
| 1153 | =head2 PKGBUILD EXAMPLE | ||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||
| 1155 | =for highlighter language=bash | ||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||
| 1157 | # Maintainer: Your Name <email@domain.tld> | ||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||
| 1159 | _author=RYOSKZYPU | ||||||||||||||||||||||||||||
| 1160 | _dist=App-cpan2arch | ||||||||||||||||||||||||||||
| 1161 | pkgname=perl-${_dist@L} | ||||||||||||||||||||||||||||
| 1162 | pkgver=v1.0.0 | ||||||||||||||||||||||||||||
| 1163 | pkgrel=1 | ||||||||||||||||||||||||||||
| 1164 | pkgdesc='generate PKGBUILD from CPAN metadata' | ||||||||||||||||||||||||||||
| 1165 | arch=('any') | ||||||||||||||||||||||||||||
| 1166 | url=https://metacpan.org/dist/$_dist | ||||||||||||||||||||||||||||
| 1167 | license=('MIT-0') | ||||||||||||||||||||||||||||
| 1168 | depends=( | ||||||||||||||||||||||||||||
| 1169 | 'perl-archive-tar' | ||||||||||||||||||||||||||||
| 1170 | 'perl-capture-tiny>=0.50' | ||||||||||||||||||||||||||||
| 1171 | 'perl-chi>=0.61' | ||||||||||||||||||||||||||||
| 1172 | 'perl-cpanel-json-xs>=4.40' | ||||||||||||||||||||||||||||
| 1173 | 'perl-devel-checkbin>=0.04' | ||||||||||||||||||||||||||||
| 1174 | 'perl-encode' | ||||||||||||||||||||||||||||
| 1175 | 'perl-encode-locale>=1.05' | ||||||||||||||||||||||||||||
| 1176 | 'perl-io-socket-ssl>=2.098' | ||||||||||||||||||||||||||||
| 1177 | 'perl-list-compare>=0.55' | ||||||||||||||||||||||||||||
| 1178 | 'perl-module-corelist>=5.20260420' | ||||||||||||||||||||||||||||
| 1179 | 'perl-mojo-useragent-cached>=1.25' # Package for Mojo::UserAgent::Cached is missing. | ||||||||||||||||||||||||||||
| 1180 | 'perl-mojolicious' | ||||||||||||||||||||||||||||
| 1181 | 'perl-object-pad>=0.825' | ||||||||||||||||||||||||||||
| 1182 | 'perl-path-tiny>=0.150' | ||||||||||||||||||||||||||||
| 1183 | 'perl-pathtools' | ||||||||||||||||||||||||||||
| 1184 | 'perl-pod-usage' | ||||||||||||||||||||||||||||
| 1185 | 'perl-scalar-list-utils' | ||||||||||||||||||||||||||||
| 1186 | 'perl-software-license>=0.104007' | ||||||||||||||||||||||||||||
| 1187 | 'perl-term-readkey>=2.38' | ||||||||||||||||||||||||||||
| 1188 | 'perl-term-table' | ||||||||||||||||||||||||||||
| 1189 | 'perl-time-piece' | ||||||||||||||||||||||||||||
| 1190 | 'perl-version>=0.9934' | ||||||||||||||||||||||||||||
| 1191 | 'perl>=5.42.0' | ||||||||||||||||||||||||||||
| 1192 | ) | ||||||||||||||||||||||||||||
| 1193 | makedepends=('perl-extutils-makemaker') | ||||||||||||||||||||||||||||
| 1194 | checkdepends=( | ||||||||||||||||||||||||||||
| 1195 | 'perl-capture-tiny>=0.50' | ||||||||||||||||||||||||||||
| 1196 | 'perl-devel-checkbin>=0.04' | ||||||||||||||||||||||||||||
| 1197 | 'perl-path-tiny>=0.150' | ||||||||||||||||||||||||||||
| 1198 | 'perl-test-simple' | ||||||||||||||||||||||||||||
| 1199 | 'perl-text-diff>=1.45' | ||||||||||||||||||||||||||||
| 1200 | ) | ||||||||||||||||||||||||||||
| 1201 | optdepends=( | ||||||||||||||||||||||||||||
| 1202 | 'perl-data-printer>=1.002001' | ||||||||||||||||||||||||||||
| 1203 | 'perl-getopt-long-more>=0.007' # Package for Getopt::Long::More is missing. | ||||||||||||||||||||||||||||
| 1204 | ) | ||||||||||||||||||||||||||||
| 1205 | options=('!emptydirs') | ||||||||||||||||||||||||||||
| 1206 | source=("https://cpan.metacpan.org/authors/id/${_author::1}/${_author::2}/$_author/$_dist-$pkgver.tar.gz") | ||||||||||||||||||||||||||||
| 1207 | sha256sums=('9bdd428eb2afc2f836216ad79afd9ebf2b935201be3067da11044b3b740f096f') | ||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||
| 1209 | build() | ||||||||||||||||||||||||||||
| 1210 | { | ||||||||||||||||||||||||||||
| 1211 | cd "$_dist-$pkgver" | ||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||
| 1213 | unset PERL_MM_OPT PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 1214 | export PERL_MM_USE_DEFAULT=1 | ||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | /usr/bin/perl Makefile.PL NO_PACKLIST=1 NO_PERLLOCAL=1 | ||||||||||||||||||||||||||||
| 1217 | make | ||||||||||||||||||||||||||||
| 1218 | } | ||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||
| 1220 | check() | ||||||||||||||||||||||||||||
| 1221 | { | ||||||||||||||||||||||||||||
| 1222 | cd "$_dist-$pkgver" | ||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||
| 1224 | unset PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||
| 1226 | make test | ||||||||||||||||||||||||||||
| 1227 | } | ||||||||||||||||||||||||||||
| 1228 | |||||||||||||||||||||||||||||
| 1229 | package() | ||||||||||||||||||||||||||||
| 1230 | { | ||||||||||||||||||||||||||||
| 1231 | cd "$_dist-$pkgver" | ||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||
| 1233 | unset PERL5LIB PERL_LOCAL_LIB_ROOT | ||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||
| 1235 | make install INSTALLDIRS=vendor DESTDIR="$pkgdir" | ||||||||||||||||||||||||||||
| 1236 | install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/" | ||||||||||||||||||||||||||||
| 1237 | } | ||||||||||||||||||||||||||||
| 1238 | |||||||||||||||||||||||||||||
| 1239 | =head1 BUGS | ||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||
| 1241 | Report bugs at L<https://github.com/ryoskzypu/App-cpan2arch/issues>. | ||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||
| 1243 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||
| 1245 | ryoskzypu <ryoskzypu@proton.me> | ||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||
| 1247 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||
| 1249 | =over 4 | ||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||
| 1251 | =item * | ||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||
| 1253 | L<https://wiki.archlinux.org/title/Perl_package_guidelines> | ||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||
| 1255 | =item * | ||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||
| 1257 | L<SRCINFO(5)|https://man.archlinux.org/man/SRCINFO.5> | ||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||
| 1259 | =item * | ||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||
| 1261 | L<PKGBUILD(5)|https://man.archlinux.org/man/core/pacman/PKGBUILD.5> | ||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||
| 1263 | =back | ||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||
| 1265 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||
| 1267 | Copyright © 2026 ryoskzypu | ||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||
| 1269 | MIT-0 License. See LICENSE for details. | ||||||||||||||||||||||||||||
| 1270 | |||||||||||||||||||||||||||||
| 1271 | =cut | ||||||||||||||||||||||||||||