webkitdirs.pm fails when CC is set to native compiler
Created attachment 239621 [details] Patch
Comment on attachment 239621 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=239621&action=review > Tools/ChangeLog:12 > + The perl regexp returns an empty array when there is no match (when > + the compiler in CC is not configured with --target or --host). Trying > + to test the first element of the array will trigger a warning > + "Use of uninitialized value $host[0] in string ne". Test that the > + array is not empty first. Maybe a better way to describe the issue is to say: Fixes an issue where webkitdirs::isCrossCompilation() causes Perl uninitialized warnings when the GCC compiler specified by the environment variable CC was not built for cross compilation. > Tools/Scripts/webkitdirs.pm:1079 > my @host = $compiler_options =~ m/--host=(.*?)\s/; > my @target = $compiler_options =~ m/--target=(.*?)\s/; > > - return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]); > + return (@host && @target && $host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]); We are underutilizing the use of an array for holding the captured output of the regular expressions because the regular expression on lines 1076 and 1077 each have exactly one capture group. Using the fact that a captured group is always a string and the property that the empty string evaluates to false in a boolean context, I would write this code as: my $host = $1 if $compiler_options =~ /--host=(.*?)\s/; my $target = $1 if $compiler_options =~ /--target=(.*?)\s/; return ($host && $target && $host ne $target);