Ticket #426: parrotinstall.patch
File parrotinstall.patch, 16.5 KB (added by wayland, 13 years ago) |
---|
-
tools/dev/install_dev_files.pl
1 #! perl -Ilib1 #! perl 2 2 ################################################################################ 3 3 # Copyright (C) 2001-2009, Parrot Foundation. 4 4 # $Id$ … … 95 95 my $parrotdir = $options{versiondir}; 96 96 97 97 # Set up transforms on filenames 98 my(@transformorder) = (qw(lib share include src doc), '^(tools|VERSION)', '^compilers'); 98 99 my(%metatransforms) = ( 99 100 lib => { 101 ismeta => 1, 100 102 optiondir => 'lib', 101 103 transform => sub { 102 my($dest) = @_; 103 $parrotdir, "tools", $dest; 104 my($filehash) = @_; 105 $filehash->{DestDirs} = [$parrotdir, "tools"]; 106 return($filehash); 104 107 }, 105 108 }, 106 109 share => { 110 ismeta => 1, 107 111 optiondir => 'data', 108 112 transform => sub { 109 my($dest) = @_; 110 $parrotdir, basename($dest); 113 my($filehash) = @_; 114 $filehash->{Dest} = basename($filehash->{Dest}); 115 $filehash->{DestDirs} = [$parrotdir]; 116 return($filehash); 111 117 }, 112 118 }, 113 119 include => { 120 ismeta => 1, 114 121 optiondir => 'include', 115 122 transform => sub { 116 my($dest) = @_; 117 $dest =~ s/^src//; # strip off leading src/ dir 118 $dest =~ s/^include//; 119 $parrotdir, $dest; 123 my($filehash) = @_; 124 $filehash->{Dest} =~ s/^src//; # strip off leading src/ dir 125 $filehash->{Dest} =~ s/^include//; 126 $filehash->{DestDirs} = [$parrotdir]; 127 return($filehash); 120 128 }, 121 129 }, 122 130 src => { 131 ismeta => 1, 123 132 optiondir => 'src', 124 133 transform => sub { 125 my($dest) = @_; 126 $dest =~ s/^src//; # strip off leading src/ dir 127 $parrotdir, $dest; 134 my($filehash) = @_; 135 $filehash->{Dest} =~ s/^src//; # strip off leading src/ dir 136 $filehash->{DestDirs} = [$parrotdir]; 137 return($filehash); 128 138 }, 129 139 }, 130 140 doc => { 141 ismeta => 1, 131 142 optiondir => 'doc', 132 143 transform => sub { 133 my($dest) = @_; 134 $dest =~ s/^docs/pod/; # other docs are actually raw Pod 135 $parrotdir, $dest; 144 my($filehash) = @_; 145 $filehash->{Dest} =~ s/^docs/pod/; # other docs are actually raw Pod 146 $filehash->{DestDirs} = [$parrotdir]; 147 return($filehash); 136 148 }, 137 149 }, 138 );139 140 my(%othertransforms) = (141 150 '^(tools|VERSION)' => { 142 151 optiondir => 'lib', 143 152 transform => sub { 144 my($dest) = @_; 145 $parrotdir, $dest; 153 my($filehash) = @_; 154 $filehash->{DestDirs} = [$parrotdir]; 155 return($filehash); 146 156 }, 147 157 }, 148 158 '^compilers' => { 149 159 optiondir => 'lib', 150 160 transform => sub { 151 my($dest) = @_; 152 $dest =~ s/^compilers/languages/; 153 $parrotdir, $dest; 161 my($filehash) = @_; 162 $filehash->{Dest} =~ s/^compilers/languages/; 163 $filehash->{DestDirs} = [$parrotdir]; 164 return($filehash); 154 165 }, 155 166 }, 156 167 ); 157 168 158 my($file s, $installable_exe, $directories) = Parrot::Install::lines_to_files(159 \%metatransforms, \ %othertransforms, \@manifests, \%options, $parrotdir169 my($filehashes, $directories) = lines_to_files( 170 \%metatransforms, \@transformorder, \@manifests, \%options, $parrotdir 160 171 ); 161 172 162 173 unless ( $options{'dry-run'} ) { 163 Parrot::Install::create_directories($options{destdir}, $directories);174 create_directories($options{destdir}, $directories); 164 175 } 165 Parrot::Install::install_files($options{destdir}, $options{'dry-run'}, @$files, @$installable_exe);176 install_files($options{destdir}, $options{'dry-run'}, $filehashes); 166 177 178 print "Finished install_dev_files.pl\n"; 179 167 180 # Local Variables: 168 181 # mode: cperl 169 182 # cperl-indent-level: 4 -
tools/dev/install_files.pl
1 # perl1 #! perl 2 2 ################################################################################ 3 # Copyright (C) 2001-200 8, Parrot Foundation.3 # Copyright (C) 2001-2009, Parrot Foundation. 4 4 # $Id$ 5 5 ################################################################################ 6 6 … … 148 148 149 149 my $parrotdir = $options{versiondir}; 150 150 151 my %metatransforms = ( 151 # Set up transforms on filenames 152 my(@transformorder) = qw(lib bin include doc pkgconfig ^compilers); 153 my(%metatransforms) = ( 152 154 lib => { 155 ismeta => 1, 153 156 optiondir => 'lib', 154 157 transform => sub { 155 my($dest) = @_; 156 if ( $dest =~ /^install_/ ) { 157 $dest =~ s/^install_//; # parrot with different config 158 $parrotdir, 'include', $dest; 158 my($filehash) = @_; 159 local($_) = $filehash->{Dest}; 160 if ( /^install_/ ) { 161 s/^install_//; # parrot with different config 162 $filehash->{DestDirs} = [$parrotdir, 'include']; 163 $filehash->{Dest} = $_; 159 164 } 160 165 else { 161 166 # don't allow libraries to be installed into subdirs of libdir 162 basename($dest);167 $filehash->{Dest} = basename($_); 163 168 } 169 return($filehash); 164 170 }, 165 171 }, 166 172 bin => { 173 ismeta => 1, 167 174 optiondir => 'bin', 168 175 transform => sub { 169 my($dest) = @_; 170 $dest =~ s/^installable_//; # parrot with different config 171 $dest; 176 my($filehash) = @_; 177 # parrot with different config 178 $filehash->{Installable} = $filehash->{Dest} =~ s/^installable_//; 179 return($filehash); 172 180 }, 173 181 isbin => 1, 174 182 }, 175 183 include => { 184 ismeta => 1, 176 185 optiondir => 'include', 177 186 transform => sub { 178 my($dest) = @_; 179 $dest =~ s/^include//; 180 $parrotdir, $dest; 187 my($filehash) = @_; 188 $filehash->{Dest} =~ s/^include//; 189 $filehash->{DestDirs} = [$parrotdir]; 190 return($filehash); 181 191 }, 182 192 }, 183 193 doc => { 194 ismeta => 1, 184 195 optiondir => 'doc', 185 196 transform => sub { 186 my($dest) = @_; 187 $dest =~ s/^docs\/resources/resources/; # resources go in the top level of docs 188 $dest =~ s/^docs/pod/; # other docs are actually raw Pod 189 $parrotdir, $dest; 197 my($filehash) = @_; 198 $filehash->{Dest} =~ s#^docs/resources#resources#; # resources go in the top level of docs 199 $filehash->{Dest} =~ s/^docs/pod/; # other docs are actually raw Pod 200 $filehash->{DestDirs} = [$parrotdir]; 201 return($filehash); 190 202 }, 191 203 }, 192 204 pkgconfig => { 205 ismeta => 1, 193 206 optiondir => 'lib', 194 207 transform => sub { 195 my($ dest) = @_;208 my($filehash) = @_; 196 209 # For the time being this is hardcoded as being installed under 197 210 # libdir as it is typically done with automake installed packages. 198 211 # If there is a use case to make this configurable we'll add a 199 212 # seperate --pkgconfigdir option. 200 'pkgconfig', $parrotdir, $dest; 213 $filehash->{DestDirs} = ['pkgconfig', $parrotdir]; 214 return($filehash); 201 215 }, 202 216 }, 203 );204 205 my %othertransforms = (206 217 '^compilers' => { 207 218 optiondir => 'lib', 208 219 transform => sub { 209 my($dest) = @_; 210 $dest =~ s/^compilers/languages/; 211 $parrotdir, $dest; 220 my($filehash) = @_; 221 $filehash->{Dest} =~ s/^compilers/languages/; 222 $filehash->{DestDirs} = [$parrotdir]; 223 return($filehash); 212 224 }, 213 225 }, 214 226 ); 215 227 216 my($file s, $installable_exe, $directories) = lines_to_files(217 \%metatransforms, \ %othertransforms, \@manifests, \%options, $parrotdir228 my($filehashes, $directories) = lines_to_files( 229 \%metatransforms, \@transformorder, \@manifests, \%options, $parrotdir 218 230 ); 219 231 220 232 unless ( $options{'dry-run'} ) { … … 222 234 } 223 235 224 236 # TT #347 225 # 1. skip build_dir-only binaries for @installable_exe 226 for (@$installable_exe) { 227 my ( $i, $dest ) = @$_; 228 my ($file) = $i =~ /installable_(.+)$/; 237 # 1. skip build_dir-only binaries for files marked Installable 238 my($filehash, @removes, $removes); 239 foreach $filehash (grep { $_->{Installable} } @$filehashes) { 240 my( $src, $dest ) = map { $filehash->{$_} } qw(Source Dest); 241 my ($file) = $src =~ /installable_(.+)$/; 229 242 next unless $file; 230 my @f = map { $_ ? $_->[0] : '' } @$files; 231 if (grep(/^$file$/, @f)) { 232 if (-e $file) { 233 print "skipping $file, using installable_$file instead\n"; 234 @$files = map {$_ and $_->[0] !~ /^$file$/ ? $_ : undef} @$files; 235 } 243 if((grep { $_->{Source} =~ /^$file$/ } @$filehashes) and -e $file) { 244 print "skipping $file, using installable_$file instead\n"; 245 push @removes, $file; 236 246 } 237 247 } 248 $removes = join '|', @removes; 249 @$filehashes = grep { $_->{Source} !~ /^($removes)$/ } @$filehashes; 250 238 251 # 2. for every .exe check if there's an installable. Fail if not 239 foreach my $f (@$files ) { 240 next unless $_; 241 my ( $f, $dest ) = @$_;242 my $i;252 my $i; 253 foreach $filehash (grep { ! $_->{Installable} } @$filehashes ) { 254 my( $src, $dest ) = map { $filehash->{$_} } qw(Source Dest); 255 next unless $src =~ /\.exe$/; 243 256 # This logic will fail on non-win32 if the generated files are really 244 257 # generated as with rt #40817. We don't have [main]bin here. 245 $i = "installable_$f" if $f =~ /\.exe$/; 246 next unless $i; 247 unless (map {$_->[0] =~ /^$i$/} @$installable_exe) { 258 $i = "installable_$src"; 259 unless (map {$_->{Source} =~ /^$i$/} grep { $_->{Installable} } @$filehashes) { 248 260 die "$i is missing in MANIFEST or MANIFEST.generated\n"; 249 261 } 250 262 } 251 263 252 install_files( 253 $options{destdir}, $options{'dry-run'}, @$files, @$installable_exe 254 ); 264 install_files($options{destdir}, $options{'dry-run'}, $filehashes); 255 265 256 266 print "Finished install_files.pl\n"; 257 267 -
lib/Parrot/Install.pm
4 4 use warnings; 5 5 use File::Basename qw(dirname); 6 6 use File::Copy; 7 use File::Path; # mkpath 7 8 use File::Spec; 8 9 use base qw( Exporter ); 9 10 our @EXPORT_OK = qw( … … 42 43 43 44 B<Arguments:> List of five scalars. 44 45 45 ($files, $ installable_exe, $directories) =46 ($files, $directories) = 46 47 lines_to_files( 47 48 \%metatransforms, 48 \ %othertransforms,49 \@transformorder, 49 50 \@manifests, 50 51 \%options, 51 52 $parrotdir, … … 58 59 =cut 59 60 60 61 sub lines_to_files { 61 my ($metatransforms, $ othertransforms, $manifests, $options, $parrotdir)62 my ($metatransforms, $transformorder, $manifests, $options, $parrotdir) 62 63 = @_; 63 64 my @files; 64 my @installable_exe;65 65 my %directories; 66 my $tkey; 66 my($tkey, $th); 67 my $filehash; 67 68 68 69 # We'll report multiple occurrences of the same file 69 70 my(%seen); … … 96 97 @meta{ split( /,/, $meta ) } = (); 97 98 $meta{$_} = 1 for ( keys %meta ); # Laziness 98 99 100 $filehash = { 101 Source => $src, 102 Dest => $dest, 103 DestDirs => [], 104 }; 99 105 FIXFILE: { 100 106 # Have to catch this case early for some unknown reason 101 107 if ( /^runtime/ ) { 102 $ dest=~ s/^runtime\/parrot\///;103 $ dest= File::Spec->catdir(108 $filehash->{Dest} =~ s/^runtime\/parrot\///; 109 $filehash->{Dest} = File::Spec->catdir( 104 110 $options->{libdir}, $parrotdir, $dest 105 111 ); 106 112 last FIXFILE; 107 113 } 108 114 109 my($copy); 110 foreach $tkey (keys %$metatransforms) { 111 if ( $meta{$tkey} ) { 112 $copy = $dest; # only needed for installable 113 $dest = File::Spec->catdir( 114 $options->{$metatransforms->{$tkey}->{optiondir} . 'dir'}, 115 &{ $metatransforms->{$tkey}->{transform} }($dest) 116 ); 117 if ( $metatransforms->{$tkey}->{isbin} 118 and 119 $copy =~ /^installable/ 120 ) { 121 push @installable_exe, [ $src, $dest ]; 122 next LINE; 123 } 124 last FIXFILE; 125 } 115 foreach $tkey (@$transformorder) { 116 $th = $metatransforms->{$tkey}; 117 unless($th->{ismeta} ? $meta{$tkey} : $tkey) { next; } 118 $filehash = &{ $th->{transform} }($filehash); 119 $filehash->{Dest} = File::Spec->catdir( 120 $options->{$th->{optiondir} . 'dir'}, 121 @{ $filehash->{DestDirs} }, 122 $filehash->{Dest} 123 ); 124 last FIXFILE; 126 125 } 127 128 foreach $tkey (keys %$othertransforms) {129 if ( /$tkey/ ) {130 $dest = File::Spec->catdir(131 $options->{$othertransforms->{$tkey}->{optiondir} . 'dir'},132 &{ $othertransforms->{$tkey}->{transform} }($dest)133 );134 last FIXFILE;135 }136 }137 126 die "Unknown install location in MANIFEST: $_"; 138 127 } 139 128 140 $dest = File::Spec->catdir( $options->{buildprefix}, $dest ) 141 if $options->{buildprefix}; 142 143 $directories{ dirname($dest) } = 1; 144 push( @files, [ $src => $dest ] ); 129 # TODO ...maybe we should be doing these even if it's installable 130 if(! $filehash->{Installable}) { 131 $filehash->{Dest} = File::Spec->catdir( $options->{buildprefix}, $filehash->{Dest} ) 132 if $options->{buildprefix}; 133 } 134 $directories{ dirname($filehash->{Dest}) } = 1; 135 push( @files, $filehash ); 145 136 } 146 137 continue { 147 138 close ARGV if eof; # Reset line numbering for each input file 148 139 } 149 140 150 return(\@files, \@installable_exe, \%directories); 141 (grep { ! ref } @files) and die "lines_to_files from Parrot::Install created a bad hash!\n"; 142 143 return(\@files, \%directories); 151 144 } 152 145 153 146 =head2 C<create_directories()> … … 169 162 170 163 sub create_directories { 171 164 my($destdir, $directories) = @_; 172 my($dir, @dirs);173 165 174 for $dir ( map { $destdir . $_ } keys %$directories ) { 175 unless ( -d $dir ) { 176 177 # Make full path to the directory $dir 178 while ( !-d $dir ) { # Scan up to nearest existing ancestor 179 unshift @dirs, $dir; 180 $dir = dirname($dir); 181 } 182 foreach (@dirs) { 183 -d or mkdir( $_, 0777 ) or die "mkdir $_: $!\n"; 184 } 185 } 186 } 187 return 1; 166 mkpath([ 167 grep { ! -d } map { $destdir . $_ } keys %$directories 168 ],0,0777); 188 169 } 189 170 190 171 =head2 C<install_files()> … … 207 188 =cut 208 189 209 190 sub install_files { 210 my($destdir, $dryrun, @files) = @_;211 my($src, $dest, $mode );191 my($destdir, $dryrun, $files) = @_; 192 my($src, $dest, $mode, $file); 212 193 213 194 print("Installing ...\n"); 214 foreach ( @files ) {215 next unless $ _;216 ( $src, $dest ) = @$_;195 foreach $file ( @$files ) { 196 next unless $file; 197 ( $src, $dest ) = map { $file->{$_} } qw(Source Dest); 217 198 $dest = $destdir . $dest; 218 199 if ( $dryrun ) { 219 200 print "$src -> $dest\n"; -
t/tools/install/01-install_files.t
10 10 use Carp; 11 11 use File::Temp qw( tempdir ); 12 12 use lib qw( lib ); 13 use File::Temp qw/ tempdir /; 13 14 use Parrot::Install qw( 14 15 install_files 15 16 create_directories … … 45 46 46 47 =cut 47 48 49 { 50 my($dir) = tempdir( CLEANUP => 1 ); 51 $dir .= '/'; 52 53 my(@dirs) = qw(foo/bar foo/bar/baz); 54 create_directories($dir, { map { $_ => 1 } @dirs }); 55 foreach(@dirs) { 56 -d $dir . $_ or croak "create_directories didn't create directory"; 57 } 58 } 59 48 60 # Local Variables: 49 61 # mode: cperl 50 62 # cperl-indent-level: 4