~ubuntu-branches/ubuntu/feisty/svn-buildpackage/feisty

« back to all changes in this revision

Viewing changes to svn-buildpackage

  • Committer: Bazaar Package Importer
  • Author(s): Eduard Bloch
  • Date: 2005-06-22 22:58:16 UTC
  • mfrom: (1.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050622225816-3xp527bqyy0gfhel
Tags: 0.6.9
using "cp" for .orig.tar.gz copying again, more reliable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl
2
2
# (c) Eduard Bloch <blade@debian.org>, 2003
3
3
# License: GPL
4
 
# Version: $Id: svn-buildpackage 1385 2005-01-02 20:04:57Z inet $
 
4
# Version: $Id: svn-buildpackage 1563 2005-03-29 01:26:46Z inet $
5
5
 
6
6
#use Getopt::Long;
7
7
use Getopt::Long qw(:config no_ignore_case bundling pass_through);
32
32
  --svn-move-to XYZ  move package files to XYZ, implies --svn-move
33
33
  --svn-only-tag     Tags the current trunk directory without building
34
34
  --svn-tag          Final build: Export && build && tag && dch -i
 
35
  --svn-retag        replace an existing tag directory if found while tagging
35
36
  --svn-lintian      Run lintian in the build area when done
36
37
  --svn-pkg PACKAGE  Specifies the package name
 
38
  --svn-export       Just prepares the build directory and exits
 
39
  --svn-reuse        Reuse an existing build directory, copy trunk over it
37
40
 
38
41
If the debian directory has the mergeWithUpstream property, svn-buildpackage
39
42
will extract .orig.tar.gz file first and add the Debian files to it.
45
48
my $opt_verbose;
46
49
my $opt_dontclean;
47
50
my $opt_dontpurge;
 
51
my $opt_reuse;
48
52
my $opt_ignnew;
49
53
my $opt_tag;
50
54
my $opt_only_tag;
55
59
my $opt_posttag;
56
60
my $opt_postbuild;
57
61
my $opt_buildcmd;
 
62
my $opt_export;
58
63
my $opt_pass_diff;
59
64
my @opt_override;
60
65
my $opt_move;
63
68
%options = (
64
69
   "h|help"                => \$opt_help,
65
70
   "svn-verbose"           => \$opt_verbose,
66
 
   "svn-ignore-new"        => \$opt_ignnew,
 
71
   "svn-ignore-new|svn-ignore"        => \$opt_ignnew,
67
72
   "svn-dont-clean"        => \$opt_dontclean,
 
73
   "svn-export"            => \$opt_export,
68
74
   "svn-dont-purge"        => \$opt_dontpurge,
 
75
   "svn-reuse"             => \$opt_reuse,
69
76
   "svn-only-tag"               => \$opt_only_tag,
70
77
   "svn-tag-only"               => \$opt_only_tag,
71
78
   "svn-tag"               => \$opt_tag,
 
79
   "svn-retag"               => \$opt_retag,
72
80
   "svn-lintian"           => \$opt_lintian,
73
81
   "svn-no-links"          => \$opt_nolinks,
74
82
   "svn-pass-diff"          => \$opt_pass_diff,
88
96
   "svn-pkg=s"             => \$package
89
97
);
90
98
 
 
99
use lib "/usr/share/svn-buildpackage";
 
100
use SDCommon;
 
101
SDCommon::init;
 
102
 
 
103
sub setenv {
 
104
   ($key, $val) = @_;
 
105
   return 0 if(!defined($val));
 
106
   print "ENV: $key=$val\n" if $opt_verbose;
 
107
   $ENV{$key}=$val;
 
108
}
 
109
 
 
110
sub setallenv {
 
111
   $tagVersion=$SDCommon::tagVersion;
 
112
   $upVersion=$SDCommon::upVersion;
 
113
   $tagVersionNonEpoch = $tagVersion;
 
114
   $tagVersionNonEpoch =~ s/^[^:]*://;
 
115
 
 
116
   #this sucks but the config file needs to be processed before the options and there should be reasonable default
 
117
   setenv("PACKAGE", defined($package) ? $package : $SDCommon::package);
 
118
   setenv("package", defined($package) ? $package : $SDCommon::package);
 
119
   setenv "TAG_VERSION", $tagVersion;
 
120
   setenv "debian_version", $tagVersion;
 
121
   setenv "non_epoch_version", $tagVersionNonEpoch;
 
122
   setenv "upstream_version", $upVersion;
 
123
   setenv "SVN_BUILDPACKAGE", $SDCommon::version;
 
124
   setenv "guess_loc", ( ($package=~/^(lib.)/)?$1:substr($package,0,1))."/$package"."_$upVersion.orig.tar.gz";
 
125
}
 
126
 
 
127
&setallenv;
 
128
 
91
129
if(open($rc, "<".$ENV{"HOME"}."/.svn-buildpackage.conf")) {
92
130
   SKIP: while(<$rc>) {
93
131
      chomp;
99
137
         s/^(\S+)\s*=\s*/$1=/;
100
138
         # convert to options and push to args
101
139
         s/^/--/;
 
140
         $_=`echo -n $_` if(/[\$`~]/);
102
141
         push(@CONFARGS, $_);
103
142
      }
104
143
   }
116
155
# if opt_only_tag is used, set opt_tag too. Should not hurt because the
117
156
# real function of opt_tag at the end of the script is never reached
118
157
$opt_tag = 1 if($opt_only_tag);
119
 
 
120
158
$opt_move=1 if $opt_move_to;
121
159
$destdir=long_path($opt_move_to ? $opt_move_to : "$startdir/..");
122
 
 
123
 
use lib "/usr/share/svn-buildpackage";
124
 
use SDCommon;
125
160
$SDCommon::opt_verbose=$opt_verbose;
 
161
$package = $SDCommon::package if(!$package);
 
162
 
126
163
withecho "fakeroot debian/rules clean || debian/rules clean" if(!$opt_dontclean);
127
164
SDCommon::check_uncommited if(!$opt_ignnew);
128
165
 
129
 
if($opt_buildcmd) {
 
166
SDCommon::configure;
 
167
needs_tagsUrl if($opt_tag);
 
168
$c=\%SDCommon::c;
 
169
 
 
170
#some things may have been overriden by user options
 
171
&setallenv;
 
172
 
 
173
 
 
174
if($opt_buildcmd || $opt_export) {
130
175
   @builder = split / /, $opt_buildcmd;
131
 
 
176
   if($opt_buildcmd=~/;|\||&/) {
 
177
      print "I: Looks like a shell construct in the build command, running trough the shell\n";
 
178
      #@builder = (join(" ", @builder, @ARGV));
 
179
      # become a single command again and let perl run it trough the shell
 
180
      $cmd=$opt_buildcmd." ".join(" ", @ARGV);
 
181
      #print "wtf, $cmd\n";
 
182
      @builder = ($cmd);
 
183
      undef @ARGV;
 
184
   }
 
185
}
132
186
else {
133
187
   push(@builder, "dpkg-buildpackage");
134
188
   # a simple "helper". Only executed if no custom command is choosen and
147
201
   die "Aborting now, set \$FORCETAG to ignore it.\n" if($opt_tag && !$ENV{"FORCETAG"});
148
202
}
149
203
 
150
 
SDCommon::configure;
151
 
needs_tagsUrl if($opt_tag);
152
 
$c=\%SDCommon::c;
153
 
$tagVersion=$SDCommon::tagVersion;
154
 
$upVersion=$SDCommon::upVersion;
155
 
 
156
 
$ENV{"TAG_VERSION"} = $tagVersion;
157
 
$ENV{"PACKAGE"}=$SDCommon::package;
158
 
$package = $SDCommon::package if(!$package);
159
 
 
160
204
@opt_override = split(/,|\ |\r|\n/,join(',',@opt_override));
161
205
for(@opt_override) {
162
206
   $SDCommon::nosave=1;
169
213
   }
170
214
}
171
215
 
 
216
sub checktag {
 
217
   if(insvn($$c{"tagsUrl"}."/$tagVersion")) {
 
218
      if($opt_retag) {
 
219
         withecho ("svn", "-m", "$scriptname Removing old tag $package-$tagVersion", "rm", $$c{"tagsUrl"}."/$tagVersion");
 
220
      }
 
221
      else {
 
222
         die "Could not create tag copy\n".
 
223
         $$c{"tagsUrl"}."/$tagVersion - it
 
224
does already exist. Add the --svn-retag option to replace that tag.\n";
 
225
      }
 
226
   }
 
227
}
 
228
 
 
229
for(keys %{$c}) {
 
230
   $val=$$c{$_};
 
231
   setenv $_, $$c{$_};
 
232
}
 
233
 
172
234
if($opt_only_tag) {
 
235
   checktag;
173
236
   chdir $$c{"trunkDir"};
174
237
   system "$opt_pretag" if($opt_pretag);
175
238
   withecho ("svn", "-m", "$scriptname Tagging $package ($tagVersion)", "cp", $$c{"trunkUrl"}, $$c{"tagsUrl"}."/$tagVersion");
179
242
   SDCommon::sd_exit 0;
180
243
}
181
244
 
182
 
$tagVersionNonEpoch = $tagVersion;
183
 
$tagVersionNonEpoch =~ s/^[^:]*://;
 
245
print "D: ",$opt_prebuild if $opt_verbose;
184
246
 
185
247
system "$opt_prebuild" if($opt_prebuild);
186
248
 
199
261
$ba=$$c{"buildArea"};
200
262
$bdir="$ba/$package-$upVersion";
201
263
 
202
 
if(-e "$bdir") {
 
264
if(!$opt_reuse && -e "$bdir") {
203
265
   $backupNr=rand;
204
266
   print STDERR "$bdir exists, renaming to $bdir.obsolete.$backupNr\n";
205
267
   rename("$bdir","$bdir.obsolete.$backupNr");
211
273
   print "mergeWithUpstream mode detected, looking for $origExpect\n";
212
274
}
213
275
 
 
276
# gets the upstream branch out of svn into .orig directory
214
277
sub exportToOrigDir {
215
278
   # no upstream source export by default and never in mergeWithUpstream mode
216
279
   if((!$ENV{"FORCEEXPORT"}) || `svn proplist debian` =~ /mergeWithUpstream/i) {
220
283
   $upsVersUrl=$$c{"upsTagUrl"}."/$upVersion";
221
284
   defined($$c{"upsCurrentUrl"}) || print STDERR "upsCurrentUrl not set and not located, expect problems...\n";
222
285
   withecho("rm", "-rf", "$bdir.orig");
223
 
   withecho "svn","export",$$c{"upsCurrentUrl"},"$bdir.orig";
 
286
   withecho "svn", "export",$$c{"upsCurrentUrl"},"$bdir.orig";
224
287
}
225
288
 
 
289
# non-Debian-native package detected, needing some kind of upstream source for
 
290
# dpkg-buildpackage (most likely, spew error messages but continue on native
 
291
# packages with dashes)
226
292
if($tagVersion =~ /-/) {
227
293
   my $abs_origfile=long_path($origfile);
228
294
   my $orig_target="$ba/".$orig;
265
331
   }
266
332
}
267
333
 
268
 
# let's make svn play "cp -l"
 
334
# contents examination for "cp -l" emulation
269
335
print STDERR "Creating file list...\n" if $opt_verbose;
270
336
open($stat, "svn status -v |");
271
337
while(<$stat>) {
272
 
   if(/^[^\?].*\s+(\S+)\n/) {
 
338
   if(/^[^\?].*\d+\s+\d+\s+\S+\s+(.*)\n/) {
273
339
      $_=$1;
274
340
      if ($_ ne ".") {
275
341
         if(-d $_) {
280
346
            push(@files,$_); 
281
347
            print STDERR "FILE: $_\n" if $opt_verbose;
282
348
         }
 
349
         s#/$##;
 
350
         push(@stuff, $_);
283
351
      }
284
352
   }
285
353
}
286
354
 
 
355
# sub cpl {
 
356
#    ($from, $to) = @_;
 
357
#    for(@dirs) {$_="$from/$_"}
 
358
#    for(@files){$_="$from/$_"}
 
359
#    
 
360
#    system "cd $bdir && mkdir -p ".join(' ',@dirs)) +
 
361
#          system "cp", "--parents", "-laf", @files), "$bdir/") ;
 
362
#       }
 
363
 
287
364
if(`svn proplist debian` =~ /mergeWithUpstream/i) {
288
 
   # debian is the only directory or during-build-merging is wanted
289
365
   print STDERR "I: mergeWithUpstream property set, looking for upstream source tarball...\n";
290
366
   die "E: Could not find the origDir directory, please check the settings!\n" if(! -e $$c{"origDir"});
291
367
   die "E: Could not find the upstream source file! (should be $origExpect)\n" if(! ($origfile && -e $origfile));
292
368
   $mod=rand;
293
369
   mkdir "$ba/tmp-$mod";
294
 
   withecho "tar", "zxf", $origfile, "-C", "$ba/tmp-$mod";
295
 
   withecho "mv $ba/tmp-$mod/* $bdir";
296
 
   withecho "rm", "-rf", "$ba/tmp-$mod";
 
370
   if($opt_reuse && -d $bdir) {
 
371
      print "Reusing old build directory\n" if $opt_verbose;
 
372
   }
 
373
   else {
 
374
      withecho "tar", "zxf", $origfile, "-C", "$ba/tmp-$mod";
 
375
      withecho "mv", (<$ba/tmp-$mod/*>), $bdir;
 
376
   }
297
377
   if($opt_nolinks || $opt_ignnew) {
298
 
      withecho ("svn", "export", $$c{"trunkDir"},"$ba/tmp-$mod");
299
 
      withecho "cp", "-af", "$ba/tmp-$mod/.", "$bdir/";
 
378
      withecho ("svn", "--force", "export", $$c{"trunkDir"},"$bdir");
300
379
   }
301
380
   else {
302
 
      if( (system "cd $bdir && mkdir -p ".join(' ',@dirs)) +
303
 
         system "cp --parents -laf ".join(' ',@files)." $bdir/") {
304
 
         # 0=good; but if pure copy failed...
305
 
         withecho ("svn", "export", $$c{"trunkDir"},"$ba/tmp-$mod");
306
 
         withecho "cp", "-af", "$ba/tmp-$mod/.", "$bdir/";
 
381
      mkdir $bdir;
 
382
      #fixme maybe rewrite to withecho
 
383
      if( system("mkdir","-p", map { "$bdir/$_" } @dirs) + system ("cp", "--parents", "-laf", @files, $bdir) ) 
 
384
      { # cp failed...
 
385
         withecho "svn", "--force", "export", $$c{"trunkDir"},"$bdir";
307
386
      }
308
387
   }
309
388
   withecho "rm", "-rf", "$ba/tmp-$mod";
310
389
}
311
390
else {
312
391
   if($opt_nolinks) {
313
 
      withecho "svn","export",$$c{"trunkDir"},"$bdir";
 
392
      withecho "svn","--force", "export",$$c{"trunkDir"},"$bdir";
314
393
   }
315
394
   else {
316
 
      if(system("mkdir", "$bdir") +
317
 
         system("cp","--parents","-laf",@files,$bdir) )
318
 
      {
319
 
         # 0=good; but if pure copy failed, export it
 
395
      mkdir $bdir;
 
396
      #fixme maybe rewrite to withecho
 
397
      if(system("mkdir","-p", map { "$bdir/$_" } @dirs) + system ("cp", "--parents", "-laf", @files, $bdir) )
 
398
      { # cp failed...
320
399
         system "rm", "-rf", $bdir;
321
 
         withecho "svn","export",$$c{"trunkDir"},"$bdir";
 
400
         withecho "svn", "--force", "export",$$c{"trunkDir"},$bdir;
322
401
      }
323
402
   }
324
403
}
325
404
 
 
405
# a cludge...
326
406
if($opt_pass_diff) {
327
407
   $dirname="$package-$upVersion";
328
408
   needs_upsCurrentUrl;
355
435
   $ENV{"DIFFSRC"}=$tmpfile;
356
436
}
357
437
 
358
 
chdir $bdir || die "Mh, something is going wrong...";
359
 
 
360
 
if (0 != system(@builder,@ARGV)) {
 
438
chdir $bdir || die "Mh, something is going wrong with builddir $bdir...";
 
439
 
 
440
if($opt_export) { print "Build directory exported to $bdir\n"; exit 0;}
 
441
 
 
442
if (!withecho(@builder,@ARGV)) {
361
443
   system "$opt_postbuild" if($opt_postbuild);
362
444
   print STDERR "build command failed in $bdir\nAborting.\n";
363
445
   print STDERR "W: build directory not purged!\n";
412
494
   }
413
495
   
414
496
   if($opt_lintian) {
415
 
      withecho "lintian $destdir/$chfile";
 
497
      withecho "lintian", "$destdir/$chfile";
416
498
   }
417
499
 
418
500
   if($opt_tag) {
419
501
      system "$opt_pretag" if($opt_pretag);
 
502
      checktag;
420
503
      withecho ("svn", "-m", "$scriptname Tagging $package ($tagVersion)", "cp", $$c{"trunkUrl"}, $$c{"tagsUrl"}."/$tagVersion");
421
504
      system "$opt_posttag" if($opt_posttag);
422
505
      chdir $$c{"trunkDir"};
423
 
      withecho "dch -D UNRELEASED -i \"NOT RELEASED YET\"";
424
 
      print "\nI: Done! Last commit pending, please execute manually.\n";
 
506
      withecho "dch", "-D", "UNRELEASED", "-i", "NOT RELEASED YET";
 
507
      print "\nI: Done! Created the next changelog entry, please commit later or revert.\n";
425
508
   }
426
509
}
427
510
SDCommon::sd_exit 0+$retval;