| 1 | # Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||||||||||||||||||||||
| 2 | # contributor license agreements. See the NOTICE file distributed with | ||||||||||||||||||||||||||||
| 3 | # this work for additional information regarding copyright ownership. | ||||||||||||||||||||||||||||
| 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 | ||||||||||||||||||||||||||||
| 5 | # (the "License"); you may not use this file except in compliance with | ||||||||||||||||||||||||||||
| 6 | # the License. You may obtain a copy of the License at | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||
| 13 | # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||
| 14 | # limitations under the License. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package Clownfish::CFC::Perl::Build::Charmonic; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use base qw( Module::Build ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||
| 24 | 2 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Cwd qw( getcwd ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use File::Spec::Functions qw( catfile curdir ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Add a custom Module::Build hashref property to pass the following build | ||||||||||||||||||||||||||||
| 32 | # parameters. | ||||||||||||||||||||||||||||
| 33 | # charmonizer_c: Charmonizer C file, required | ||||||||||||||||||||||||||||
| 34 | # create_makefile: Whether to create a Makefile. | ||||||||||||||||||||||||||||
| 35 | # make_options: Options passed to make. | ||||||||||||||||||||||||||||
| 36 | 2 | ▶ | if ( $Module::Build::VERSION <= 0.30 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | __PACKAGE__->add_property( charmonizer_params => {} ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||
| 40 | 2 | __PACKAGE__->add_property( | |||||||||||||||||||||||||||
| 41 | 'charmonizer_params', | ||||||||||||||||||||||||||||
| 42 | default => {}, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | my $CHARMONIZER_EXE_PATH = catfile( curdir(), "charmonizer$Config{_exe}" ); | |||||||||||||||||||||||||||
| 47 | 2 | my $CHARMONY_H_PATH = 'charmony.h'; | |||||||||||||||||||||||||||
| 48 | 2 | my $CHARMONY_PM_PATH = 'Charmony.pm'; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Compile and run the charmonizer executable, creating the charmony.h and | ||||||||||||||||||||||||||||
| 51 | # Charmony.pm files. | ||||||||||||||||||||||||||||
| 52 | 1 | ▶ | sub ACTION_charmony { | ||||||||||||||||||||||||||
|
Subroutine
ACTION_charmony: called CC=16 SCAR=34.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Charmonizer doesn't support fat binaries on macOS. | ||||||||||||||||||||||||||||
| 56 | 1 | for my $key (qw( ccflags ldflags lddlflags )) { | |||||||||||||||||||||||||||
| 57 | 3 | my $flags = $self->config($key); | |||||||||||||||||||||||||||
| 58 | 3 | $flags =~ s/-arch \w+\s*//g; | |||||||||||||||||||||||||||
| 59 | 3 | $self->config( $key => $flags ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | my $cc = $self->config('cc'); | |||||||||||||||||||||||||||
| 63 | 1 | my $is_msvc = lc($cc) =~ /^cl\b/; | |||||||||||||||||||||||||||
| 64 | 1 | my $charmonizer_c = $self->charmonizer_params('charmonizer_c'); | |||||||||||||||||||||||||||
| 65 | 1 | my $create_makefile = $self->charmonizer_params('create_makefile'); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | $self->add_to_cleanup($CHARMONIZER_EXE_PATH); | |||||||||||||||||||||||||||
| 68 | 1 | ▶ | if ( !$self->up_to_date( $charmonizer_c, $CHARMONIZER_EXE_PATH ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 1 | print "\nCompiling $CHARMONIZER_EXE_PATH...\n\n"; | |||||||||||||||||||||||||||
| 70 | 1 | my @command = ( $self->split_like_shell($cc), $charmonizer_c ); | |||||||||||||||||||||||||||
| 71 | 1 | ▶ | if ($is_msvc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | push @command, "/Fe$CHARMONIZER_EXE_PATH"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||
| 75 | 1 | push @command, '-o', $CHARMONIZER_EXE_PATH; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | system @command | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | and die "Failed to compile $CHARMONIZER_EXE_PATH"; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | my @derived_files = ( $CHARMONY_H_PATH, $CHARMONY_PM_PATH ); | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | push @derived_files, 'Makefile' if $create_makefile; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | return if $self->up_to_date( $CHARMONIZER_EXE_PATH, \@derived_files ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | print "\nRunning $CHARMONIZER_EXE_PATH...\n\n"; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | $self->add_to_cleanup($CHARMONY_H_PATH); | |||||||||||||||||||||||||||
| 87 | 1 | $self->add_to_cleanup($CHARMONY_PM_PATH); | |||||||||||||||||||||||||||
| 88 | # Clean up after charmonizer if it doesn't succeed on its own. | ||||||||||||||||||||||||||||
| 89 | 1 | $self->add_to_cleanup("_charm*"); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | ▶ | if ($is_msvc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | $self->add_to_cleanup('charmonizer.obj'); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Prepare arguments to charmonizer. | ||||||||||||||||||||||||||||
| 96 | 1 | my @command = ( | |||||||||||||||||||||||||||
| 97 | $CHARMONIZER_EXE_PATH, | ||||||||||||||||||||||||||||
| 98 | "--cc=$cc", # May contain spaces and args. | ||||||||||||||||||||||||||||
| 99 | '--host=perl', | ||||||||||||||||||||||||||||
| 100 | '--enable-c', | ||||||||||||||||||||||||||||
| 101 | '--enable-perl', | ||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | if ($create_makefile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | push @command, | |||||||||||||||||||||||||||
| 105 | '--make=' . $self->config('make'), | ||||||||||||||||||||||||||||
| 106 | '--enable-makefile'; | ||||||||||||||||||||||||||||
| 107 | 0 | $self->add_to_cleanup('Makefile'); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | # Perl 5.8.7 added support for CLONE_SKIP. | ||||||||||||||||||||||||||||
| 110 | # Thread support in 5.10.0 seems completely broken (CLOWNFISH-107). | ||||||||||||||||||||||||||||
| 111 | # We also got some mysterious, thread-related CPAN Testers failures with | ||||||||||||||||||||||||||||
| 112 | # several 5.8 releases, so disable thread support for 5.10.0 and earlier. | ||||||||||||||||||||||||||||
| 113 | 1 | ▶ | if ( !$self->config('usethreads') || $^V le v5.10.0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->config("usethreads") or $^V le v5.10.0
MC/DC0%0/2
not $self->config("usethreads") or $^V le v5.10.0
not $self->config("usethreads")
$^V le v5.10.0
Truth table33%1/3
not(A) or B
A= not $self->config("usethreads")B= $^V le v5.10.0
| |||||||||||||||||||||||||||||
| 114 | 1 | push @command, '--disable-threads'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | 1 | push @command, ( | |||||||||||||||||||||||||||
| 117 | '--', $self->config('ccflags'), | ||||||||||||||||||||||||||||
| 118 | '-I' . File::Spec->catdir($self->config('archlibexp'), 'CORE'), | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | 1 | ▶ | if ( $ENV{CFISH_EXTRA_CFLAGS} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | push @command, $self->split_like_shell( $ENV{CFISH_EXTRA_CFLAGS} ); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 1 | ▶ | if ( $ENV{CHARM_VALGRIND} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | unshift @command, "valgrind", "--leak-check=yes"; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 1 | print join( " ", @command ), $/; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 1 | ▶ | if ( system(@command) != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | warn "Failed to run $CHARMONIZER_EXE_PATH: $!\n"; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ( ( $ENV{CHARM_VERBOSITY} || 0 ) < 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ENV{'CHARM_VERBOSITY'} || 0
MC/DC0%0/1
$ENV{'CHARM_VERBOSITY'} || 0
$ENV{'CHARM_VERBOSITY'}
Truth table0%0/2
A
A= $ENV{'CHARM_VERBOSITY'}
| |||||||||||||||||||||||||||||
| 132 | 0 | print "Rerunning $CHARMONIZER_EXE_PATH with CHARM_VERBOSITY=2\n\n"; | |||||||||||||||||||||||||||
| 133 | 0 | $ENV{CHARM_VERBOSITY} = 2; | |||||||||||||||||||||||||||
| 134 | 0 | system(@command); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | die "Aborted"; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | my $config; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | ▶ | sub charmony { | ||||||||||||||||||||||||||
|
Subroutine
charmony: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 1 | my ( undef, $key ) = @_; | |||||||||||||||||||||||||||
| 145 | 1 | ▶ | if (!$config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 1 | local @INC = ( @INC, '.' ); | |||||||||||||||||||||||||||
| 147 | 1 | eval { require 'Charmony.pm'; }; | |||||||||||||||||||||||||||
| 148 | 1 | ▶ | if ( !$@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 1 | $config = Charmony->config; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 1 | ▶ | if ($config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 1 | return $config->{$key}; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 0 | return; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub cf_make_objects { | ||||||||||||||||||||||||||
|
Subroutine
cf_make_objects: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 159 | 0 | my ( $self, $target ) = @_; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return [] unless $self->charmonizer_params('create_makefile'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | $self->_cf_charm_run_make(lc($target)); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | return [ split( /\s+/, $self->charmony(uc($target)) ) ]; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub cf_make_clean { | ||||||||||||||||||||||||||
|
Subroutine
cf_make_clean: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | return unless $self->charmonizer_params('create_makefile') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->charmonizer_params("create_makefile") and -e "Makefile"
MC/DC0%0/2
$self->charmonizer_params("create_makefile") and -e "Makefile"
$self->charmonizer_params("create_makefile")
-e "Makefile"
Truth table0%0/3
A and B
A= $self->charmonizer_params("create_makefile")B= -e "Makefile"
| |||||||||||||||||||||||||||||
| 172 | && -e 'Makefile'; | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | $self->_cf_charm_run_make('clean'); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub _cf_charm_run_make { | ||||||||||||||||||||||||||
|
Subroutine
_cf_charm_run_make: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 178 | 0 | my ( $self, $target ) = @_; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my $make_options = $self->charmonizer_params('make_options'); | |||||||||||||||||||||||||||
| 181 | 0 | my @command = ( | |||||||||||||||||||||||||||
| 182 | $self->config('make'), | ||||||||||||||||||||||||||||
| 183 | $self->split_like_shell($make_options), | ||||||||||||||||||||||||||||
| 184 | $target, | ||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||
| 186 | 0 | print join(' ', @command), "\n"; | |||||||||||||||||||||||||||
| 187 | 0 | ▶ | system @command and die($self->config('make') . " failed"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 2 | 1; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | __END__ | ||||||||||||||||||||||||||||