- new deptransfrom script to automatically create a debian diff file
authorMichael Schröder <mls@suse.de>
Thu, 8 Mar 2007 15:47:37 +0000 (15:47 +0000)
committerMichael Schröder <mls@suse.de>
Thu, 8 Mar 2007 15:47:37 +0000 (15:47 +0000)
- fix host setting in XEN
- fix changelog setting in XEN
- add vminstall config parameter

Build.pm
build
changelog2spec
debtransform [new file with mode: 0755]
init_buildsystem

index bd465c1..e9c196e 100644 (file)
--- a/Build.pm
+++ b/Build.pm
@@ -9,6 +9,7 @@ use Digest::MD5;
 use Build::Rpm;
 use Build::Deb;
 
+
 my $std_macros = q{
 %define ix86 i386 i486 i586 i686 athlon
 %define arm armv4l armv4b armv5l armv5b armv5tel armv5teb
@@ -73,6 +74,7 @@ sub read_config {
   my @spec;
   Build::Rpm::parse($config, \@newconfig, \@spec);
   $config->{'preinstall'} = [];
+  $config->{'vminstall'} = [];
   $config->{'runscripts'} = [];
   $config->{'required'} = [];
   $config->{'support'} = [];
@@ -96,7 +98,7 @@ sub read_config {
       $config->{'rawmacros'} .= $l;
       next;
     }
-    if ($l0 eq 'preinstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') {
+    if ($l0 eq 'preinstall:' || $l0 eq 'vminstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') {
       push @{$config->{substr($l0, 0, -1)}}, @l;
     } elsif ($l0 eq 'substitute:') {
       next unless @l;
@@ -112,7 +114,7 @@ sub read_config {
       warn("unknown keyword in config: $l0\n");
     }
   }
-  for my $l (qw{preinstall required support keep runscripts repotype}) {
+  for my $l (qw{preinstall vminstall required support keep runscripts repotype}) {
     $config->{$l} = [ unify(@{$config->{$l}}) ];
   }
   for my $l (keys %{$config->{'substitute'}}) {
@@ -222,6 +224,11 @@ sub get_preinstalls {
   return @{$config->{'preinstall'}};
 }
 
+sub get_vminstalls {
+  my ($config) = @_;
+  return @{$config->{'vminstall'}};
+}
+
 sub get_runscripts {
   my ($config) = @_;
   return @{$config->{'runscripts'}};
diff --git a/build b/build
index b80f8ad..b6f9d61 100755 (executable)
--- a/build
+++ b/build
@@ -214,6 +214,7 @@ if test "$0" = "/.build/build" ; then
     fi
     set "/.build-srcdir/$SPECFILE"
     HOST="$MYHOSTNAME"
+    export HOST
 fi
 
 while test -n "$1"; do
@@ -534,10 +535,15 @@ for SPECFILE in $SPECFILES ; do
         DO_INIT=true
     fi
 
-    if test -n "$CHANGELOG" ; then
+    if test -n "$CHANGELOG" -a -z "$RUNNING_IN_XEN" ; then
        rm -f $BUILD_ROOT/.build-changelog
-       if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
-           $BUILD_DIR/changelog2spec --spec "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog || rm -f $BUILD_ROOT/.build-changelog
+       case $SPECFILE in
+         *.dsc) CFFORMAT=debian ;;
+         *) CFFORMAT=rpm ;;
+       esac
+       echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
+       if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
+           rm -f $BUILD_ROOT/.build-changelog
        fi
     fi
 
@@ -569,6 +575,7 @@ for SPECFILE in $SPECFILES ; do
        echo "NOROOTFORBUILD='${NOROOTFORBUILD//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
        echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
        echo "REASON='${REASON//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
+       echo "CHANGELOG='${CHANGELOG//\'/$Q}'" >> $BUILD_ROOT/.build/build.data
        test -n "$XENSWAP" && echo "XENSWAP='/dev/hda2'" >> $BUILD_ROOT/.build/build.data
        PERSONALITY_SYSCALL=
        PERSONALITY=0
@@ -654,7 +661,9 @@ for SPECFILE in $SPECFILES ; do
             mkdir -p $BUILD_ROOT/home/abuild
             chown 99:99 $BUILD_ROOT/home/abuild
         fi
-       sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
+       if test -f $BUILD_ROOT/etc/shadow ; then
+           sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
+       fi
     else
         if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
             egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
@@ -681,10 +690,11 @@ for SPECFILE in $SPECFILES ; do
     cp -p $MYSRCDIR/* $BUILD_ROOT$TOPDIR/SOURCES/
     test $MYSRCDIR = $BUILD_ROOT/.build-srcdir && rm -rf $MYSRCDIR
 
+    CHANGELOGARGS=
+    test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
+
     if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
        # do buildrequires/release substitution
-       CHANGELOGARGS=
-       test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
        substitutedeps $RELEASE --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
        # extract macros from configuration
        getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
@@ -707,7 +717,18 @@ for SPECFILE in $SPECFILES ; do
     if test "$SPECFILE" != "${SPECFILE%.dsc}" ; then
        rm -rf $BUILD_ROOT$TOPDIR/BUILD
        test $BUILD_USER = abuild && chown 99:99 $BUILD_ROOT$TOPDIR
-       chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES/$SPECFILE $TOPDIR/BUILD" - $BUILD_USER
+       DEB_TRANSFORM=
+       for f in $TOPDIR/SOURCES/debian.* ; do
+           test -f $f && DEB_TRANSFORM=true
+       done
+       if test -n $DEB_TRANSFORM ; then
+           mkdir -p $TOPDIR/SOURCES.DEB
+            debtransform $CHANGELOGARGS $TOPDIR/SOURCES $TOPDIR/SOURCES/$SPECFILE $TOPDIR/SOURCES.DEB
+           chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES.DEB/*.dsc $TOPDIR/BUILD" - $BUILD_USER
+           rm -rf $TOPDIR/SOURCES.DEB
+        else
+           chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES/$SPECFILE $TOPDIR/BUILD" - $BUILD_USER
+        fi
     fi
     if test $BUILD_USER = abuild ; then
         chown -R 99:99 $BUILD_ROOT$TOPDIR/*
index 1f6b18b..7015cd6 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #
-# Convert a SUSE changelog file to rpm format
+# Convert a SUSE or Debian changelog file to rpm format
 #
 
 use Date::Parse;
@@ -12,40 +12,213 @@ use strict;
 my @wday = qw{Sun Mon Tue Wed Thu Fri Sat};
 my @mon = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};
 
-if (@ARGV == 2 && $ARGV[0] eq '--spec') {
-  die("bad --spec arg\n") unless $ARGV[1] =~ /^(.*)\/([^\/]+)\.spec$/;
-  my ($dir, $spec) = ($1, $2);
+
+my $ok;
+my $zone;
+my $test;
+my $printtype;
+my $input = '';
+my $target = 'rpm';
+
+while (@ARGV) {
+  if ($ARGV[0] eq '--test') {
+    $test = 1;
+    shift @ARGV;
+    next;
+  }
+  if ($ARGV[0] eq '--type') {
+    $printtype = 1;
+    shift @ARGV;
+    next;
+  }
+  if (@ARGV > 1 && $ARGV[0] eq '--target') {
+    shift @ARGV;
+    $target = shift @ARGV;
+    next;
+  }
+  last;
+}
+
+if (@ARGV == 2 && $ARGV[0] eq '--file') {
+  die("bad --file arg\n") unless $ARGV[1] =~ /^(.*)\/([^\/]+)$/;
+  my ($dir, $file) = ($1, $2);
+  $file =~ s/\.(?:spec|dsc)$//;
   opendir(D, $dir) || die("$dir: $!\n");
   my @changes = grep {/\.changes$/} readdir(D);
   closedir(D);
   @changes = sort {length($a) <=> length($b) || $a cmp $b} @changes;
-  exit(1) unless @changes;
+  exit(1) unless @changes;     # nothing to do
   if (@changes > 1) {
-    while ($spec ne '') {
-      my @c = grep {/\Q$spec\E/} @changes;
+    while ($file ne '') {
+      my @c = grep {/\Q$file\E/} @changes;
       if (@c) {
        @changes = @c;
        last;
       }
-      last unless $spec =~ s/[-.][^-.]*$//;
+      last unless $file =~ s/[-.][^-.]*$//;
     }
   }
   @ARGV = ("$dir/$changes[0]");
 }
 
-my $ok;
-my $zone;
-my $test;
-if ($ARGV[0] eq '--test') {
-  $test = 1;
-  shift @ARGV;
+sub parse_suse {
+  $_ = $_[0];
+
+  my $dline;
+  die("bad changelog heading\n") unless /^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/;
+  my $dt = $1;
+  my $who = $2;
+  $dt = lc($dt);
+  $who =~ s/^\s+//;
+  $who =~ s/^-\s*//;
+  $dt =~ /([0-9][0-9][0-9][0-9])/;
+  $dline = $_;
+  my $year = $1;
+  if (!defined($zone) && $dt =~ /\s([a-z]{3,4})(dst)?\s[0-9]{4}/) {
+    my $dst = $2;
+    $zone = tz_offset($1);
+    $zone += 3600 if defined($zone) && $dst;
+  }
+  my $tdt = str2time($dt);
+  $dt =~ /([0-9]+)/;
+  my $day = $1;
+  if (!$tdt) {
+    if ($dt =~ /([a-z]{3})\s+([a-z]{3})/) {
+      $tdt = str2time("$1 $2 $day $year");
+    }
+  }
+  if (!$tdt) {
+    if ($dt =~ /([a-z]{3})/) {
+      $tdt = str2time("$1 $day $year");
+    }
+  }
+  if (!$tdt) {
+    $tdt = str2time("$year-1-1");
+  }
+  $tdt += 12 * 3600 unless $dt =~ /\d:\d/;     # 12:00 if not specified
+  $tdt += ($zone || 0);
+  my $ok = 1;
+  my $change = '';
+  while(<>) {
+    chomp;
+    last if /^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/;
+    next if (/^--------------/);
+    next if (/^========================/);
+    s/\s+$//;
+    next if $_ eq '';
+    s/^\s*-/-/ if $ok == 1;    # obsolete?
+    s/^\s*\*\s*/  * /;
+    if (!/^-/) {
+      s/^\s+-\s*/  - /;
+      s/^\s*/  / unless s/^    \s*/    /;
+    }
+    $change .= "$_\n";
+    $ok = 2;
+  }
+  return ($_, $tdt, $dline, $who, $change);
 }
-my $lastt;
+
+sub parse_debian {
+  $_ = $_[0];
+  
+  die("bad line: $_\n") unless /^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-+0-9a-z.]+)+)\;.*$/;
+  my $package = $1;
+  my $version = $2;
+  my $distribution = $3;
+  my $who;
+  my $date;
+  my $changes = "- version $version\n";
+  while(<>) {
+    chomp;
+    s/\s+$//;
+    next if $_ eq '';
+    if (/^ --/) {
+      die("bad maintainer line\n") unless /^ \-\- (.* <.*>)  (.*)$/;
+      $who = $1;
+      $date = $2;
+      last;
+    }
+    die("bad change details line: $_\n") unless s/^  //;
+    s/^\*/-/;
+    s/\s*\(closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*\)//i;
+    s/\s+$//;
+    next if $_ eq '';
+    $changes .= "$_\n";
+  }
+  die("no maintainer line in last entry\n") unless defined $date;
+  if (!defined($zone) && ($date =~ /([-+])(\d\d)(\d\d)$/)) {
+    $zone = 60 * ($3 + 60 * $2);
+    $zone = -$zone if $1 eq '-';
+  }
+  my $tdt = str2time($date);
+  return ('', $tdt, $_, $who, $changes);
+}
+
+my $format;
 while (<>) {
   chomp;
+  next if /^\s*$/;
   next if (/^--------------/);
   next if (/^========================/);
   if (/^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/) {
+    $format = 'suse';
+    
+  } elsif (/^(\w[-+0-9a-z.]*) \(([^\(\) \t]+)\)((\s+[-+0-9a-z.]+)+)\;.*$/) {
+    $format = 'debian';
+  } else {
+    die("unknown changelog format\n");
+  }
+  last;
+}
+exit(0) unless $format;
+
+if ($printtype) {
+  print "$format\n";
+  exit(0);
+}
+
+if ($target eq $format) {
+  print "$_\n";
+  while (<>) {
+    print $_;
+  }
+  exit(0);
+}
+
+die("don't know how to convert changelog to format '$target'\n") if $target ne 'rpm';
+
+my ($lastt, $t, $dline, $who, $changes);
+while(defined($_)) {
+  if (/^\s*$/) {
+    $_ = <>;
+    last unless $_;
+    chomp;
+    next;
+  }
+  if ($format eq 'suse') {
+    ($_, $t, $dline, $who, $changes) = parse_suse($_);
+  } elsif ($format eq 'debian') {
+    ($_, $t, $dline, $who, $changes) = parse_debian($_);
+  }
+  if (defined($lastt) && $lastt < $t) {
+    die("changes file not incremental: $dline\n") if $test;
+    warn("changes file not incremental: $dline\n");
+  }
+  $lastt = $t;
+  my @gm = gmtime($t);
+  @gm = (0, 0, 0, 2, 0, 97, 4) if $gm[5] < 97 || ($gm[5] == 97 && $gm[3] <= 1);
+  printf("* %s %s %2d %4d %s\n", $wday[$gm[6]], $mon[$gm[4]], $gm[3], $gm[5] + 1900, $who);
+  $changes =~ s/%/%%/g;
+  $changes =~ s/^(\s*)(\#\d*)/$1\[$2\]/mg;
+  $changes =~ s/^\*/  */mg;
+  print $changes;
+}
+exit(0);
+
+
+while (<>) {
+  chomp;
+  if (/^(?:\* )?([A-Za-z]+\s+[A-Za-z]+\s+[0-9].*[0-9][0-9][0-9][0-9])(.*\@.*$)/) {
     my $dt = $1;
     my $who = $2;
     $dt = lc($dt);
@@ -90,6 +263,8 @@ while (<>) {
     next;
   }
   next unless $ok;
+  next if (/^--------------/);
+  next if (/^========================/);
   s/\s+$//;
   next if $_ eq '';
   s/%/%%/g;
diff --git a/debtransform b/debtransform
new file mode 100755 (executable)
index 0000000..d1533cb
--- /dev/null
@@ -0,0 +1,258 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Digest::MD5;
+
+sub parsedsc {
+  my ($fn) = @_;
+  my @control;
+  local *F;
+  open(F, '<', $fn) || die("$fn: $!\n");
+  @control = <F>;
+  close F;
+  chomp @control;
+  splice(@control, 0, 3) if @control > 3 && $control[0] =~ /^-----BEGIN/;
+  my @seq = ();
+  my %tag;
+  while (@control) {
+    my $c = shift @control;
+    last if $c eq '';   # new paragraph
+    my ($tag, $data) = split(':', $c, 2);
+    next unless defined $data;
+    push @seq, $tag;
+    $tag = uc($tag);
+    while (@control && $control[0] =~ /^\s/) {
+      $data .= "\n".substr(shift @control, 1);
+    }
+    $data =~ s/^\s+//s;
+    $data =~ s/\s+$//s;
+    $tag{$tag} = $data;
+  }
+  $tag{'__seq'} = \@seq;
+  return \%tag;
+}
+
+sub writedsc {
+  my ($fn, $tags) = @_;
+  open(F, '>', $fn) || die("$fn: $!\n");
+  my @seq = @{$tags->{'__seq'} || []};
+  my %seq = map {uc($_) => 1} @seq;
+  for (sort keys %$tags) {
+    push @seq, ucfirst(lc($_)) unless $seq{$_};
+  }
+  for my $seq (@seq) {
+    my $ucseq = uc($seq);
+    my $d = $tags->{$ucseq};
+    next unless defined $d;
+    $d =~ s/\n/\n /sg;
+    print F "$seq: $d\n";
+  }
+  print F "\n";
+  close F;
+}
+
+sub listtar {
+  my ($tar) = @_;
+  local *F;
+  my @c;
+  open(F, '-|', 'tar', '--numeric-owner', '-tvf', $tar) || die("tar: $!\n");
+  while(<F>) {
+    next unless /^([-dlbcp])(.........)\s+\d+\/\d+\s+(\S+) \d\d\d\d-\d\d-\d\d \d\d:\d\d(?::\d\d)? (.*)$/;
+    my ($type, $mode, $size, $name) = ($1, $2, $3, $4);
+    next if $type eq 'd';
+    die("debian tar contains link: $name\n") if $type eq 'l';
+    die("debian tar contains unexpected file type: $name\n") if $type ne '-';
+    $name =~ s/^\.\///;
+    $name =~ s/^debian\///;
+    push @c, {'name' => $name, 'size' => $size};
+  }
+  close(F) || die("tar: $!\n");
+  return @c;
+}
+
+sub dotar {
+  my ($tar, $tardir, @c) = @_;
+  local *F;
+  open(F, '-|', 'tar', '-xOf', $tar) || die("tar: $!\n");
+  for my $c (@c) {
+    my $s = $c->{'size'};
+    my $file = '';
+    while ($s > 0) {
+      my $l = sysread(F, $file, $s, length($file));
+      die("tar read error\n") unless $l;
+      $s -= $l;
+    }
+    my @file = split("\n", $file);
+    print DIFF "--- $tardir.orig/debian/$c->{'name'}\n";
+    print DIFF "+++ $tardir/debian/$c->{'name'}\n";
+    next unless @file;
+    print DIFF "\@\@ -0,0 +1,".scalar(@file)." \@\@\n";
+    print DIFF "+$_\n" for @file;
+  }
+  close(F);
+}
+
+sub dofile {
+  my ($file, $tardir, $dfile) = @_;
+  local *F;
+  if (!defined($dfile)) {
+    $dfile = $file;
+    $dfile =~ s/.*\///;
+    $dfile =~ s/\./\//;
+  }
+  open(F, '<', $file) || die("$file: $!\n");
+  my @file = <F>;
+  close F;
+  chomp(@file);
+  print DIFF "--- $tardir.orig/$dfile\n";
+  print DIFF "+++ $tardir/$dfile\n";
+  return unless @file;
+  print DIFF "\@\@ -0,0 +1,".scalar(@file)." \@\@\n";
+  print DIFF "+$_\n" for @file;
+}
+
+sub doseries {
+  my ($series, $tardir) = @_;
+  my $dir = $series;
+  $dir =~ s/[^\/]+$//;
+  $dir =~ s/\/+$//;
+  $dir = '.' if $dir eq '';
+  local *F;
+  open(F, '<', $series) || die("$series: $!\n");
+  my @series = <F>;
+  close F;
+  chomp(@series);
+  for my $patch (@series) {
+    $patch =~ s/(^|\s+)#.*//;
+    next if $patch =~ /^\s*$/;
+    my $level = 1;
+    $level = $1 if $patch =~ /\s.*-p\s*(\d+)/;
+    $patch =~ s/\s.*//;
+    open(F, '<', "$dir/$patch") || die("$dir/$patch: $!\n");
+    while(<F>) {
+      chomp;
+      if ((/^--- ./ || /^\+\+\+ ./) && !/^... \/dev\/null/) {
+        my $start = substr($_, 0, 4);
+        $_ = substr($_, 4);
+        my $l = $level;
+        while ($l > 0) {
+         last unless s/.*?\///;
+         $l--;
+       }
+        if ($start eq '--- ') {
+          print DIFF "$start$tardir.orig/$_\n";
+       } else {
+          print DIFF "$start$tardir/$_\n";
+       }
+       next;
+      }
+      print DIFF "$_\n";
+    }
+    close F;
+  }
+}
+
+sub addfile {
+  my ($file) = @_;
+  my $base = $file;
+  $base =~ s/.*\///;
+  local *F;
+  open(F, '<', $file) || die("$file: $!\n");
+  my $size = -s F;
+  my $ctx = Digest::MD5->new;
+  $ctx->addfile(*F);
+  close F;
+  my $md5 = $ctx->hexdigest();
+  return "$md5 $size $base";
+}
+
+my $changelog;
+
+if (@ARGV > 1 && $ARGV[0] eq '--changelog') {
+  shift @ARGV;
+  $changelog = shift @ARGV;
+}
+die("usage: debtransform [--changelog <changelog>] <srcdir> <dscfile> <outdir>\n") unless @ARGV == 3;
+
+my $dir = $ARGV[0];
+my $dsc = $ARGV[1];
+my $out = $ARGV[2];
+
+die("$out: $!\n") unless -d $out;
+
+opendir(D, $dir) || die("$dir: $!\n");
+my @dir = grep {$_ ne '.' && $_ ne '..'} readdir(D);
+closedir(D);
+my %dir = map {$_ => 1} @dir;
+
+my @tars = grep {/\.tar(?:\.gz|\.bz2)?$/} @dir;
+my @debtars = grep {/^debian\.tar(?:\.gz|\.bz2)?$/} @tars;
+@tars = grep {!/^debian\.tar(?:\.gz|\.bz2)?$/} @tars;
+die("package contains no tar file\n") unless @tars;
+die("package contains more than one tar file: @tars\n") if @tars > 1;
+die("package contains more than one debian tar file\n") if @debtars > 1;
+my $tarfile = $tars[0];
+my $debtarfile = $debtars[0];
+
+my $tags = parsedsc($dsc);
+my $name = $tags->{'SOURCE'};
+die("dsc file contains no source\n") unless defined($name);
+my $version = $tags->{'VERSION'};
+die("dsc file contains no version\n") unless defined($version);
+
+my $tardir = $tarfile;
+$tardir =~ s/\.orig\.tar/\.tar/;
+$tardir =~ s/\.tar.*?$//;
+
+my @files;
+my $v = $version;
+$v =~ s/-[^-]*$//;
+$tarfile =~ /.*(\.tar.*?)$/;
+my $ntarfile = "${name}_$v.orig$1";
+link("$dir/$tarfile", "$out/$ntarfile") || die("link $dir/$tarfile $out/$ntarfile: $!\n");
+push @files, addfile("$out/$ntarfile");
+
+open(DIFF, '>', "$out/${name}_$version.diff") || die("$out/${name}_$version.diff: $!\n");
+
+undef $changelog if $dir{'debian.changelog'};
+
+if ($debtarfile) {
+  my @c = listtar($debtarfile);
+  for (@c) {
+    die("debian tar and directory both contain '$_->{'name'}'\n") if $dir{"debian.$_->{'name'}"};
+    undef $changelog if $_->{'name'} eq 'changelog';
+  }
+  dofile($changelog, $tardir, "debian/changelog") if defined $changelog;
+  undef $changelog;
+  dotar($debtarfile, $tardir, @c);
+}
+
+dofile($changelog, $tardir, "debian/changelog") if defined $changelog;
+
+for my $file (grep {/^debian\./} @dir) {
+  next if $file =~ /^debian\.tar/;
+  next if $file eq 'debian.series';
+  dofile("$dir/$file", $tardir);
+}
+
+if ($dir{"debian.series"}) {
+  doseries("$dir/debian.series", $tardir);
+} elsif ($dir{"patches.series"}) {
+  doseries("$dir/patches.series", $tardir);
+}
+
+close(DIFF);
+
+if (! -s "$out/${name}_$version.diff") {
+  unlink("$out/${name}_$version.diff");
+} else {
+  system('gzip', '-9', "$out/${name}_$version.diff");
+  if (-f "$out/${name}_$version.diff.gz") {
+    push @files, addfile("$out/${name}_$version.diff.gz");
+  } else {
+    push @files, addfile("$out/${name}_$version.diff");
+  }
+}
+
+$tags->{'FILES'} = "\n".join("\n", @files);
+writedsc("$out/${name}_$version.dsc", $tags);
index 0585a36..fcfcedc 100755 (executable)
@@ -671,7 +671,7 @@ if test -e $BUILD_ROOT/usr/share/zoneinfo/UTC ; then
     chroot $BUILD_ROOT zic -l UTC
 fi
 
-HOST=`hostname`
+test -e $BUILD_ROOT/.build/init_buildsystem.data || HOST=`hostname`
 test -e $BUILD_ROOT/etc/hosts || echo "127.0.0.1 localhost" > $BUILD_ROOT/etc/hosts
 if ! grep -F "127.0.0.1 $HOST" $BUILD_ROOT/etc/hosts > /dev/null ; then
     # this makes a reverse lookup on 127.0.0.1 return the host name,