Commit 513c7765 authored by Alexandre Julliard's avatar Alexandre Julliard

tools: Improve error handling in the buildicon script.

parent 3b1b1863
...@@ -36,12 +36,27 @@ my $icoName = $1; ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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"); ...@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment