tools: Improve error handling in the buildicon script.

This commit is contained in:
Alexandre Julliard 2010-04-06 13:24:04 +02:00
parent 3b1b1863e4
commit 513c77655a
1 changed files with 25 additions and 12 deletions

View File

@ -36,12 +36,27 @@ my $icoName = $1;
my @pngFiles; my @pngFiles;
# Get the programs from the environment variables # Get the programs from the environment variables
my $convert = $ENV{"CONVERT"}; my $convert = $ENV{"CONVERT"} || "convert";
$convert = "convert" if $convert eq ""; my $rsvg = $ENV{"RSVG"} || "rsvg";
my $rsvg = $ENV{"RSVG"}; my $icotool = $ENV{"ICOTOOL"} || "icotool";
$rsvg = "rsvg" if $rsvg eq "";
my $icotool = $ENV{"ICOTOOL"}; sub cleanup()
$icotool = "icotool" if $icotool eq ""; {
unlink $renderedSVGFileName;
unlink $_ foreach(@pngFiles);
}
$SIG{"INT"} = "cleanup";
$SIG{"HUP"} = "cleanup";
$SIG{"TERM"} = "cleanup";
$SIG{"__DIE__"} = "cleanup";
# run a shell command and die on error
sub shell(@)
{
my @args = @_;
system(@args) == 0 or die "@args failed: $?";
}
sub svg_element_start sub svg_element_start
{ {
@ -67,7 +82,7 @@ sub svg_element_start
if(defined($x) and defined($x)) { if(defined($x) and defined($x)) {
if($x =~ /\d*/ and $y =~ /\d*/) { if($x =~ /\d*/ and $y =~ /\d*/) {
system "$convert $renderedSVGFileName -crop '$size x$size+$x+$y' $pngFileName"; shell $convert, $renderedSVGFileName, "-crop", "${size}x${size}+$x+$y", $pngFileName;
} }
} }
@ -96,7 +111,7 @@ sub resize_image
# Use ImageMagick to stretch the image # Use ImageMagick to stretch the image
my($size) = @_; my($size) = @_;
my $pngFileName = "$icoName-$size.png"; my $pngFileName = "$icoName-$size.png";
system "$convert $renderedSVGFileName -resize '$size x$size' $pngFileName"; shell $convert, $renderedSVGFileName, "-resize", "${size}x${size}", $pngFileName;
push(@pngFiles, $pngFileName); push(@pngFiles, $pngFileName);
} }
@ -108,7 +123,7 @@ sub fallback_render
} }
# Render the SVG image # Render the SVG image
system 'rsvg', $svgFileName, $renderedSVGFileName; shell 'rsvg', $svgFileName, $renderedSVGFileName;
# Render the images in the SVG # Render the images in the SVG
my $parser = new XML::Parser( my $parser = new XML::Parser(
@ -120,9 +135,7 @@ $parser->parsefile("$svgFileName");
fallback_render unless(@pngFiles); fallback_render unless(@pngFiles);
# Combine them into an ICO file # Combine them into an ICO file
my $icotoolCommand = "$icotool -c -o $icoFileName"; shell $icotool, "-c", "-o", $icoFileName, @pngFiles;
$icotoolCommand .= " $_" foreach(@pngFiles);
system $icotoolCommand;
# Delete the intermediate images # Delete the intermediate images
unlink $renderedSVGFileName; unlink $renderedSVGFileName;