Ticket #359: tt359-pbc_uuid.patch
| File tt359-pbc_uuid.patch, 9.3 KB (added by rurban, 4 years ago) |
|---|
-
lib/Parrot/BuildUtil.pm
old new 12 12 13 13 =head1 DESCRIPTION 14 14 15 This package holds three subroutines: C<parrot_version()>, C<slurp_file>,16 and C<generated_file_header>. Subroutines are not exported--each must be17 requested by using a fully qualified name.15 This package holds pre-configure time subroutines, which are not exported 16 and should not require Parrot::Config. 17 Each must be requested by using a fully qualified name. 18 18 19 19 =head1 SUBROUTINES 20 20 … … 134 134 return $header; 135 135 } 136 136 137 1; 137 =item C<generate_pbc_fingerprint()> 138 138 139 =back 139 Generate a unique number, the md5 of F<PBC_COMPAT>, 140 for each pbc format change. The length (12) influences 141 the header layout. 142 143 This is used in the packfile library. 144 See also F<tools/dev/pbc_header.pl> 145 146 =cut 147 148 sub generate_pbc_fingerprint { 149 150 unless (eval { require Digest::MD5; }) { 151 warn "Digest::MD5 not found. Skipping fingerprint"; 152 return ''; 153 } 154 my $content = slurp_file('PBC_COMPAT'); 155 $content =~ s/^#.*\n//gm; 156 $content =~ s/^\n//gm; 157 my $fingerprint = Digest::MD5::md5($content); 158 return substr $fingerprint, 0, 12; 159 } 160 161 =item C<get_bc_version()> 162 163 Return an array of ($bc_major, $bc_minor) from F<PBC_COMPAT>. 164 This is used to generate the pbc_uuid. 140 165 141 =head1 AUTHOR 166 See also F<tools/dev/pbc_header.pl> and F<tools/build/pbcversion_h.pl>. 142 167 143 Gregor N. Purdy. Revised by James E Keenan. 168 =cut 169 170 sub get_bc_version { 171 my $compat_file = 'PBC_COMPAT'; 172 my ( $bc_major, $bc_minor ); 173 open my $IN, '<', $compat_file or die "Can't read $compat_file"; 174 while (<$IN>) { 175 if (/^(\d+)\.0*(\d+)/) { 176 ( $bc_major, $bc_minor ) = ( $1, $2 ); 177 last; 178 } 179 } 180 unless ( defined $bc_major && defined $bc_minor ) { 181 die "No bytecode version found in '$compat_file'."; 182 } 183 close $IN; 184 return ( $bc_major, $bc_minor ); 185 } 186 187 188 1; 189 190 =back 144 191 145 192 =cut 146 193 -
tools/dev/pbc_header.pl
old new 36 36 =cut 37 37 38 38 use Getopt::Long; 39 use Digest::MD5 qw(md5); 39 use lib "lib"; 40 use Parrot::BuildUtil; 40 41 41 42 my %opt; 42 use constant FP_LEN => 12;43 43 my $word_size = 4; 44 44 45 45 main(); 46 46 47 sub get_fp {48 49 # s. also fingerprint_c.pl50 my $compat_file = 'PBC_COMPAT';51 open my $IN, '<', $compat_file or die "Can't read $compat_file";52 my @lines = <$IN>;53 close $IN;54 55 my $len = FP_LEN;56 my $fingerprint = md5 join "\n", grep { !/^#/ } @lines;57 58 return substr $fingerprint, 0, $len;59 }60 61 47 sub get_version { 62 48 my $version_file = 'VERSION'; 63 49 open my $IN, '<', $version_file or die "Can't read $version_file"; … … 87 73 sub update_fp { 88 74 my (@args) = @_; 89 75 90 my $fp = get_fp(); 76 my $fp = Parrot::BuildUtil::generate_pbc_fingerprint(); 77 my $fp_len = length $fp; 91 78 my ( $major, $minor, $patch ) = get_version(); 92 79 my ( $bc_major, $bc_minor ) = get_bc_version(); 93 80 for my $f (@args) { … … 104 91 # uuid_type = 1, uuid_size = 10, uuid_data = $fp 105 92 read $F, $b, 8; 106 93 my ($type, $uuid_len) = unpack "cc", $b; 107 if ($type != 1 or $uuid_len != FP_LEN) {94 if ($type != 1 or $uuid_len != $fp_len) { 108 95 # if uuid_type was 0 or of different size copy the tail first 109 96 my $leftover = (18 + $uuid_len) % 16; 110 97 my $n = $leftover == 0 ? 0 : 16 - $leftover; 111 # we can skip the copy if there's enough room already (pad: 14=>2)112 goto SEEK if $n < FP_LEN;98 # we can skip the copy if there's enough room already (pad: 14=>2) 99 goto SEEK if $n > $fp_len; 113 100 my $dirstart = 18 + $uuid_len + $n; 114 101 seek $F, $dirstart, 0; # skip to dir 115 102 my $size = -s $F; … … 119 106 } 120 107 SEEK: 121 108 seek $F, 16, 0; # back to pos 16: uuid_type, uuid_size 122 print $F pack "cc", 1, FP_LEN;109 print $F pack "cc", 1, $fp_len; 123 110 print $F $fp; 124 111 close $F; 125 112 } -
config/gen/config_h/config_h.in
old new 94 94 #define PARROT_BYTEORDER 0x@byteorder@ 95 95 #define PARROT_BIGENDIAN @bigendian@ 96 96 #define PARROT_PTR_ALIGNMENT @ptr_alignment@ 97 #define PARROT_PBC_UUID "@pbc_uuid@" 97 98 98 99 #define PARROT_LITTLEENDIAN !(PARROT_BIGENDIAN) 99 100 -
src/packfile.c
old new 1245 1245 # endif 1246 1246 # endif 1247 1247 #endif 1248 if (*PARROT_PBC_UUID) { 1249 header->uuid_type = 1; 1250 header->uuid_size = sizeof(PARROT_PBC_UUID); 1251 header->uuid_data = (unsigned char *)PARROT_PBC_UUID; 1252 mem_sys_allocate(header->uuid_size + 1); 1253 memcpy(header->uuid_data, PARROT_PBC_UUID, header->uuid_size); 1254 /* NULL terminate */ 1255 header->uuid_data[header->uuid_size] = 0; 1256 } 1248 1257 } 1249 1258 1250 1259 -
Configure.pl
old new 64 64 # from Parrot::Configure::Data 65 65 $conf->options->set( %{$args} ); 66 66 # save the command-line for make reconfig 67 $conf->data->set(configure_args => @ARGV ? '"'.join("\" \"", map {qq($_)} @ARGV).'"' 68 : ''); 67 $conf->data->set(configure_args => 68 @ARGV ? '"'.join("\" \"", map {qq($_)} @ARGV).'"' 69 : ''); 69 70 70 71 # Log files created by Configure.pl in MANIFEST.configure.generated 71 72 $conf->{active_configuration} = 1; -
config/auto/pmc.pm
old new 9 9 10 10 Asks the user to select which PMC files to include. 11 11 12 Generate a specific UUID for this selection then, 13 for the default use the md5 of PBC_COMPAT. 14 12 15 =cut 13 16 14 17 package auto::pmc; … … 22 25 use File::Spec::Functions qw/catfile/; 23 26 24 27 use Parrot::Configure::Utils ':auto'; 28 use Parrot::BuildUtil; 25 29 26 30 sub _init { 27 31 my $self = shift; … … 168 172 169 173 my @names = $self->order_pmcs_by_hierarchy( \%parents ); 170 174 175 # Generate a specific UUID for user-defined pmc's and ops 176 # auto::ops runs before auto::pmc, so do it here. 177 my $pbc_uuid = ''; 178 if ($conf->options->get('pmc') or $conf->options->get('ops')) { 179 unless (eval { require Digest::MD5; }) { 180 warn "Digest::MD5 not found. Skipping fingerprint"; 181 } 182 else { 183 my ( $major, $minor ) = Parrot::BuildUtil::get_bc_version(); 184 my $ops = $conf->data->get( 'ops' ); 185 my $fp = join( ' ', @names ) . " ". $ops . " " . $major . " " . $minor; 186 $pbc_uuid = substr Digest::MD5::md5( $fp ), 0, 12; 187 } 188 } 189 else { # use the default UUID. This requires PBC_COMPAT discipline 190 $pbc_uuid = Parrot::BuildUtil::generate_pbc_fingerprint(); 191 } 192 171 193 $conf->data->set( 172 194 pmc => $pmc_list, 173 195 pmc_names => join( ' ', @names ), 196 pbc_uuid => $pbc_uuid, 174 197 TEMP_pmc_o => $TEMP_pmc_o, 175 198 TEMP_pmc_build => $TEMP_pmc_build, 176 199 TEMP_pmc_classes_o => $TEMP_pmc_classes_o, -
tools/build/pbcversion_h.pl
old new 21 21 use warnings; 22 22 use strict; 23 23 use lib 'lib'; 24 use Parrot::BuildUtil; 24 25 25 my ( $major, $minor ); 26 27 my $compat_file = 'PBC_COMPAT'; 28 open my $IN, '<', $compat_file or die "Can't read $compat_file"; 29 while (<$IN>) { 30 if (/^(\d+)\.0*(\d+)/) { 31 ( $major, $minor ) = ( $1, $2 ); 32 last; 33 } 34 } 35 close $IN; 36 37 unless ( defined $major && defined $minor ) { 38 die "No bytecode version found in '$compat_file'."; 39 } 26 my ( $major, $minor ) = Parrot::BuildUtil::get_bc_version(); 40 27 41 28 print << "EOF"; 42 29 /* ex: set ro: 43 30 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! 44 31 * 45 * This file is generated automatically from ' $compat_file'32 * This file is generated automatically from 'PBC_COMPAT' 46 33 * by $0. 47 34 * 48 35 * Any changes made here will be lost! -
config/auto/ops.pm
old new 9 9 10 10 Asks the user to select which ops files to include. 11 11 12 Generate a specific UUID for this selection in auto::pmc then. 13 12 14 =cut 13 15 14 16 package auto::ops;
