builder/Acme/Parataxis/Builder.pm

filter: Statementstmt 34.1% 53 / 155 Branchbran 2.9% 1 / 34 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 53.8% 14 / 26 Podpod 0.0% 0 / 11 totaltotal 27.4% 68 / 248 CC 30 SCAR 40.7
CC
30
Cov
27%
step_build
210.0
Build_PL
20.0
step_test
12.0
CRAP 58.3
« 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=14 SCAR=53.5
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 the DSO must record that dependency explicitly or dlopen()
71 # fails at load time (Bionic is especially unforgiving about unresolved data symbols). Termux is the smoker
72 # 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 0 push @extra_ldflags, '-lperl';
78 }
79 }
80  
81 #~ Escape hatch for platform triage in CI (e.g. -mno-retpoline on OpenBSD). Keep these out of normal builds;
82 #~ the shipped flags above are the ones we support.
83 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
84 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
85 0 my $extra_cflags = join ' ', @extra_cflags;
86 0 my $extra_ldflags = join ' ', @extra_ldflags;
87 my $build = Affix::Build->new(
88 name => 'parataxis',
89 flags => {
90 cflags => join(
91 ' ', (
92 $Config::Config{ccflags}, '-std=c11',
93 0 $extra_cflags, map { '-I' . $_ } ( File::Spec->catdir( $Config::Config{archlibexp}, 'CORE' ), 'src' )
94 )
95 ),
96 ldflags => $extra_ldflags
97 },
98 build_dir => $arch_dir,
99 clean => 0
100 );
101  
102 # Add the C source file to be compiled. It's expected to be in 'lib/Acme/'
103 0 $build->add('lib/Acme/Parataxis.c');
104 0 say "Compiling and linking...";
105 0 $build->compile_and_link();
106 0 say "Build complete.";
107 0 my %modules = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pm$/, 'lib' );
108 0 my %docs = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pod$/, 'lib' );
109 0 my %scripts = map { $_ => catfile( 'blib', $_ ) } find( qr/(?:)/, 'script' );
110 0 my %sdocs = map { $_ => delete $scripts{$_} } grep {/.pod$/} keys %scripts;
111 0 pm_to_blib( { %modules, %docs, %sdocs }, catdir(qw[blib lib auto]) );
112 #
113 0 mkpath( catdir(qw[blib script]), $verbose );
114 0 for my $src ( keys %scripts ) {
115 0 my $dest = $scripts{$src};
116 0 my $content = path($src)->slurp_raw;
117 0 $content =~ s{^#!.*perl.*}{#!$^X};
118 0 path($dest)->spew_raw($content);
119 0 make_executable($dest);
120 }
121 #
122 0 my %dist_shared = map { $_ => catfile( qw[blib lib auto share dist], $meta->name, abs2rel( $_, 'share' ) ) } find( qr/(?:)/, 'share' );
123 0 my %module_shared = map { $_ => catfile( qw[blib lib auto share module], abs2rel( $_, 'module-share' ) ) } find( qr/(?:)/, 'module-share' );
124 0 pm_to_blib( { %dist_shared, %module_shared }, catdir(qw[blib lib auto]) );
125 0 mkpath( catdir(qw[blib arch]), $verbose );
126 0 0;
127 }
128 0 ▶ method step_clean() { rmtree( $_, $verbose ) for qw[blib temp]; 0 }
Subroutine step_clean: not called CC=2 SCAR=17.9
Pod undocumented
129  
130 0 ▶ method step_install() {
Subroutine step_install: not called CC=2 SCAR=17.9
Pod undocumented
131 0 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
132 0 install(
133 [ from_to => $install_paths->install_map,
134 verbose => $verbose,
135 dry_run => $dry_run,
136 uninstall_shadows => $uninst,
137 skip => undef,
138 always_copy => 1
139 ]
140 );
141 0 0;
142 }
143 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
144  
145 0 ▶ method step_test() {
Subroutine step_test: not called CC=3 SCAR=24.8
Pod undocumented
146 0 ▶ $self->step_build() unless -d 'blib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "blib" 0 0 0
147 0 require TAP::Harness::Env;
148 0 require Config;
149 0 my @libs = map { rel2abs( catdir( 'blib', $_ ) ) } qw[arch lib];
150 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
151 0 my %test_args = ( ( verbosity => $verbose ), ( jobs => $jobs ), ( color => -t STDOUT ), lib => [@libs] );
152 0 TAP::Harness::Env->create( \%test_args )->runtests( sort map { $_->stringify } find( qr/\.t$/, 't' ) )->has_errors;
153 }
154  
155 0 ▶ method get_arguments (@sources) {
Subroutine get_arguments: not called CC=2 SCAR=17.9
Pod undocumented
156 0 $_ = detildefy($_) for grep {defined} $install_base, $destdir, $prefix, values %{$install_paths};
157 0 $install_paths = ExtUtils::InstallPaths->new( dist_name => $meta->name );
158 0 return;
159 }
160  
161 0 ▶ method Build(@args) {
Subroutine Build: not called CC=2 SCAR=17.9
Pod undocumented
162 0 my $method = $self->can( 'step_' . $action );
163 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
164 0 exit $method->($self);
165 }
166  
167 0 ▶ method Build_PL() {
Subroutine Build_PL: not called CC=4 SCAR=30.0
Pod undocumented
168 0 say sprintf 'Creating new Build script for %s %s', $meta->name, $meta->version;
169 0 $self->write_file( 'Build', sprintf <<'', $^X, __PACKAGE__, __PACKAGE__ );
170 #!%s
171 use lib 'builder';
172 use %s;
173 use Getopt::Long qw[GetOptionsFromArray];
174 my %%opts = ( @ARGV && $ARGV[0] =~ /\A\w+\z/ ? ( action => shift @ARGV ) : () );
175 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];
176 %s->new(%%opts)->Build();
177  
178 0 make_executable('Build');
179 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
180 0 $self->write_file( '_build_params', encode_json( [ \@env, \@ARGV ] ) );
181 0 ▶ if ( my $dynamic = $meta->custom('x_dynamic_prereqs') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dynamic = $meta->custom("x_dynamic_prereqs")) 0 0 0
182 0 my %meta = ( %{ $meta->as_struct }, dynamic_config => 0 );
183 0 $self->get_arguments( \@env, \@ARGV );
184 0 require CPAN::Requirements::Dynamic;
185 0 my $dynamic_parser = CPAN::Requirements::Dynamic->new();
186 0 my $prereq = $dynamic_parser->evaluate($dynamic);
187 0 $meta{prereqs} = $meta->effective_prereqs->with_merged_prereqs($prereq)->as_string_hash;
188 0 $meta = CPAN::Meta->new( \%meta );
189 }
190 0 $meta->save(@$_) for ['MYMETA.json'];
191 }
192  
193 0 ▶ sub find ( $pattern, $base ) {
Subroutine find: not called CC=2 SCAR=17.9
Pod undocumented
194 0 ▶ $base = path($base) unless builtin::blessed $base;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($base) 0 0 0
195 my $blah = $base->visit(
196 0 ▶ sub ( $path, $state ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
197 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
198  
199 #~ return \0 if keys %$state == 10;
200 },
201 0 { recurse => 1 }
202 );
203 0 values %$blah;
204 }
205 };
206 1 1;
« blib/lib/Acme/Parataxis/Compat.pm ↑ Summary blib/lib/Acme/Parataxis/Error.pm »