Changeset 182 for trunk


Ignore:
Timestamp:
05/27/15 21:49:52 (10 years ago)
Author:
kdeugau
Message:

/trunk

Major update worth a bump in the major version.

Rewrite handling for the %setup macro/tag after a bit of prodding from
Neal Gompa from the Enano CMS Project. The main addition is support
for the -a and -b flags, along with their related baggage.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r180 r182  
    66
    77PKGNAME=debbuild
    8 VERSION=0.9.10
     8VERSION=0.10.0
    99
    1010MANDIR=/usr/share/man
  • trunk/debbuild

    r180 r182  
    3232use Config;
    3333
    34 my $version = "0.9.10"; #VERSION#
     34my $version = "0.10.0"; #VERSION#
    3535
    3636# regex debugger
     
    110110  RPM_PACKAGE_RELEASE="%{release}"
    111111  export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
     112  LANG=C
     113  export LANG
     114  unset CDPATH DISPLAY ||:
    112115  RPM_BUILD_ROOT="%{buildroot}"
    113116  export RPM_BUILD_ROOT
     117
     118  PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/lib64/pkgconfig:/usr/share/pkgconfig"
     119  export PKG_CONFIG_PATH
    114120);
    115 foreach (`dpkg-architecture`) {
    116   s/=(.+)/="$1"/;
    117   $scriptletbase .= "  $_";
    118   ($hostarch) = (/^DEB_HOST_ARCH="(.+)"$/) if /DEB_HOST_ARCH=/;
     121
     122if (-e '/usr/bin/dpkg-architecture') {
     123  foreach (`dpkg-architecture`) {
     124    s/=(.+)/="$1"/;
     125    $scriptletbase .= "  $_";
     126    ($hostarch) = (/^DEB_HOST_ARCH="(.+)"$/) if /DEB_HOST_ARCH=/;
     127  }
     128} else {
     129  warn "Missing dpkg-architecture, DEB_HOST_ARCH will not be set!\n";
    119130}
     131
    120132$scriptletbase .=
    121133q(
    122134  set -x
    123135  umask 022
    124   cd %{_topdir}/BUILD
     136  cd "%{_topdir}/BUILD"
    125137);
    126138
     
    569581                $_ !~ /^%(?:attr|build|changelog|check|clean|config|configure|defattr|define|description|
    570582                dir|doc|docdir|else|endif|files|ghost|if|ifarch|ifn|ifnarch|ifnos|ifnxxx|fos|ifxxx|
    571                 install|makeinstall|package|patch\d+|post|postun|pre|prep|preun|readme|setup|
     583                install|makeinstall|package|patch\d+|post|postun|pre|prep|preun|readme|setup[^\s]*|
    572584                triggerin|triggerpostun|triggerun|verify|verifyscript)\b/x
    573585        ) {
     
    760772      if (/^\%setup/) {
    761773        $pkgdata{main}{hassetup} = 1;  # flag the fact that we've got %setup
    762         # Parse out the %setup macro.  Note that we aren't supporting
    763         # many of RPM's %setup features.
    764         $prepscript .= "cd $topdir/BUILD\n";
    765         if ( /\s+-n\s+([^\s]+)\s+/ ) {
    766           $tarballdir = $1;
    767         }
     774        # Parse out the %setup macro.
     775        chomp;
     776        # rpmbuild doesn't complain about gibberish immediately following %setup, but we will
     777        warn "Suspect \%setup tag '$_', continuing\n" if ! /^\%setup(?:\s|$)/;
     778
     779        # Prepare some flags
     780        my $changedir = 0;
     781        my $deldir = 1;
     782        my $quietunpack = 0;
     783        my $deftarball = 1;
     784        my $snum = '';
     785        my $sbefore;
     786        my $safter;
     787        my $altsource = 0;
     788
     789        my @sbits = split /\s+/;
     790        shift @sbits;
     791        while (my $sopt = shift @sbits) {
     792          if ($sopt eq '-n') {
     793            $tarballdir = shift @sbits;
     794          } elsif ($sopt eq '-a') {
     795            # shift, next opt must be numeric (which sourcenn:)
     796            $sopt = shift @sbits;
     797            die "Argument for \%setup -a must be numeric at $specfile line $.\n" if $sopt !~ /^\d+$/;
     798            $safter = $sopt;
     799            $snum = $sopt;
     800            $altsource = 1;
     801          } elsif ($sopt eq '-b') {
     802            # shift, next opt must be numeric (which sourcenn:)
     803            $sopt = shift @sbits;
     804            die "Argument for \%setup -b must be numeric at $specfile line $.\n" if $sopt !~ /^\d+$/;
     805            $sbefore = $sopt;
     806            $snum = $sopt;
     807            $altsource = 2;
     808          } elsif ($sopt eq '-c') {
     809            # flag, create and change directory before unpack
     810            $changedir = 1;
     811          } elsif ($sopt eq '-D') {
     812            # flag, do not delete directory before unpack
     813            $deldir = 0;
     814          } elsif ($sopt eq '-T') {
     815            # flag, do not unpack first source
     816            $deftarball = 0;
     817          } elsif ($sopt eq '-q') {
     818            # SSSH!  Unpack quietly
     819            $quietunpack = 1;
     820          }
     821        } # $sopt = shift @sbits
     822
     823# Note that this is an incomplete match to rpmbuild's full %setup expression.
     824# Still known to do:
     825# - Match implementation of -a and -b if both are specified.
     826#   Looks to be "expand -a into $aftersource and expand -b into $beforesource inside the while()"
     827#   instead of treating them as flags like the other arguments.
     828# - -q appears to be somewhat positional
     829
     830        $prepscript .= "cd '$topdir/BUILD'\n";
    768831        $tarballdir = expandmacros($tarballdir,'gp');
    769         $prepscript .= "rm -rf $tarballdir\n";
    770         if (/\s+-c\s+/) {
    771           $prepscript .= "mkdir $tarballdir\ncd $tarballdir\n";
    772         }
    773         $prepscript .=
     832        $prepscript .= "rm -rf '$tarballdir'\n" if $deldir;
     833        $prepscript .= "/bin/mkdir -p $tarballdir\n" if $changedir;
     834
     835        if ($deftarball) {
     836          $prepscript .=
    774837                ( $pkgdata{main}{source} =~ /\.tar\.gz$/  ? "/bin/gzip"   : "" ).
    775838                ( $pkgdata{main}{source} =~ /\.tar\.bz2$/ ? "/bin/bzip2"  : "" ).
    776839                ( $pkgdata{main}{source} =~ /\.tar\.xz$/  ? "/usr/bin/xz" : "" ).
    777                 " -dc $topdir/SOURCES/$pkgdata{main}{source} | /bin/tar -".
    778                 ( /\s+-q\s+/ ? '' : 'vv' )."xf -\n".
    779                 qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n).
    780                 "cd $topdir/BUILD/$tarballdir\n".
    781                 qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
    782                 qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
    783                 qq(/bin/chmod -Rf a+rX,g-w,o-w .\n);
     840                " -dc '$topdir/SOURCES/$pkgdata{main}{source}' | /bin/tar -x".
     841                ( $quietunpack ? '' : 'vv' )."f -\n".
     842                qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     843        }
     844
     845        if ($altsource) {
     846          if ($altsource == 1) { # -a
     847            $prepscript .= "cd '$tarballdir'\n";
     848            $prepscript .=
     849                ( $pkgdata{sources}{$snum} =~ /\.tar\.gz$/  ? "/bin/gzip"   : "" ).
     850                ( $pkgdata{sources}{$snum} =~ /\.tar\.bz2$/ ? "/bin/bzip2"  : "" ).
     851                ( $pkgdata{sources}{$snum} =~ /\.tar\.xz$/  ? "/usr/bin/xz" : "" ).
     852                " -dc '$topdir/SOURCES/$pkgdata{sources}{$snum}' | /bin/tar -x".
     853                ( $quietunpack ? '' : 'vv' )."f -\n".
     854                qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     855          } # $altsource == 1
     856
     857          if ($altsource == 2) { # -b
     858            $prepscript .=
     859                ( $pkgdata{sources}{$snum} =~ /\.tar\.gz$/  ? "/bin/gzip"   : "" ).
     860                ( $pkgdata{sources}{$snum} =~ /\.tar\.bz2$/ ? "/bin/bzip2"  : "" ).
     861                ( $pkgdata{sources}{$snum} =~ /\.tar\.xz$/  ? "/usr/bin/xz" : "" ).
     862                " -dc '$topdir/SOURCES/$pkgdata{sources}{$snum}' | /bin/tar -x".
     863                ( $quietunpack ? '' : 'vv' )."f -\n".
     864                qq(STATUS=\$?\nif [ \$STATUS -ne 0 ]; then\n  exit \$STATUS\nfi\n);
     865            $prepscript .= "cd '$tarballdir'\n";
     866          } # $altsource == 2
     867        } else {
     868          $prepscript .= "cd '$tarballdir'\n" unless $changedir;
     869        }
     870
     871# rpm doesn't seem to do the chowns any more
     872#               qq([ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .\n).
     873#               qq([ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .\n).
     874        $prepscript .=
     875                qq(/bin/chmod -Rf a+rX,u+w,g-w,o-w .\n);
     876
    784877      } elsif ( my ($patchnum,$patchopts) = (/^\%patch([^\s]+)(\s+.+)?$/) ) {
    785878        chomp $patchnum;
     
    9591052      } elsif (/^buildroot:\s*(.+)/i) {
    9601053        $specglobals{buildroot} = $1;
    961       } elsif (/^source0?:\s*(.+)/i) {
    962         $pkgdata{main}{source} = $1;
     1054      } elsif (my ($sval) = /^source0?:\s*(.+)/i) {
     1055        $pkgdata{main}{source} = $sval;
    9631056        # Do this here since we don't use any URL forms elsewhere (maybe some other time)
    964         $pkgdata{main}{source} =~ s|^.+/([^/]+)$|$1|;
     1057        $pkgdata{main}{source} =~ s|^.+/([^/]+)$|$sval|;
     1058        $pkgdata{sources}{0} = $pkgdata{main}{source};
    9651059        # .tar, .tar.gz, .tar.bz2, .tgz, .xz
    9661060        die "Unknown tarball format $1\n" if $1 !~ /\.(?:tar(?:\.(?:gz|bz2|xz))?|tgz)$/;
  • trunk/debbuild.spec

    r181 r182  
    5757%if %{_vendor} == "debbuild"
    5858Recommends: patch, bzip2
     59# For setting DEB_HOST_ARCH
     60Recommends: dpkg-architecture
    5961Suggests: rpm, subversion
    6062%endif
Note: See TracChangeset for help on using the changeset viewer.