Ticket #426: parrotinstall.patch

File parrotinstall.patch, 16.5 KB (added by wayland, 13 years ago)

Update based on the svn branch

  • tools/dev/install_dev_files.pl

     
    1 #! perl -Ilib 
     1#! perl 
    22################################################################################ 
    33# Copyright (C) 2001-2009, Parrot Foundation. 
    44# $Id$ 
     
    9595my $parrotdir = $options{versiondir}; 
    9696 
    9797# Set up transforms on filenames 
     98my(@transformorder) = (qw(lib share include src doc), '^(tools|VERSION)', '^compilers'); 
    9899my(%metatransforms) = ( 
    99100    lib => { 
     101        ismeta => 1, 
    100102        optiondir => 'lib', 
    101103        transform => sub { 
    102             my($dest) = @_; 
    103             $parrotdir, "tools", $dest; 
     104            my($filehash) = @_; 
     105            $filehash->{DestDirs} = [$parrotdir, "tools"]; 
     106            return($filehash); 
    104107        }, 
    105108    }, 
    106109    share => { 
     110        ismeta => 1, 
    107111        optiondir => 'data', 
    108112        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); 
    111117        }, 
    112118    }, 
    113119    include => { 
     120        ismeta => 1, 
    114121        optiondir => 'include', 
    115122        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); 
    120128        }, 
    121129    }, 
    122130    src => { 
     131        ismeta => 1, 
    123132        optiondir => 'src', 
    124133        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); 
    128138        }, 
    129139    }, 
    130140    doc => { 
     141        ismeta => 1, 
    131142        optiondir => 'doc', 
    132143        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); 
    136148        }, 
    137149    }, 
    138 ); 
    139  
    140 my(%othertransforms) = ( 
    141150    '^(tools|VERSION)' => { 
    142151        optiondir => 'lib', 
    143152        transform => sub { 
    144             my($dest) = @_; 
    145             $parrotdir, $dest; 
     153            my($filehash) = @_; 
     154            $filehash->{DestDirs} = [$parrotdir]; 
     155            return($filehash); 
    146156        }, 
    147157    }, 
    148158    '^compilers' => { 
    149159        optiondir => 'lib', 
    150160        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); 
    154165        }, 
    155166    }, 
    156167); 
    157168 
    158 my($files, $installable_exe, $directories) = Parrot::Install::lines_to_files( 
    159     \%metatransforms, \%othertransforms, \@manifests, \%options, $parrotdir 
     169my($filehashes, $directories) = lines_to_files( 
     170    \%metatransforms, \@transformorder, \@manifests, \%options, $parrotdir 
    160171); 
    161172 
    162173unless ( $options{'dry-run'} ) { 
    163     Parrot::Install::create_directories($options{destdir}, $directories); 
     174    create_directories($options{destdir}, $directories); 
    164175} 
    165 Parrot::Install::install_files($options{destdir}, $options{'dry-run'}, @$files, @$installable_exe); 
     176install_files($options{destdir}, $options{'dry-run'}, $filehashes); 
    166177 
     178print "Finished install_dev_files.pl\n"; 
     179 
    167180# Local Variables: 
    168181#   mode: cperl 
    169182#   cperl-indent-level: 4 
  • tools/dev/install_files.pl

     
    1 # perl 
     1#! perl 
    22################################################################################ 
    3 # Copyright (C) 2001-2008, Parrot Foundation. 
     3# Copyright (C) 2001-2009, Parrot Foundation. 
    44# $Id$ 
    55################################################################################ 
    66 
     
    148148 
    149149my $parrotdir = $options{versiondir}; 
    150150 
    151 my %metatransforms = ( 
     151# Set up transforms on filenames 
     152my(@transformorder) = qw(lib bin include doc pkgconfig ^compilers); 
     153my(%metatransforms) = ( 
    152154    lib => { 
     155        ismeta => 1, 
    153156        optiondir => 'lib', 
    154157        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} = $_; 
    159164            } 
    160165            else { 
    161166                # don't allow libraries to be installed into subdirs of libdir 
    162                 basename($dest); 
     167                $filehash->{Dest} = basename($_); 
    163168            } 
     169            return($filehash); 
    164170        }, 
    165171    }, 
    166172    bin => { 
     173        ismeta => 1, 
    167174        optiondir => 'bin', 
    168175        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); 
    172180        }, 
    173181        isbin => 1, 
    174182    }, 
    175183    include => { 
     184        ismeta => 1, 
    176185        optiondir => 'include', 
    177186        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); 
    181191        }, 
    182192    }, 
    183193    doc => { 
     194        ismeta => 1, 
    184195        optiondir => 'doc', 
    185196        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); 
    190202        }, 
    191203    }, 
    192204    pkgconfig => { 
     205        ismeta => 1, 
    193206        optiondir => 'lib', 
    194207        transform => sub { 
    195             my($dest) = @_; 
     208            my($filehash) = @_; 
    196209            # For the time being this is hardcoded as being installed under 
    197210            # libdir as it is typically done with automake installed packages. 
    198211            # If there is a use case to make this configurable we'll add a 
    199212            # seperate --pkgconfigdir option. 
    200             'pkgconfig', $parrotdir, $dest; 
     213            $filehash->{DestDirs} = ['pkgconfig', $parrotdir]; 
     214            return($filehash); 
    201215        }, 
    202216    }, 
    203 ); 
    204  
    205 my %othertransforms = ( 
    206217    '^compilers' => { 
    207218        optiondir => 'lib', 
    208219        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); 
    212224        }, 
    213225    }, 
    214226); 
    215227 
    216 my($files, $installable_exe, $directories) = lines_to_files( 
    217     \%metatransforms, \%othertransforms, \@manifests, \%options, $parrotdir 
     228my($filehashes, $directories) = lines_to_files( 
     229    \%metatransforms, \@transformorder, \@manifests, \%options, $parrotdir 
    218230); 
    219231 
    220232unless ( $options{'dry-run'} ) { 
     
    222234} 
    223235 
    224236# 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 
     238my($filehash, @removes, $removes); 
     239foreach $filehash (grep { $_->{Installable} } @$filehashes) { 
     240    my( $src, $dest ) = map { $filehash->{$_} } qw(Source Dest); 
     241    my ($file) = $src =~ /installable_(.+)$/; 
    229242    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; 
    236246    } 
    237247} 
     248$removes = join '|', @removes; 
     249@$filehashes = grep { $_->{Source} !~ /^($removes)$/ } @$filehashes; 
     250 
    238251# 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; 
     252my $i; 
     253foreach $filehash (grep { ! $_->{Installable} } @$filehashes ) { 
     254    my( $src, $dest ) = map { $filehash->{$_} } qw(Source Dest); 
     255    next unless $src =~ /\.exe$/; 
    243256    # This logic will fail on non-win32 if the generated files are really 
    244257    # 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) { 
    248260        die "$i is missing in MANIFEST or MANIFEST.generated\n"; 
    249261    } 
    250262} 
    251263 
    252 install_files( 
    253     $options{destdir}, $options{'dry-run'}, @$files, @$installable_exe 
    254 ); 
     264install_files($options{destdir}, $options{'dry-run'}, $filehashes); 
    255265 
    256266print "Finished install_files.pl\n"; 
    257267 
  • lib/Parrot/Install.pm

     
    44use warnings; 
    55use File::Basename qw(dirname); 
    66use File::Copy; 
     7use File::Path; # mkpath 
    78use File::Spec; 
    89use base qw( Exporter ); 
    910our @EXPORT_OK = qw( 
     
    4243 
    4344B<Arguments:> List of five scalars. 
    4445 
    45     ($files, $installable_exe, $directories) = 
     46    ($files, $directories) = 
    4647        lines_to_files( 
    4748            \%metatransforms, 
    48             \%othertransforms, 
     49            \@transformorder, 
    4950            \@manifests, 
    5051            \%options, 
    5152            $parrotdir, 
     
    5859=cut 
    5960 
    6061sub lines_to_files { 
    61     my ($metatransforms, $othertransforms, $manifests, $options, $parrotdir) 
     62    my ($metatransforms, $transformorder, $manifests, $options, $parrotdir) 
    6263        = @_; 
    6364    my @files; 
    64     my @installable_exe; 
    6565    my %directories; 
    66     my $tkey; 
     66    my($tkey, $th); 
     67    my $filehash; 
    6768 
    6869    # We'll report multiple occurrences of the same file 
    6970    my(%seen); 
     
    9697        @meta{ split( /,/, $meta ) } = (); 
    9798        $meta{$_} = 1 for ( keys %meta );          # Laziness 
    9899 
     100        $filehash = { 
     101            Source => $src, 
     102            Dest => $dest, 
     103            DestDirs => [], 
     104        }; 
    99105        FIXFILE: { 
    100106            # Have to catch this case early for some unknown reason 
    101107            if ( /^runtime/ ) { 
    102                 $dest =~ s/^runtime\/parrot\///; 
    103                 $dest = File::Spec->catdir( 
     108                $filehash->{Dest} =~ s/^runtime\/parrot\///; 
     109                $filehash->{Dest} = File::Spec->catdir( 
    104110                    $options->{libdir}, $parrotdir, $dest 
    105111                ); 
    106112                last FIXFILE; 
    107113            } 
    108114 
    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; 
    126125            } 
    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             } 
    137126            die "Unknown install location in MANIFEST: $_"; 
    138127        } 
    139128 
    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 ); 
    145136    } 
    146137    continue { 
    147138        close ARGV if eof;    # Reset line numbering for each input file 
    148139    } 
    149140 
    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); 
    151144} 
    152145 
    153146=head2 C<create_directories()> 
     
    169162 
    170163sub create_directories { 
    171164    my($destdir, $directories) = @_; 
    172     my($dir, @dirs); 
    173165 
    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); 
    188169} 
    189170 
    190171=head2 C<install_files()> 
     
    207188=cut 
    208189 
    209190sub install_files { 
    210     my($destdir, $dryrun, @files) = @_; 
    211     my($src, $dest, $mode); 
     191    my($destdir, $dryrun, $files) = @_; 
     192    my($src, $dest, $mode, $file); 
    212193 
    213194    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); 
    217198        $dest = $destdir . $dest; 
    218199        if ( $dryrun ) { 
    219200            print "$src -> $dest\n"; 
  • t/tools/install/01-install_files.t

     
    1010use Carp; 
    1111use File::Temp qw( tempdir ); 
    1212use lib qw( lib ); 
     13use File::Temp qw/ tempdir /; 
    1314use Parrot::Install qw( 
    1415    install_files 
    1516    create_directories 
     
    4546 
    4647=cut 
    4748 
     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 
    4860# Local Variables: 
    4961#   mode: cperl 
    5062#   cperl-indent-level: 4