summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
authorMarcin Owsiany <porridge@debian.org>2012-09-09 12:13:20 +0100
committerJoey Hess <joey@kitenet.net>2012-09-09 14:17:20 -0400
commita3494762925e5a42a42ce82c688f62f163ffad1b (patch)
tree17ebd0bc0a1d852670cf139286341d2f4379b59b /Debian
parentb3c00de156adf9c52da3cd0fa7c46414d5eb6982 (diff)
Make it possible to pass perl code to autoscript.
The shell-quoted sed code passed as parameter 4 is fragile (see Bug#665296). Make it possible to pass a sub that operates on each line via $_ instead. Also add a basic unit test for Dh_Lib, for now just with tests for autoscript.
Diffstat (limited to 'Debian')
-rw-r--r--Debian/Debhelper/Dh_Lib.pm23
1 files changed, 20 insertions, 3 deletions
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 10ae69f..7b550b0 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -504,7 +504,8 @@ sub pkgfilename {
# 1: package
# 2: script to add to
# 3: filename of snippet
-# 4: sed to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
+# 4: either text: shell-quoted sed to run on the snippet. Ie, 's/#PACKAGE#/$PACKAGE/'
+# or a sub to run on each line of the snippet. Ie sub { s/#PACKAGE#/$PACKAGE/ }
sub autoscript {
my $package=shift;
my $script=shift;
@@ -533,18 +534,34 @@ sub autoscript {
&& !compat(5)) {
# Add fragments to top so they run in reverse order when removing.
complex_doit("echo \"# Automatically added by ".basename($0)."\"> $outfile.new");
- complex_doit("sed \"$sed\" $infile >> $outfile.new");
+ autoscript_sed($sed, $infile, "$outfile.new");
complex_doit("echo '# End automatically added section' >> $outfile.new");
complex_doit("cat $outfile >> $outfile.new");
complex_doit("mv $outfile.new $outfile");
}
else {
complex_doit("echo \"# Automatically added by ".basename($0)."\">> $outfile");
- complex_doit("sed \"$sed\" $infile >> $outfile");
+ autoscript_sed($sed, $infile, $outfile);
complex_doit("echo '# End automatically added section' >> $outfile");
}
}
+sub autoscript_sed {
+ my $sed = shift;
+ my $infile = shift;
+ my $outfile = shift;
+ if (ref($sed) eq 'CODE') {
+ open(IN, $infile) or die "$infile: $!";
+ open(OUT, ">>$outfile") or die "$outfile: $!";
+ while (<IN>) { $sed->(); print OUT }
+ close(OUT) or die "$outfile: $!";
+ close(IN) or die "$infile: $!";
+ }
+ else {
+ complex_doit("sed \"$sed\" $infile >> $outfile");
+ }
+}
+
# Removes a whole substvar line.
sub delsubstvar {
my $package=shift;