| 1 | package Hardware::Vhdl::Automake::CompileTool; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Hardware::Vhdl::Automake::DesignUnit; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use File::Spec::Functions; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | Hardware::Vhdl::Automake::CompileTool - Base class for compilation tool controller | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | my $null = File::Spec::Functions::devnull(); | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 0 | ▶ | sub new { # class or object method, returns a new project object | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 18 | 0 | my $class=shift; | |||||||||||||||||||
| 19 | 0 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 20 | 0 | my $self={ | |||||||||||||||||||
| 21 | toolid => $class, | ||||||||||||||||||||
| 22 | status_callback => undef, | ||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||
| 24 | 0 | bless $self, $class; | |||||||||||||||||||
| 25 | 0 | $self->init(@_); | |||||||||||||||||||
| 26 | 0 | $self; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | sub toolid { $_[0]->{toolid} } | ||||||||||||||||||
|
Subroutine
toolid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | ▶ | sub set_status_callback { | ||||||||||||||||||
|
Subroutine
set_status_callback: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||
| 36 | 0 | $self->{status_callback} = shift; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | ▶ | sub report_status { | ||||||||||||||||||
|
Subroutine
report_status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 40 | 0 | my $self = shift; | |||||||||||||||||||
| 41 | 0 | ▶ | &{$self->{status_callback}}(@_) if defined $self->{status_callback}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub compile_start { | ||||||||||||||||||
|
Subroutine
compile_start: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||
| 46 | 0 | $self->report_status({type => 'compile_start', text => 'Starting compilation'}); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub compile { | ||||||||||||||||||
|
Subroutine
compile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||
| 51 | 0 | my $dunit = shift; | |||||||||||||||||||
| 52 | 0 | $self->report_status({type => 'compile', text => 'Compiling a design unit'}); | |||||||||||||||||||
| 53 | #... | ||||||||||||||||||||
| 54 | 0 | $dunit->set_compile_info($self->{toolid}, { xxx => 123 }); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub compile_finish { | ||||||||||||||||||
|
Subroutine
compile_finish: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||
| 59 | 0 | $self->report_status({type => 'compile_finish', text => 'Finishing compilation'}); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | sub compile_abort { | ||||||||||||||||||
|
Subroutine
compile_abort: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||
| 64 | 0 | $self->report_status({type => 'compile_abort', text => 'Aborting compilation'}); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | sub sys_capture { | ||||||||||||||||||
|
Subroutine
sys_capture: not called CC=21 SCAR=61.4
Pod
undocumented
| |||||||||||||||||||||
| 68 | # taken from Shell.pm by Larry Wall, Jenda@Krynicky.cz, Dave Cottle <d.cottle@csc.canterbury.ac.nz> and Casey West <casey@geeknest.com>. | ||||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||||
| 70 | 0 | my $cmd = shift; | |||||||||||||||||||
| 71 | 0 | my @cmd_args; | |||||||||||||||||||
| 72 | 0 | ▶ | if (ref $cmd eq 'ARRAY') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 0 | @cmd_args = @$cmd; | |||||||||||||||||||
| 74 | 0 | $cmd = shift @cmd_args; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | 0 | my $raw = 0; | |||||||||||||||||||
| 77 | 0 | my $capture_stderr = 1; | |||||||||||||||||||
| 78 | #print join(' ',"\n# Executing command:",$cmd, @cmd_args)."\n"; | ||||||||||||||||||||
| 79 | 0 | ▶ | if ( @cmd_args < 1 ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 80 | 0 | ▶ | $capture_stderr == 1 ? qx/$cmd 2>\&1/ | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 81 | : $capture_stderr == -1 ? qx/$cmd 2>$null/ | ||||||||||||||||||||
| 82 | : qx/$cmd/; | ||||||||||||||||||||
| 83 | } elsif ( $^O eq 'os2' ) { | ||||||||||||||||||||
| 84 | 0 | local ( *SAVEOUT, *READ, *WRITE ); | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | open SAVEOUT, '>&STDOUT' or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | ▶ | pipe READ, WRITE or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | ▶ | open STDOUT, '>&WRITE' or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 0 | close WRITE; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $pid = system( 1, $cmd, @cmd_args ); | |||||||||||||||||||
| 92 | 0 | ▶ | die "Can't execute $cmd: $!\n" if $pid < 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | ▶ | open STDOUT, '>&SAVEOUT' or die; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 0 | close SAVEOUT; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 0 | my @ret = <READ>; | |||||||||||||||||||
| 99 | 0 | close READ; | |||||||||||||||||||
| 100 | 0 | waitpid $pid, 0; | |||||||||||||||||||
| 101 | 0 | @ret; | |||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||
| 103 | 0 | local ($/) = undef; | |||||||||||||||||||
| 104 | 0 | my $ret = <READ>; | |||||||||||||||||||
| 105 | 0 | close READ; | |||||||||||||||||||
| 106 | 0 | waitpid $pid, 0; | |||||||||||||||||||
| 107 | 0 | $ret; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||
| 110 | 0 | my $a; | |||||||||||||||||||
| 111 | 0 | my @arr = @cmd_args; | |||||||||||||||||||
| 112 | 0 | ▶ | unless ($raw) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | 0 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | # XXX this special-casing should not be needed | ||||||||||||||||||||
| 116 | # if we do quoting right on Windows. :-( | ||||||||||||||||||||
| 117 | # | ||||||||||||||||||||
| 118 | # First, escape all quotes. Cover the case where we | ||||||||||||||||||||
| 119 | # want to pass along a quote preceded by a backslash | ||||||||||||||||||||
| 120 | # (i.e., C<"param \""" end">). | ||||||||||||||||||||
| 121 | # Ugly, yup? You know, windoze. | ||||||||||||||||||||
| 122 | # Enclose in quotes only the parameters that need it: | ||||||||||||||||||||
| 123 | # try this: c:> dir "/w" | ||||||||||||||||||||
| 124 | # and this: c:> dir /w | ||||||||||||||||||||
| 125 | 0 | for (@arr) { | |||||||||||||||||||
| 126 | 0 | s/"/\\"/g; | |||||||||||||||||||
| 127 | 0 | s/\\\\"/\\\\"""/g; | |||||||||||||||||||
| 128 | 0 | ▶ | $_ = qq["$_"] if /\s/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | #print "Win32 command: ", join(' ', $cmd, @arr), "\n"; | ||||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||
| 132 | 0 | for (@arr) { | |||||||||||||||||||
| 133 | 0 | s/(['\\])/\\$1/g; | |||||||||||||||||||
| 134 | 0 | $_ = $_; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | 0 | ▶ | push @arr, '2>&1' if $capture_stderr == 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 139 | 0 | ▶ | push @arr, '2>$null' if $capture_stderr == -1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | 0 | ▶ | open( SUBPROC, join( ' ', $cmd, @arr, '|' ) ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | or die "Can't exec $cmd: $!\n"; | ||||||||||||||||||||
| 142 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | 0 | my @ret = <SUBPROC>; | |||||||||||||||||||
| 144 | 0 | close SUBPROC; # XXX Oughta use a destructor. | |||||||||||||||||||
| 145 | 0 | @ret; | |||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||
| 147 | 0 | local ($/) = undef; | |||||||||||||||||||
| 148 | 0 | my $ret = <SUBPROC>; | |||||||||||||||||||
| 149 | 0 | close SUBPROC; | |||||||||||||||||||
| 150 | 0 | $ret; | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | } | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 1 | 1; | |||||||||||||||||||