blib/lib/SPVM/Builder/CommandInfo.pm

filter: Statementstmt 73.9% 34 / 46 Branchbran 25.0% 1 / 4 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 72.7% 8 / 11 Podpod 33.3% 2 / 6 totaltotal 59.7% 46 / 77 CC 7 SCAR 10.3
CC
7
Cov
64%
new
5.5
new
5.5
create_command
2.0
CRAP 2.8
« blib/lib/SPVM/Builder/ScriptInfo.pm ↑ Summary blib/lib/SPVM/BlessedObject.pm »
1 package SPVM::Builder::CommandInfo;
2  
3 770 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 770 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 770 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 770 ▶use SPVM::Builder::Accessor 'has';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 770 ▶use SPVM::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Fields
11 770 my $field_names = [qw(
12 config
13 output_file
14 command_hash
15 start_time
16 end_time
17 tmp_dir
18 process_id
19 diagnostic_message
20 )];
21 770 has $field_names;
22  
23 # Class methods
24 12888 ▶sub new {
Subroutine new: called CC=3 SCAR=17.1
Pod undocumented
25 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=17.1
Pod undocumented
26
27 0 my $self = {
28 @_,
29 };
30
31 0 ▶ bless $self, ref $class || $class;
Condition16%1/6
ref $class || $class
l!l&&r!l&&!r
0128880
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
32
33 0 SPVM::Builder::Util::check_option_names($self, $self->field_names);
34
35 0 ▶ unless ($self->config) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->config) 0 12888 12888
unless ($self->config) 0 0 0
36 0 confess("'config' field must be defined.");
37 }
38
39 # Clone the config to avoid polluting the global configuration
40 # when applying individual build options
41 0 $self->config($self->config->clone);
42
43 0 return $self;
44 }
45  
46 # Instance Methods
47 12888 ▶sub field_names {
Subroutine field_names: called CC=1 SCAR=1.2
Pod undocumented
48 0 ▶ my ($self) = @_;
Subroutine field_names: not called CC=1 SCAR=1.2
Pod undocumented
49
50 0 return $field_names;
51 }
52  
53 0 ▶sub create_command { confess('Not implemented.') }
Subroutine create_command: not called CC=1 SCAR=6.9
Pod documented
54  
55 363720 ▶sub create_command_string {
Subroutine create_command_string: called CC=2 SCAR=6.9
Pod documented
56 363720 my ($self, $options) = @_;
57  
58 363720 my $compile_command = $self->create_command($options);
59
60 363720 my @quoted_parts;
61 363720 for my $part (@$compile_command) {
62 3355498 push @quoted_parts, SPVM::Builder::Util::quote_literal($part);
63 }
64
65 363720 my $compile_command_string = join(' ', @quoted_parts);
66
67 363720 return $compile_command_string;
68 }
69  
70 770 1;
71  
72 =head1 Name
73  
74 SPVM::Builder::CommandInfo - Command Information
75  
76 =head1 Description
77  
78 SPVM::Builder::CommandInfo class manages command information.
79  
80 =head1 Fields
81  
82 =head2 config
83  
84 my $config = $command_info->config;
85 $command_info->config($config);
86  
87 Gets and sets the C<config> field, a L<SPVM::Builder::Config> object.
88  
89 =head2 output_file
90  
91 my $output_file = $command_info->output_file;
92 $command_info->output_file($output_file);
93  
94 Gets and sets the C<output_file> field, an output file.
95  
96 =head2 command_hash
97  
98 my $command_hash = $command_info->command_hash;
99 $command_info->command_hash($command_hash);
100  
101 Gets and sets the C<command_hash> field, a SHA-1 hash string that uniquely identifies the compilation task.
102  
103 This hash ensures the consistency of the compilation. It is generated from the following information:
104  
105 =over 2
106  
107 =item * The compilation command itself.
108  
109 =item * The Command version.
110  
111 =item * The SPVM version-specific headers.
112  
113 =item * The information of the dependent files.
114  
115 =back
116  
117 If any of these change, the hash will change, triggering a re-compilation in the C<ninja> build system.
118  
119 =head2 start_time
120  
121 my $start_time = $command_info->start_time;
122 $command_info->start_time($start_time);
123  
124 Gets and sets the C<start_time> field. It is a Unix timestamp in milliseconds when the command execution started.
125  
126 =head2 end_time
127  
128 my $end_time = $command_info->end_time;
129 $command_info->end_time($end_time);
130  
131 Gets and sets the C<end_time> field. It is a Unix timestamp in milliseconds when the command execution ended.
132  
133 =head2 tmp_dir
134  
135 my $tmp_dir = $command_info->tmp_dir;
136 $command_info->tmp_dir($tmp_dir);
137  
138 Gets and sets the C<tmp_dir> field. It is a directory where the stderr log file and other temporary files of the command are stored.
139  
140 =head2 process_id
141  
142 my $process_id = $command_info->process_id;
143 $command_info->process_id($process_id);
144  
145 Gets and sets the C<process_id> field. It is the process ID of the command.
146  
147 =head2 diagnostic_message
148  
149 my $diagnostic_message = $command_info->diagnostic_message;
150 $command_info->diagnostic_message($diagnostic_message);
151  
152 Gets and sets the C<diagnostic_message> field. It is a diagnostic message output when the command is executed.
153  
154 =head1 Instance Methods
155  
156 =head2 create_command
157  
158 my $command = $command_info->create_command;
159 my $command_no_output = $command_info->create_command({no_output_option => 1});
160  
161 Creates an array reference of the command components, and returns it.
162  
163 If the C<no_output_option> option is a true value, the output option (e.g. C<-o output_file>) is not added to the command.
164  
165 This method is meant to be implemented in child classes.
166  
167 =head2 create_command_string
168  
169 my $command_string = $command_info->create_command_string;
170 my $command_string_no_output = $command_info->create_command_string({no_output_option => 1});
171  
172 Converts the array reference of the command returned by the L</"create_command"> method into a single string that can be executed in a shell (such as C<sh> or C<bash>) or the Windows Command Prompt (C<cmd.exe>).
173  
174 If the C<no_output_option> option is a true value, this option is passed to the L</"create_command"> method, and the output option is not included in the returned string.
175  
176 Each argument is automatically and appropriately quoted only when necessary (e.g., containing spaces or special characters) according to the operating system (OS) to ensure it can be safely executed as a command line.
177  
178 Return Value Examples:
179  
180 =over 2
181  
182 =item * On UNIX/Linux:
183  
184 gcc -c -o foo.o -O2 '-std=c99' -Ipath/include foo.c
185  
186 # With no_output_option => 1
187 gcc -c -O2 '-std=c99' -Ipath/include foo.c
188  
189 =item * On Windows:
190  
191 gcc -c -o foo.o -O2 -std=c99 -Ipath/include foo.c
192  
193 # With no_output_option => 1
194 gcc -c -O2 -std=c99 -Ipath/include foo.c
195  
196 =back
197  
198 =head1 Well Knowned Child Classes
199  
200 =over
201  
202 =item * L<SPVM::Builder::LinkInfo>
203  
204 =item * L<SPVM::Builder::CompileInfo>
205  
206 =back
207  
208 =head1 Copyright & License
209  
210 Copyright (c) 2023 Yuki Kimoto
211  
212 MIT License
« blib/lib/SPVM/Builder/ScriptInfo.pm ↑ Summary blib/lib/SPVM/BlessedObject.pm »