CPAN-Packager

 view release on metacpan or  search on metacpan

lib/CPAN/Packager/Builder/RPM/Spec.pm  view on Meta::CPAN

            exit(1);
        }
        if ( !-r $options{'descfile'} ) {
            print STDERR "Description file given is not readable!\n";
            print STDERR "File:  ${options{'descfile'}}\n";
            exit(1);
        }
    }

    #
    # Overide defaults if necessary, otherwise keep them.
    my $tarball          = basename($fullname);
    my $create           = $options{create} || '';
    my $email            = $options{email} || $defaults{'email'};
    my $requires         = $options{requires} || [];
    my $buildrequires    = $options{buildrequires} || [];
    my $outdir           = $options{outdir} || $defaults{'outdir'};
    my $tmpdir           = $options{tmpdir} || $defaults{'tmpdir'};
    my $noarch           = $options{noarch} || '';
    my $plat_perl_reqs   = $options{'noperlreqs'} ? 0 : 1;
    my $release          = $options{'release'} || $defaults{'release'};
    my $build_switch     = 's';
    my $use_module_build = 0;
    my @docs             = ();

    $tmpdir = tempdir( CLEANUP => 1, DIR => $tmpdir );

    #
    # Set build arch - this is needed to find out where
    # the binary rpm was placed, and copy it back to the
    # current working directory.
    my $build_arch;
    if ( $options{'arch'} ) {
        $build_arch = $options{'arch'};
    }
    elsif ( $options{'noarch'} ) {
        $build_arch = 'noarch';
    }
    else {
        $build_arch = get_default_build_arch();
        if ( $build_arch eq '' ) {
            print STDERR "Could not get default build arch!\n";
            exit(1);
        }
    }

    $build_switch = 'a' if ( defined( $options{'buildall'} ) );

    $tarball =~ /^(.+)\-([^-]+)\.t(ar\.)?gz$/;
    my $name = $options{name}    || $1;
    my $ver  = $options{version} || $2;
    my $tarball_top_dir = "$name-%{version}";

    die "Module name/version not parsable from $tarball"
        unless $name and $ver;

    $name =~ s/::/-/g;

    copy( $fullname, $tmpdir )
        or die "copy $fullname: $!";
    utime( ( stat($fullname) )[ 8, 9 ], "$tmpdir/$tarball" );

    if ( my @files = Archive::Tar->list_archive("$tmpdir/$tarball") ) {
        $use_module_build = 1 if grep {/Build\.PL$/} @files;

        if ( not exists $options{noarch} ) {
            $noarch = 1;
            $noarch = 0 if grep {/\.(xs|c|cc|C)$/} @files;
        }

        my %prefixes;
        foreach (@files) {
            my @path_components = split m[/], $_;
            $prefixes{ $path_components[0] }++;

            if ( $path_components[-1] eq 'META.yml' ) {
                my $tar = new Archive::Tar;
                $tar->read( "$tmpdir/$tarball", 1 );
                my $contents = $tar->get_content($_);
                my $yaml;
                eval { $yaml = Load($contents); };

                unless ($@) {
                    while ( my ( $mod, $ver )
                        = each %{ $yaml->{build_requires} } )
                    {
                        push @build_requires, [ "perl($mod)", $ver ];
                    }
                    while ( my ( $mod, $ver ) = each %{ $yaml->{requires} } )
                    {
                        push @requires, [ "perl($mod)", $ver ];
                    }
                }
            }

            # find docs
            if (m,^${name}-${ver}/(
          authors?|
          change(log|s)|
          credits|
          copy(ing|right)|
          licen[cs]e|
          readme|
          todo
          )$,ix
                )
            {
                push( @docs, $1 );
            }
        }

        if ( scalar keys %prefixes == 1 ) {
            ($tarball_top_dir) = keys %prefixes;
            $tarball_top_dir =~ s/$ver/%{version}/;
        }
    }

    #
    # Get patches copied into place
    my $patchfile  = '';
    my @patchfiles = ();
    my $patch      = '';
    if ( $options{patch} ) {
        for $patch ( @{ $options{'patch'} } ) { ## no critic
            copy( $patch, $tmpdir ) or die "copy ${patch}: $!";
            utime(
                ( stat( $options{patch} ) )[ 8, 9 ],
                "$tmpdir/" . basename( $options{patch} )
            );
            push @patchfiles, ( basename($patch) );
        }
    }

    #
    # Copy install scriptlets if defined to the tmp directory
    foreach my $scriptlet (qw(pre post preun postun)) {
        if ( defined( $options{$scriptlet} ) ) {
            copy( $options{$scriptlet}, $tmpdir )
                or die "copy ${options{${scriptlet}}}: $!";
            my ( $atime, $mtime ) = ( stat( $options{$scriptlet} ) )[ 8, 9 ];
            $options{$scriptlet}
                = "${tmpdir}/" . basename( $options{$scriptlet} );
            utime( $atime, $mtime, $options{$scriptlet} );
        }
    }

    my $spec = new RPM::Specfile;

    # some basic spec fields
    $spec->name("perl-$name");
    $spec->version($ver);
    $spec->release($release);
    $spec->epoch( $options{epoch} );
    $spec->summary("$name Perl module");
    $spec->group("Development/Libraries");
    $spec->license('GPL or Artistic');
    $spec->packager($email)
        if $defaults{'packager'};
    my $clver = defined( $options{epoch} ) ? "$options{epoch}:" : '';
    $clver .= "$ver-$release";
    $spec->add_changelog_entry( $email,
        "Specfile autogenerated with command '$orig_cmd'", $clver );

    for my $req (@requires) {
        $spec->push_require($req);
    }

    for my $req (@build_requires) {
        $spec->push_buildrequire($req);
    }

    # Setup spec description.  Defaults to summary, unless
    # description file provided:
    if ( $options{'descfile'} ) {
        $spec->description( read_desc_file( $options{'descfile'} ) );
    }
    else {
        $spec->description('%{summary}.');
    }

    #
    # Setup build architecture.
    $spec->buildarch( $options{'arch'} ) if ( defined( $options{'arch'} ) );
    $spec->buildarch('noarch') if $noarch;

    #
    # Use perl requirements by default (onward and upward...).
    if ($plat_perl_reqs) {
        $spec->push_require(
            q|perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))|
        );
    }

    $spec->push_source($tarball);
    foreach $patchfile (@patchfiles) { ## no critic
        $spec->push_patch($patchfile);
    }

    # make a URL that can actually possibly take you to the right place
    $spec->url(



( run in 1.138 second using v1.01-cache-2.11-cpan-302cb4679cc )