| 1 | package SPVM::Builder::LinkInfo; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 685 | ▶ | use parent 'SPVM::Builder::CommandInfo'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 685 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 685 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 685 | ▶ | use Config; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 685 | ▶ | use Carp 'confess'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 685 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 685 | ▶ | use SPVM::Builder::Accessor 'has'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | # Fields | ||||||||||||||||||||||
| 13 | 685 | my $field_names = [qw( | |||||||||||||||||||||
| 14 | compile_infos | ||||||||||||||||||||||
| 15 | object_file_infos | ||||||||||||||||||||||
| 16 | dl_func_list | ||||||||||||||||||||||
| 17 | )]; | ||||||||||||||||||||||
| 18 | 685 | has $field_names; | |||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | # Class Methods | ||||||||||||||||||||||
| 21 | 12311 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | 0 | ▶ | my $self = shift->SUPER::new( | ||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||
| 24 | object_file_infos => [], | ||||||||||||||||||||||
| 25 | dl_func_list => [], | ||||||||||||||||||||||
| 26 | @_ | ||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 0 | return $self; | |||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | # Instance Methods | ||||||||||||||||||||||
| 33 | 12311 | ▶ | sub field_names { | ||||||||||||||||||||
|
Subroutine
field_names: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||
| 34 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||
|
Subroutine
field_names: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | 0 | return [@{$self->SUPER::field_names}, @$field_names]; | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 45539 | ▶ | sub create_command { | ||||||||||||||||||||
|
Subroutine
create_command: called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||
| 40 | 0 | ▶ | my ($self, $options) = @_; | ||||||||||||||||||||
|
Subroutine
create_command: not called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 0 | ▶ | $options //= {}; | ||||||||||||||||||||
|
Condition50%2/4
$options //= {}
$options //= {}
MC/DC100%1/1
$options //= {}
$options
MC/DC0%0/1
$options //= {}
$options
Truth table100%2/2
A
A= $options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 0 | my $no_output_option = $options->{no_output_option}; | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 0 | my $config = $self->config; | |||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | 0 | my $ld = $config->ld; | |||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | 0 | my $output_type = $config->output_type; | |||||||||||||||||||||
| 51 | 0 | my $output_file = $config->output_file; | |||||||||||||||||||||
| 52 | 0 | my $object_file_infos = $self->object_file_infos; | |||||||||||||||||||||
| 53 | 0 | my $object_file_names = [map { $_->to_string; } @$object_file_infos]; | |||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | 0 | my @link_command; | |||||||||||||||||||||
| 56 | 0 | ▶ | if ($output_type eq 'static_lib') { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 57 | 0 | my $ar_output_file; | |||||||||||||||||||||
| 58 | 0 | ▶ | if ($no_output_option) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 59 | 0 | $ar_output_file = "__AR_OUTPUT_FILE__"; | |||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||
| 61 | else { | ||||||||||||||||||||||
| 62 | 0 | $ar_output_file = $output_file; | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | 0 | push @link_command, ('ar', 'rcs', $ar_output_file, @$object_file_names); | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||
| 68 | 0 | my $ldflags = $self->create_ldflags; | |||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | # Get output option name | ||||||||||||||||||||||
| 71 | 0 | my $ld_output_option_name = $config->ld_output_option_name; | |||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | # Build command | ||||||||||||||||||||||
| 74 | 0 | push @link_command, ($ld); | |||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | 0 | ▶ | unless ($no_output_option) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 77 | # Build output option | ||||||||||||||||||||||
| 78 | 0 | my $output_option = $config->create_option($ld_output_option_name, $output_file); | |||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | 0 | push @link_command, $output_option; | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | 0 | push @link_command, (@$object_file_names, @$ldflags); | |||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | 0 | return \@link_command; | |||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | 45730 | ▶ | sub create_ldflags { | ||||||||||||||||||||
|
Subroutine
create_ldflags: called CC=8 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||
| 90 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||
|
Subroutine
create_ldflags: not called CC=8 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 0 | my $config = $self->config; | |||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | 0 | my @merged_ldflags; | |||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | 0 | ▶ | if (length $config->ld_optimize) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 97 | 0 | push @merged_ldflags, split(/ +/, $config->ld_optimize); | |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | 0 | my $ldflags = $config->ldflags; | |||||||||||||||||||||
| 101 | 0 | push @merged_ldflags, grep { length $_ } @{$config->ldflags}; | |||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 0 | my $ld_system_field_names = $config->get_ld_system_field_names; | |||||||||||||||||||||
| 104 | 0 | my $output_type = $config->output_type; | |||||||||||||||||||||
| 105 | 0 | for my $ld_system_field_name (@$ld_system_field_names) { | |||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | 0 | my $add; | |||||||||||||||||||||
| 108 | 0 | ▶ | if ($ld_system_field_name =~ /^dynamic_lib_ldflags$/) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 109 | 0 | ▶ | if ($output_type eq 'dynamic_lib') { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 110 | 0 | $add = 1; | |||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||||
| 114 | 0 | $add = 1; | |||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | 0 | ▶ | if ($add) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 118 | 0 | push @merged_ldflags, grep { length $_ } @{$config->$ld_system_field_name}; | |||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | 0 | my $lib_dirs = $config->lib_dirs; | |||||||||||||||||||||
| 123 | push @merged_ldflags, map { | ||||||||||||||||||||||
| 124 | 0 | $config->create_option($config->lib_dir_option_name, SPVM::Builder::Util::quote_literal($_)) | |||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||
| 126 | 0 | grep { length $_ } @$lib_dirs; | |||||||||||||||||||||
| 127 | |||||||||||||||||||||||
| 128 | 0 | my $libs = $config->libs; | |||||||||||||||||||||
| 129 | 0 | my @lib_ldflags; | |||||||||||||||||||||
| 130 | 0 | ▶ | for (my $i = 0; $i < @$libs; $i++) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 131 | 0 | my $lib = $libs->[$i]; | |||||||||||||||||||||
| 132 | 0 | ▶ | $lib = ref $lib ? $lib : SPVM::Builder::LibInfo->new(name => $lib, config => $config); | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 133 | 0 | $libs->[$i] = $lib; | |||||||||||||||||||||
| 134 | 0 | my $lib_ldflags = $lib->create_ldflags; | |||||||||||||||||||||
| 135 | 0 | push @lib_ldflags, @$lib_ldflags; | |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||
| 137 | |||||||||||||||||||||||
| 138 | 0 | push @merged_ldflags, @lib_ldflags; | |||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | 0 | return \@merged_ldflags; | |||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | 685 | 1; | |||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | =head1 Name | ||||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | SPVM::Builder::LinkInfo - Link Information | ||||||||||||||||||||||
| 148 | |||||||||||||||||||||||
| 149 | =head1 Description | ||||||||||||||||||||||
| 150 | |||||||||||||||||||||||
| 151 | SPVM::Builder::LinkInfo class manages information for a link. | ||||||||||||||||||||||
| 152 | |||||||||||||||||||||||
| 153 | =head1 Usage | ||||||||||||||||||||||
| 154 | |||||||||||||||||||||||
| 155 | my $link_info = SPVM::Builder::LinkInfo->new(%fields); | ||||||||||||||||||||||
| 156 | |||||||||||||||||||||||
| 157 | =head1 Super Class | ||||||||||||||||||||||
| 158 | |||||||||||||||||||||||
| 159 | L<SPVM::Builder::CommandInfo> | ||||||||||||||||||||||
| 160 | |||||||||||||||||||||||
| 161 | =head1 Fields | ||||||||||||||||||||||
| 162 | |||||||||||||||||||||||
| 163 | =head2 object_file_infos | ||||||||||||||||||||||
| 164 | |||||||||||||||||||||||
| 165 | my $object_file_infos = $link_info->object_file_infos; | ||||||||||||||||||||||
| 166 | $link_info->object_file_infos($object_file_infos); | ||||||||||||||||||||||
| 167 | |||||||||||||||||||||||
| 168 | Gets and sets the C<object_file_infos> field, an array reference of L<SPVM::Builder::ObjectFileInfo> objects. | ||||||||||||||||||||||
| 169 | |||||||||||||||||||||||
| 170 | =head2 dl_func_list | ||||||||||||||||||||||
| 171 | |||||||||||||||||||||||
| 172 | my $dl_func_list = $link_info->dl_func_list; | ||||||||||||||||||||||
| 173 | $link_info->dl_func_list($dl_func_list); | ||||||||||||||||||||||
| 174 | |||||||||||||||||||||||
| 175 | Gets and sets the C<dl_func_list> field. It is an array reference of function names to be exported from a dynamic library for Windows. | ||||||||||||||||||||||
| 176 | |||||||||||||||||||||||
| 177 | =head1 Class Methods | ||||||||||||||||||||||
| 178 | |||||||||||||||||||||||
| 179 | =head2 new | ||||||||||||||||||||||
| 180 | |||||||||||||||||||||||
| 181 | my $link_info = SPVM::Builder::LinkInfo->new(%fields); | ||||||||||||||||||||||
| 182 | |||||||||||||||||||||||
| 183 | Creates a new C<SPVM::Builder::LinkInfo> object given L</"Fields">, and returns it. | ||||||||||||||||||||||
| 184 | |||||||||||||||||||||||
| 185 | Field Default Values: | ||||||||||||||||||||||
| 186 | |||||||||||||||||||||||
| 187 | =over 2 | ||||||||||||||||||||||
| 188 | |||||||||||||||||||||||
| 189 | =item * L</"object_file_infos"> | ||||||||||||||||||||||
| 190 | |||||||||||||||||||||||
| 191 | [] | ||||||||||||||||||||||
| 192 | |||||||||||||||||||||||
| 193 | =back | ||||||||||||||||||||||
| 194 | |||||||||||||||||||||||
| 195 | Exceptions: | ||||||||||||||||||||||
| 196 | |||||||||||||||||||||||
| 197 | L<"config"|SPVM::Builder::CommandInfo/"config"> field must be defined. | ||||||||||||||||||||||
| 198 | |||||||||||||||||||||||
| 199 | =head1 Instance Methods | ||||||||||||||||||||||
| 200 | |||||||||||||||||||||||
| 201 | =head2 create_command | ||||||||||||||||||||||
| 202 | |||||||||||||||||||||||
| 203 | my $link_command = $link_info->create_command; | ||||||||||||||||||||||
| 204 | my $link_command_no_output = $link_info->create_command({no_output_option => 1}); | ||||||||||||||||||||||
| 205 | |||||||||||||||||||||||
| 206 | Creates an array reference of the link command, and returns it. | ||||||||||||||||||||||
| 207 | |||||||||||||||||||||||
| 208 | If the C<no_output_option> option is a true value, the output option (e.g. C<-o dylib.so>) is not added to the command. | ||||||||||||||||||||||
| 209 | |||||||||||||||||||||||
| 210 | Return Value Examples: | ||||||||||||||||||||||
| 211 | |||||||||||||||||||||||
| 212 | [qw(cc -o dylib.so foo.o bar.o -shared -O2 -Llibdir -lz)] | ||||||||||||||||||||||
| 213 | |||||||||||||||||||||||
| 214 | # With no_output_option => 1 | ||||||||||||||||||||||
| 215 | [qw(cc foo.o bar.o -shared -O2 -Llibdir -lz)] | ||||||||||||||||||||||
| 216 | |||||||||||||||||||||||
| 217 | =head2 create_ldflags | ||||||||||||||||||||||
| 218 | |||||||||||||||||||||||
| 219 | my $ldflags = $link_info->create_ldflags; | ||||||||||||||||||||||
| 220 | |||||||||||||||||||||||
| 221 | Creates an array reference of the linker options, and returns it. | ||||||||||||||||||||||
| 222 | |||||||||||||||||||||||
| 223 | The output file L<"output_file"|SPVM::Builder::CommandInfo/"output_file"> and the object files L</"object_file_infos"> are not contained. | ||||||||||||||||||||||
| 224 | |||||||||||||||||||||||
| 225 | Return Value Examples: | ||||||||||||||||||||||
| 226 | |||||||||||||||||||||||
| 227 | [qw(-shared -O2 -Llibdir -lz)] | ||||||||||||||||||||||
| 228 | |||||||||||||||||||||||
| 229 | =head1 Copyright & License | ||||||||||||||||||||||
| 230 | |||||||||||||||||||||||
| 231 | Copyright (c) 2023 Yuki Kimoto | ||||||||||||||||||||||
| 232 | |||||||||||||||||||||||
| 233 | MIT License | ||||||||||||||||||||||