@@ -160,6 +160,8 @@ sub solve_relative_path($$);
160160sub read_gcov_header ($);
161161sub read_gcov_file ($);
162162sub info (@);
163+ sub map_llvm_version ($);
164+ sub version_to_str ($);
163165sub get_gcov_version ();
164166sub system_no_output ($@);
165167sub read_config ($);
@@ -304,6 +306,9 @@ if (defined($opt_config_file)) {
304306elsif (-r " /etc/lcovrc" )
305307{
306308 $config = read_config(" /etc/lcovrc" );
309+ } elsif (-r " /usr/local/etc/lcovrc" )
310+ {
311+ $config = read_config(" /usr/local/etc/lcovrc" );
307312}
308313
309314if ($config || %opt_rc )
@@ -1898,6 +1903,36 @@ sub read_gcov_file($)
18981903}
18991904
19001905
1906+ # Map LLVM versions to the version of GCC gcov which they emulate.
1907+
1908+ sub map_llvm_version ($)
1909+ {
1910+ my ($ver ) = @_ ;
1911+
1912+ return 0x040200 if ($ver >= 0x030400);
1913+
1914+ warn (" WARNING: This version of LLVM's gcov is unknown. " .
1915+ " Assuming it emulates GCC gcov version 4.2.\n " );
1916+
1917+ return 0x040200;
1918+ }
1919+
1920+
1921+ # Return a readable version of encoded gcov version.
1922+
1923+ sub version_to_str ($)
1924+ {
1925+ my ($ver ) = @_ ;
1926+ my ($a , $b , $c );
1927+
1928+ $a = $ver >> 16 & 0xff;
1929+ $b = $ver >> 8 & 0xff;
1930+ $c = $ver & 0xff;
1931+
1932+ return " $a .$b .$c " ;
1933+ }
1934+
1935+
19011936#
19021937# Get the GCOV tool version. Return an integer number which represents the
19031938# GCOV version. Version numbers can be compared using standard integer
@@ -1909,58 +1944,48 @@ sub get_gcov_version()
19091944 local *HANDLE;
19101945 my $version_string ;
19111946 my $result ;
1912- my $pipe_next_line ;
1947+ my ($a , $b , $c ) = (4, 2, 0); # Fallback version
1948+
1949+ # Examples for gcov version output:
1950+ #
1951+ # gcov (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
1952+ #
1953+ # gcov (crosstool-NG 1.18.0) 4.7.2
1954+ #
1955+ # LLVM (http://llvm.org/):
1956+ # LLVM version 3.4svn
1957+ #
1958+ # Apple LLVM version 8.0.0 (clang-800.0.38)
1959+ # Optimized build.
1960+ # Default target: x86_64-apple-darwin16.0.0
1961+ # Host CPU: haswell
19131962
19141963 open (GCOV_PIPE, " -|" , " $gcov_tool --version" )
19151964 or die (" ERROR: cannot retrieve gcov version!\n " );
1965+ local $/ ;
19161966 $version_string = <GCOV_PIPE>;
1917- # LLVM gcov keeps version information on the second line.
1918- # For example, gcov --version yields:
1919- # LLVM (http://llvm.org/):
1920- # LLVM version 3.4svn
1921-
1922- $pipe_next_line = <GCOV_PIPE>;
1923- # In case version information is on first line.
1924- # For example, with Xcode 7.0 gcov --version yields:
1925- # Apple LLVM 7.0.0 (clang-700.0.65)
1926-
1927- $version_string = $pipe_next_line if ($pipe_next_line && $version_string =~ / LLVM/ );
19281967 close (GCOV_PIPE);
19291968
1930- # Remove version information in parenthesis to cope with the following:
1931- # - gcov (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
1932- # - gcov (crosstool-NG 1.18.0) 4.7.2
1969+ # Remove all bracketed information
19331970 $version_string =~ s /\( [^\) ]*\) // g ;
19341971
1935- $result = 0;
1936- if ($version_string =~ / (\d +)\. (\d +)(\. (\d +))?/ )
1937- {
1938- if (defined ($4 ))
1939- {
1940- info(" Found gcov version: $1 .$2 .$4 \n " );
1941- $result = $1 << 16 | $2 << 8 | $4 ;
1942- }
1943- else
1944- {
1945- info(" Found gcov version: $1 .$2 \n " );
1946- $result = $1 << 16 | $2 << 8;
1947- }
1972+ if ($version_string =~ / (\d +)\. (\d +)(\. (\d +))?/ ) {
1973+ ($a , $b , $c ) = ($1 , $2 , $4 );
1974+ $c = 0 if (!defined ($c ));
1975+ } else {
1976+ warn (" WARNING: cannot determine gcov version - " .
1977+ " assuming $a .$b .$c \n " );
19481978 }
1949- if ($version_string =~ / LLVM/ )
1950- {
1951- # Map LLVM versions to the version of GCC gcov which
1952- # they emulate
1953- if ($result >= 0x030400)
1954- {
1955- info(" Found LLVM gcov version 3.4, which emulates gcov version 4.2\n " );
1956- $result = 0x040200;
1957- }
1958- else
1959- {
1960- warn (" This version of LLVM's gcov is unknown. Assuming it emulates GCC gcov version 4.2.\n " );
1961- $result = 0x040200;
1962- }
1979+ $result = $a << 16 | $b << 8 | $c ;
1980+
1981+ if ($version_string =~ / LLVM/ ) {
1982+ $result = map_llvm_version($result );
1983+ info(" Found LLVM gcov version $a .$b .$c , which emulates gcov " .
1984+ " version " .version_to_str($result )." \n " );
1985+ } else {
1986+ info(" Found gcov version: " .version_to_str($result )." \n " );
19631987 }
1988+
19641989 return ($result , $version_string );
19651990}
19661991
0 commit comments