builder/Acme/Parataxis/Builder.pm

filter: Statementstmt 33.9% 53 / 156 Branchbran 2.7% 1 / 36 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 53.8% 14 / 26 Podpod 0.0% 0 / 11 totaltotal 27.0% 68 / 251 CC 31 SCAR 42.3
CC
31
Cov
26%
step_build
240.0
Build_PL
20.0
step_test
12.0
CRAP 69.0
« blib/lib/Acme/Parataxis/Compat.pm ↑ Summary blib/lib/Acme/Parataxis/Error.pm »
1 # Based on Module::Build::Tiny which is copyright (c) 2011 by Leon Timmermans, David Golden.
2 # Module::Build::Tiny is free software; you can redistribute it and/or modify it under
3 # the same terms as the Perl 5 programming language system itself.
4 1 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 class #
8 1 Acme::Parataxis::Builder {
9 1 ▶ use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use ExtUtils::Install qw[pm_to_blib install];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶ use ExtUtils::InstallPaths 0.002;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use File::Basename qw[basename dirname];
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use File::Path qw[mkpath rmtree];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use File::Spec::Functions qw[catfile catdir rel2abs abs2rel splitdir curdir];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use JSON::PP 2 qw[encode_json decode_json];
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Not in CORE
19 1 ▶ use Path::Tiny qw[path];
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use ExtUtils::Helpers 0.028 qw[make_executable split_like_shell detildefy];
Subroutine BEGIN: called CC=1 SCAR=0.0
21 #
22 1 field $action : param //= 'build';
23 1 field $meta : reader = CPAN::Meta->load_file('META.json');
24  
25 # Params to Build script
26 1 field $install_base : param //= '';
27 1 field $installdirs : param //= '';
28 1 field $uninst : param //= 0; # Make more sense to have a ./Build uninstall command but...
29 1 field $install_paths : param //= ExtUtils::InstallPaths->new( dist_name => $meta->name );
30 1 field $verbose : param //= 0;
31 1 field $dry_run : param //= 0;
32 1 field $pureperl : param //= 0;
33 1 field $jobs : param //= 1;
34 1 field $destdir : param //= '';
35 1 field $prefix : param //= '';
36 #
37 1 ▶ ADJUST {
Subroutine __ANON__: called CC=2 SCAR=7.6
38 1 ▶ -e 'META.json' or die "No META information provided\n";
Branch: 1 branch
BranchTrueFalseTotal
-e "META.json" or die "No META information provided\n" 1 0 1
39 }
40 0 ▶ method write_file( $filename, $content ) { path($filename)->spew_raw($content) or die "Could not open $filename: $!\n" }
Subroutine write_file: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
path($filename)->spew_raw($content) or die "Could not open ${filename}: $!\n" 0 0 0
41 0 ▶ method read_file ($filename) { path($filename)->slurp_utf8 or die "Could not open $filename: $!\n" }
Subroutine read_file: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
path($filename)->slurp_utf8 or die "Could not open ${filename}: $!\n" 0 0 0
42  
43 0 ▶ method step_build() {
Subroutine step_build: not called CC=15 SCAR=54.8
Pod undocumented
44 0 for my $pl_file ( find( qr/\.PL$/, 'lib' ) ) {
45 0 ( my $pm = $pl_file ) =~ s/\.PL$//;
46 0 ▶ system $^X, $pl_file->stringify, $pm and die "$pl_file returned $?\n";
Branch: 1 branch
BranchTrueFalseTotal
system $^X, $pl_file->stringify, $pm and die "$pl_file returned $?\n" 0 0 0
47 }
48  
49 # C Extension Compilation - removed conditional block
50 0 say 'Building libparataxis...';
51 0 require Affix::Build; # This module is used for C compilation
52 0 require Config;
53 0 require File::Spec;
54 0 my $arch_dir = catdir(qw[blib arch auto Acme Parataxis]);
55 0 mkpath( $arch_dir, $verbose );
56 0 ▶ my @extra_cflags = ( '-fno-lto', ( $^O eq 'openbsd' ? '-fno-ret-protector' : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'openbsd' ? : 0 0 0
57 0 my @extra_ldflags;
58  
59 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
elsif ($^O eq 'darwin') { } 0 0 0
60 push @extra_ldflags, '-L' . File::Spec->catdir( $Config::Config{archlibexp}, 'CORE' ),
61 0 '-l' . ( $Config::Config{libperl} =~ s/^lib//r =~ s/\.a$//r =~ s/\.lib$//r ), '-lws2_32';
62 }
63 elsif ( $^O eq 'darwin' ) {
64 0 push @extra_ldflags, '-undefined dynamic_lookup';
65 }
66 else {
67 0 ▶ push @extra_ldflags, '-Wl,-z,nobtcfi' if $^O eq 'openbsd';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "openbsd" 0 0 0
68 #
69 # Affix builds the library with perl's compiler but does not add perl's own link flags. A perl built with
70 # -Duseshrplib keeps its API in libperl.so, so where a linkable libperl is present the DSO should record
71 # that dependency explicitly (Bionic is especially unforgiving about unresolved data symbols). Termux is
72 # the smoker case; carry its ldflags too so -L/-rpath and its extra libraries are present.
73 0 ▶ if ( $Config::Config{useshrplib} && $Config::Config{useshrplib} ne 'false' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Config{"useshrplib"} and $Config::Config{"useshrplib"} ne "false") 0 0 0
Condition0%0/3
$Config::Config{"useshrplib"} and $Config::Config{"useshrplib"} ne "false"
!ll&&!rl&&r
000
MC/DC0%0/2
$Config::Config{"useshrplib"} and $Config::Config{"useshrplib"} ne "false"
$Config::Config{"useshrplib"} $Config::Config{"useshrplib"} ne "false"
Truth table0%0/3
A and B
A= $Config::Config{"useshrplib"}B= $Config::Config{"useshrplib"} ne "false"
ABresult
0X0
100
111
74 0 my $core = File::Spec->catdir( $Config::Config{archlibexp}, 'CORE' );
75 0 push @extra_ldflags, "-L$core", "-Wl,-rpath,$core";
76 0 ▶ push @extra_ldflags, grep {length} split ' ', ( $Config::Config{ldflags} // '' ) if $^O eq 'android';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "android" 0 0 0
Condition0%0/2
$Config::Config{"ldflags"} // ""
l!l
00
MC/DC0%0/1
$Config::Config{"ldflags"} // ""
$Config::Config{"ldflags"}
Truth table0%0/2
A
A= $Config::Config{"ldflags"}
Aresult
11
00
77  
78 # Only pass -lperl when the linker can actually find an unversioned libperl in CORE. Debian's perl-base
79 # ships just the versioned libperl.so.5.xx runtime object (the unversioned symlink lives in libperl-dev),
80 # so -lperl fails there even though the loader resolves every Perl API symbol from the libperl the perl
81 # executable already loaded ...exactly how ordinary XS extensions build and run on that system. Cygwin's
82 # import library is libperl.dll.a; Termux and most Unix perls have libperl.so or libperl.a.
83 0 ▶ push @extra_ldflags, '-lperl' if grep { -e File::Spec->catfile( $core, $_ ) } qw[libperl.so libperl.a libperl.dylib libperl.dll.a];
Branch: 1 branch
BranchTrueFalseTotal
if grep {-e "File::Spec"->catfile($core, $_);} "libperl.so", "libperl.a", "libperl.dylib", "libperl.dll.a" 0 0 0
84 }
85 }
86  
87 # Escape hatch for platform triage in CI (e.g. -mno-retpoline on OpenBSD). Keep these out of normal builds;
88 # the shipped flags above are the ones we support.
89 0 ▶ push @extra_cflags, grep {length} split ' ', ( $ENV{PARATAXIS_EXTRA_CFLAGS} // '' );
Condition0%0/2
$ENV{"PARATAXIS_EXTRA_CFLAGS"} // ""
l!l
00
MC/DC0%0/1
$ENV{"PARATAXIS_EXTRA_CFLAGS"} // ""
$ENV{"PARATAXIS_EXTRA_CFLAGS"}
Truth table0%0/2
A
A= $ENV{"PARATAXIS_EXTRA_CFLAGS"}
Aresult
11
00
90 0 ▶ push @extra_ldflags, grep {length} split ' ', ( $ENV{PARATAXIS_EXTRA_LDFLAGS} // '' );
Condition0%0/2
$ENV{"PARATAXIS_EXTRA_LDFLAGS"} // ""
l!l
00
MC/DC0%0/1
$ENV{"PARATAXIS_EXTRA_LDFLAGS"} // ""
$ENV{"PARATAXIS_EXTRA_LDFLAGS"}
Truth table0%0/2
A
A= $ENV{"PARATAXIS_EXTRA_LDFLAGS"}
Aresult
11
00
91 0 my $extra_cflags = join ' ', @extra_cflags;
92 0 my $extra_ldflags = join ' ', @extra_ldflags;
93 my $build = Affix::Build->new(
94 name => 'parataxis',
95 flags => {
96 cflags => join(
97 ' ', (
98 $Config::Config{ccflags}, '-std=c11',
99 0 $extra_cflags, map { '-I' . $_ } ( File::Spec->catdir( $Config::Config{archlibexp}, 'CORE' ), 'src' )
100 )
101 ),
102 ldflags => $extra_ldflags
103 },
104 build_dir => $arch_dir,
105 clean => 0
106 );
107  
108 # Add the C source file to be compiled. It's expected to be in 'lib/Acme/'
109 0 $build->add('lib/Acme/Parataxis.c');
110 0 say "Compiling and linking...";
111 0 $build->compile_and_link();
112 0 say "Build complete.";
113 0 my %modules = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pm$/, 'lib' );
114 0 my %docs = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pod$/, 'lib' );
115 0 my %scripts = map { $_ => catfile( 'blib', $_ ) } find( qr/(?:)/, 'script' );
116 0 my %sdocs = map { $_ => delete $scripts{$_} } grep {/.pod$/} keys %scripts;
117 0 pm_to_blib( { %modules, %docs, %sdocs }, catdir(qw[blib lib auto]) );
118 #
119 0 mkpath( catdir(qw[blib script]), $verbose );
120 0 for my $src ( keys %scripts ) {
121 0 my $dest = $scripts{$src};
122 0 my $content = path($src)->slurp_raw;
123 0 $content =~ s{^#!.*perl.*}{#!$^X};
124 0 path($dest)->spew_raw($content);
125 0 make_executable($dest);
126 }
127 #
128 0 my %dist_shared = map { $_ => catfile( qw[blib lib auto share dist], $meta->name, abs2rel( $_, 'share' ) ) } find( qr/(?:)/, 'share' );
129 0 my %module_shared = map { $_ => catfile( qw[blib lib auto share module], abs2rel( $_, 'module-share' ) ) } find( qr/(?:)/, 'module-share' );
130 0 pm_to_blib( { %dist_shared, %module_shared }, catdir(qw[blib lib auto]) );
131 0 mkpath( catdir(qw[blib arch]), $verbose );
132 0 0;
133 }
134 0 ▶ method step_clean() { rmtree( $_, $verbose ) for qw[blib temp]; 0 }
Subroutine step_clean: not called CC=2 SCAR=17.9
Pod undocumented
135  
136 0 ▶ method step_install() {
Subroutine step_install: not called CC=2 SCAR=17.9
Pod undocumented
137 0 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
138 0 install(
139 [ from_to => $install_paths->install_map,
140 verbose => $verbose,
141 dry_run => $dry_run,
142 uninstall_shadows => $uninst,
143 skip => undef,
144 always_copy => 1
145 ]
146 );
147 0 0;
148 }
149 0 ▶ method step_realclean () { rmtree( $_, $verbose ) for qw[blib temp Build _build_params MYMETA.yml MYMETA.json]; 0 }
Subroutine step_realclean: not called CC=2 SCAR=17.9
Pod undocumented
150  
151 0 ▶ method step_test() {
Subroutine step_test: not called CC=3 SCAR=24.8
Pod undocumented
152 0 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
153 0 require TAP::Harness::Env;
154 0 require Config;
155 0 my @libs = map { rel2abs( catdir( 'blib', $_ ) ) } qw[arch lib];
156 0 ▶ local $ENV{PERL5LIB} = join( $Config::Config{path_sep}, @libs, ( defined $ENV{PERL5LIB} ? $ENV{PERL5LIB} : () ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL5LIB'} ? : 0 0 0
157 0 my %test_args = ( ( verbosity => $verbose ), ( jobs => $jobs ), ( color => -t STDOUT ), lib => [@libs] );
158 0 TAP::Harness::Env->create( \%test_args )->runtests( sort map { $_->stringify } find( qr/\.t$/, 't' ) )->has_errors;
159 }
160  
161 0 ▶ method get_arguments (@sources) {
Subroutine get_arguments: not called CC=2 SCAR=17.9
Pod undocumented
162 0 $_ = detildefy($_) for grep {defined} $install_base, $destdir, $prefix, values %{$install_paths};
163 0 $install_paths = ExtUtils::InstallPaths->new( dist_name => $meta->name );
164 0 return;
165 }
166  
167 0 ▶ method Build(@args) {
Subroutine Build: not called CC=2 SCAR=17.9
Pod undocumented
168 0 my $method = $self->can( 'step_' . $action );
169 0 ▶ $method // die "No such action '$action'\n";
Condition0%0/2
$method // die("No such action '${action}'\n")
l!l
00
MC/DC0%0/1
$method // die("No such action '${action}'\n")
$method
Truth table0%0/2
A
A= $method
Aresult
11
00
170 0 exit $method->($self);
171 }
172  
173 0 ▶ method Build_PL() {
Subroutine Build_PL: not called CC=4 SCAR=30.0
Pod undocumented
174 0 say sprintf 'Creating new Build script for %s %s', $meta->name, $meta->version;
175 0 $self->write_file( 'Build', sprintf <<'', $^X, __PACKAGE__, __PACKAGE__ );
176 #!%s
177 use lib 'builder';
178 use %s;
179 use Getopt::Long qw[GetOptionsFromArray];
180 my %%opts = ( @ARGV && $ARGV[0] =~ /\A\w+\z/ ? ( action => shift @ARGV ) : () );
181 GetOptionsFromArray \@ARGV, \%%opts, qw[install_base=s install_path=s%% installdirs=s destdir=s prefix=s config=s%% uninst:1 verbose:1 dry_run:1 jobs=i];
182 %s->new(%%opts)->Build();
183  
184 0 make_executable('Build');
185 0 ▶ my @env = defined $ENV{PERL_MB_OPT} ? split_like_shell( $ENV{PERL_MB_OPT} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL_MB_OPT'} ? : 0 0 0
186 0 $self->write_file( '_build_params', encode_json( [ \@env, \@ARGV ] ) );
187 0 ▶ if ( my $dynamic = $meta->custom('x_dynamic_prereqs') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dynamic = $meta->custom("x_dynamic_prereqs")) 0 0 0
188 0 my %meta = ( %{ $meta->as_struct }, dynamic_config => 0 );
189 0 $self->get_arguments( \@env, \@ARGV );
190 0 require CPAN::Requirements::Dynamic;
191 0 my $dynamic_parser = CPAN::Requirements::Dynamic->new();
192 0 my $prereq = $dynamic_parser->evaluate($dynamic);
193 0 $meta{prereqs} = $meta->effective_prereqs->with_merged_prereqs($prereq)->as_string_hash;
194 0 $meta = CPAN::Meta->new( \%meta );
195 }
196 0 $meta->save(@$_) for ['MYMETA.json'];
197 }
198  
199 0 ▶ sub find ( $pattern, $base ) {
Subroutine find: not called CC=2 SCAR=17.9
Pod undocumented
200 0 ▶ $base = path($base) unless builtin::blessed $base;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($base) 0 0 0
201 my $blah = $base->visit(
202 0 ▶ sub ( $path, $state ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
203 0 ▶ $state->{$path} = $path if -f $path && $path =~ $pattern;
Branch: 1 branch
BranchTrueFalseTotal
if -f $path and $path =~ /$pattern/u 0 0 0
Condition0%0/3
-f $path and $path =~ /$pattern/u
!ll&&!rl&&r
000
MC/DC0%0/2
-f $path and $path =~ /$pattern/u
-f $path $path =~ /$pattern/u
Truth table0%0/3
A and B
A= -f $pathB= $path =~ /$pattern/u
ABresult
0X0
100
111
204  
205 #~ return \0 if keys %$state == 10;
206 },
207 0 { recurse => 1 }
208 );
209 0 values %$blah;
210 }
211 };
212 1 1;
« blib/lib/Acme/Parataxis/Compat.pm ↑ Summary blib/lib/Acme/Parataxis/Error.pm »