From 117f6e6389fc4da2d7b0b2bdb203503caf88cf9c Mon Sep 17 00:00:00 2001 From: senmiao Date: Tue, 11 Oct 2016 17:16:24 +0800 Subject: [PATCH] fix:Xcode8 Support --- lcov-1.12/bin/copy_dates.sh | 36 ++++++ lcov-1.12/bin/genhtml | 16 ++- lcov-1.12/bin/geninfo | 109 ++++++++++++------- lcov-1.12/bin/get_changes.sh | 13 +++ lcov-1.12/bin/install.sh | 71 ++++++++++++ lcov-1.12/bin/lcov | 6 +- lcov-1.12/bin/updateversion.pl | 193 +++++++++++++++++++++++++++++++++ 7 files changed, 397 insertions(+), 47 deletions(-) create mode 100755 lcov-1.12/bin/copy_dates.sh create mode 100755 lcov-1.12/bin/get_changes.sh create mode 100755 lcov-1.12/bin/install.sh create mode 100755 lcov-1.12/bin/updateversion.pl diff --git a/lcov-1.12/bin/copy_dates.sh b/lcov-1.12/bin/copy_dates.sh new file mode 100755 index 0000000..2c2af8a --- /dev/null +++ b/lcov-1.12/bin/copy_dates.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Usage: copy_dates.sh SOURCE TARGET +# +# For each file found in SOURCE, set the modification time of the copy of that +# file in TARGET to either the time of the latest Git commit (if SOURCE contains +# a Git repository and the file was not modified after the last commit), or the +# modification time of the original file. + +SOURCE="$1" +TARGET="$2" + +if [ -z "$SOURCE" -o -z "$TARGET" ] ; then + echo "Usage: $0 SOURCE TARGET" >&2 + exit 1 +fi + +[ -d "$SOURCE/.git" ] ; NOGIT=$? + +echo "Copying modification/commit times from $SOURCE to $TARGET" + +cd "$SOURCE" || exit 1 +find * -type f | while read FILENAME ; do + [ ! -e "$TARGET/$FILENAME" ] && continue + + # Copy modification time + touch -m "$TARGET/$FILENAME" -r "$FILENAME" + + [ $NOGIT -eq 1 ] && continue # No Git + git diff --quiet -- "$FILENAME" || continue # Modified + git diff --quiet --cached -- "$FILENAME" || continue # Modified + + # Apply modification time from Git commit time + TIME=$(git log --pretty=format:%cd -n 1 --date=iso -- "$FILENAME") + [ -n "$TIME" ] && touch -m "$TARGET/$FILENAME" --date "$TIME" +done diff --git a/lcov-1.12/bin/genhtml b/lcov-1.12/bin/genhtml index b89b0ef..9f7bfa4 100755 --- a/lcov-1.12/bin/genhtml +++ b/lcov-1.12/bin/genhtml @@ -350,6 +350,9 @@ if (defined($opt_config_file)) { elsif (-r "/etc/lcovrc") { $config = read_config("/etc/lcovrc"); +} elsif (-r "/usr/local/etc/lcovrc") +{ + $config = read_config("/usr/local/etc/lcovrc"); } if ($config || %opt_rc) @@ -3848,8 +3851,8 @@ sub fmt_centered($$) { my ($width, $text) = @_; my $w0 = length($text); - my $w1 = int(($width - $w0) / 2); - my $w2 = $width - $w0 - $w1; + my $w1 = $width > $w0 ? int(($width - $w0) / 2) : 0; + my $w2 = $width > $w0 ? $width - $w0 - $w1 : 0; return (" "x$w1).$text.(" "x$w2); } @@ -5325,6 +5328,7 @@ sub demangle_list($) my $tmpfile; my $handle; my %demangle; + my $demangle_arg = ""; my %versions; # Write function names to file @@ -5333,8 +5337,14 @@ sub demangle_list($) print($handle join("\n", @$list)); close($handle); + # Extra flag necessary on OS X so that symbols listed by gcov get demangled + # properly. + if ($^O eq "darwin") { + $demangle_arg = "--no-strip-underscores"; + } + # Build translation hash from c++filt output - open($handle, "-|", "c++filt < $tmpfile") or + open($handle, "-|", "c++filt $demangle_arg < $tmpfile") or die("ERROR: could not run c++filt: $!\n"); foreach my $func (@$list) { my $translated = <$handle>; diff --git a/lcov-1.12/bin/geninfo b/lcov-1.12/bin/geninfo index c6d68e1..a5ae883 100755 --- a/lcov-1.12/bin/geninfo +++ b/lcov-1.12/bin/geninfo @@ -160,6 +160,8 @@ sub solve_relative_path($$); sub read_gcov_header($); sub read_gcov_file($); sub info(@); +sub map_llvm_version($); +sub version_to_str($); sub get_gcov_version(); sub system_no_output($@); sub read_config($); @@ -304,6 +306,9 @@ if (defined($opt_config_file)) { elsif (-r "/etc/lcovrc") { $config = read_config("/etc/lcovrc"); +} elsif (-r "/usr/local/etc/lcovrc") +{ + $config = read_config("/usr/local/etc/lcovrc"); } if ($config || %opt_rc) @@ -1898,6 +1903,36 @@ sub read_gcov_file($) } +# Map LLVM versions to the version of GCC gcov which they emulate. + +sub map_llvm_version($) +{ + my ($ver) = @_; + + return 0x040200 if ($ver >= 0x030400); + + warn("WARNING: This version of LLVM's gcov is unknown. ". + "Assuming it emulates GCC gcov version 4.2.\n"); + + return 0x040200; +} + + +# Return a readable version of encoded gcov version. + +sub version_to_str($) +{ + my ($ver) = @_; + my ($a, $b, $c); + + $a = $ver >> 16 & 0xff; + $b = $ver >> 8 & 0xff; + $c = $ver & 0xff; + + return "$a.$b.$c"; +} + + # # Get the GCOV tool version. Return an integer number which represents the # GCOV version. Version numbers can be compared using standard integer @@ -1909,58 +1944,48 @@ sub get_gcov_version() local *HANDLE; my $version_string; my $result; - my $pipe_next_line; + my ($a, $b, $c) = (4, 2, 0); # Fallback version + + # Examples for gcov version output: + # + # gcov (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) + # + # gcov (crosstool-NG 1.18.0) 4.7.2 + # + # LLVM (http://llvm.org/): + # LLVM version 3.4svn + # + # Apple LLVM version 8.0.0 (clang-800.0.38) + # Optimized build. + # Default target: x86_64-apple-darwin16.0.0 + # Host CPU: haswell open(GCOV_PIPE, "-|", "$gcov_tool --version") or die("ERROR: cannot retrieve gcov version!\n"); + local $/; $version_string = ; - # LLVM gcov keeps version information on the second line. - # For example, gcov --version yields: - # LLVM (http://llvm.org/): - # LLVM version 3.4svn - - $pipe_next_line = ; - # In case version information is on first line. - # For example, with Xcode 7.0 gcov --version yields: - # Apple LLVM 7.0.0 (clang-700.0.65) - - $version_string = $pipe_next_line if ($pipe_next_line && $version_string =~ /LLVM/); close(GCOV_PIPE); - # Remove version information in parenthesis to cope with the following: - # - gcov (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) - # - gcov (crosstool-NG 1.18.0) 4.7.2 + # Remove all bracketed information $version_string =~ s/\([^\)]*\)//g; - $result = 0; - if ($version_string =~ /(\d+)\.(\d+)(\.(\d+))?/) - { - if (defined($4)) - { - info("Found gcov version: $1.$2.$4\n"); - $result = $1 << 16 | $2 << 8 | $4; - } - else - { - info("Found gcov version: $1.$2\n"); - $result = $1 << 16 | $2 << 8; - } + if ($version_string =~ /(\d+)\.(\d+)(\.(\d+))?/) { + ($a, $b, $c) = ($1, $2, $4); + $c = 0 if (!defined($c)); + } else { + warn("WARNING: cannot determine gcov version - ". + "assuming $a.$b.$c\n"); } - if ($version_string =~ /LLVM/) - { - # Map LLVM versions to the version of GCC gcov which - # they emulate - if ($result >= 0x030400) - { - info("Found LLVM gcov version 3.4, which emulates gcov version 4.2\n"); - $result = 0x040200; - } - else - { - warn("This version of LLVM's gcov is unknown. Assuming it emulates GCC gcov version 4.2.\n"); - $result = 0x040200; - } + $result = $a << 16 | $b << 8 | $c; + + if ($version_string =~ /LLVM/) { + $result = map_llvm_version($result); + info("Found LLVM gcov version $a.$b.$c, which emulates gcov ". + "version ".version_to_str($result)."\n"); + } else { + info("Found gcov version: ".version_to_str($result)."\n"); } + return ($result, $version_string); } diff --git a/lcov-1.12/bin/get_changes.sh b/lcov-1.12/bin/get_changes.sh new file mode 100755 index 0000000..cfa97d6 --- /dev/null +++ b/lcov-1.12/bin/get_changes.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Usage: get_changes.sh +# +# Print lcov change log information as provided by Git + +TOOLDIR=$(cd $(dirname $0) ; pwd) + +cd $TOOLDIR + +if ! git --no-pager log --no-merges --decorate=short --color=never 2>/dev/null ; then + cat "$TOOLDIR/../CHANGES" 2>/dev/null +fi diff --git a/lcov-1.12/bin/install.sh b/lcov-1.12/bin/install.sh new file mode 100755 index 0000000..931f875 --- /dev/null +++ b/lcov-1.12/bin/install.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# install.sh [--uninstall] sourcefile targetfile [install options] +# + + +# Check for uninstall option +if test "x$1" == "x--uninstall" ; then + UNINSTALL=true + SOURCE=$2 + TARGET=$3 + shift 3 +else + UNINSTALL=false + SOURCE=$1 + TARGET=$2 + shift 2 +fi + +# Check usage +if test -z "$SOURCE" || test -z "$TARGET" ; then + echo Usage: install.sh [--uninstall] source target [install options] >&2 + exit 1 +fi + + +# +# do_install(SOURCE_FILE, TARGET_FILE) +# + +do_install() +{ + local SOURCE=$1 + local TARGET=$2 + local PARAMS=$3 + + install -p -D $PARAMS $SOURCE $TARGET +} + + +# +# do_uninstall(SOURCE_FILE, TARGET_FILE) +# + +do_uninstall() +{ + local SOURCE=$1 + local TARGET=$2 + + # Does target exist? + if test -r $TARGET ; then + # Is target of the same version as this package? + if diff -I '^our \$lcov_version' -I '^\.TH ' $SOURCE $TARGET >/dev/null; then + rm -f $TARGET + else + echo WARNING: Skipping uninstall for $TARGET - versions differ! >&2 + fi + else + echo WARNING: Skipping uninstall for $TARGET - not installed! >&2 + fi +} + + +# Call sub routine +if $UNINSTALL ; then + do_uninstall $SOURCE $TARGET +else + do_install $SOURCE $TARGET "$*" +fi + +exit 0 diff --git a/lcov-1.12/bin/lcov b/lcov-1.12/bin/lcov index abcf3d8..e8d6a9c 100755 --- a/lcov-1.12/bin/lcov +++ b/lcov-1.12/bin/lcov @@ -243,6 +243,9 @@ if (defined($opt_config_file)) { elsif (-r "/etc/lcovrc") { $config = read_config("/etc/lcovrc"); +} elsif (-r "/usr/local/etc/lcovrc") +{ + $config = read_config("/usr/local/etc/lcovrc"); } if ($config || %opt_rc) @@ -2915,7 +2918,7 @@ sub remove() foreach $pattern (@pattern_list) { - $match_found ||= ($filename =~ (/$pattern$/)); + $match_found ||= ($filename =~ (/^$pattern$/)); } @@ -4250,7 +4253,6 @@ sub warn_handler($) { my ($msg) = @_; - temp_cleanup(); warn("$tool_name: $msg"); } diff --git a/lcov-1.12/bin/updateversion.pl b/lcov-1.12/bin/updateversion.pl new file mode 100755 index 0000000..02d2ec2 --- /dev/null +++ b/lcov-1.12/bin/updateversion.pl @@ -0,0 +1,193 @@ +#!/usr/bin/perl -w + +use strict; + +use File::Basename; + +sub update_man_page($); +sub update_bin_tool($); +sub update_txt_file($); +sub update_spec_file($); +sub write_version_file($); +sub get_file_info($); + +our $directory = $ARGV[0]; +our $version = $ARGV[1]; +our $release = $ARGV[2]; +our $full = $ARGV[3]; + +our @man_pages = ("man/gendesc.1", "man/genhtml.1", "man/geninfo.1", + "man/genpng.1", "man/lcov.1", "man/lcovrc.5"); +our @bin_tools = ("bin/gendesc", "bin/genhtml", "bin/geninfo", + "bin/genpng", "bin/lcov"); +our @txt_files = ("README"); +our @spec_files = ("rpm/lcov.spec"); + +if (!defined($directory) || !defined($version) || !defined($release)) { + die("Usage: $0 DIRECTORY|FILE VERSION RELEASE FULL_VERSION\n"); +} + +# Determine mode of operation +if (-f $directory) { + my $file = $directory; + my $base = basename($file); + + if (grep(/^$base$/, map({ basename($_) } @man_pages))) { + print("Updating man page $file\n"); + update_man_page($file); + } elsif (grep(/^$base$/, map({ basename($_) } @bin_tools))) { + print("Updating bin tool $file\n"); + update_bin_tool($file); + } elsif (grep(/^$base$/, map({ basename($_) } @txt_files))) { + print("Updating text file $file\n"); + update_txt_file($file); + } elsif (grep(/^$base$/, map({ basename($_) } @spec_files))) { + print("Updating spec file $file\n"); + update_spec_file($file); + } elsif ($base eq ".version") { + print("Updating version file $file\n"); + write_version_file($file); + } else { + print("WARNING: Skipping unknown file $file\n"); + } + print("Done.\n"); + exit(0); +} + +foreach (@man_pages) { + print("Updating man page $_\n"); + update_man_page($directory."/".$_); +} +foreach (@bin_tools) { + print("Updating bin tool $_\n"); + update_bin_tool($directory."/".$_); +} +foreach (@txt_files) { + print("Updating text file $_\n"); + update_txt_file($directory."/".$_); +} +foreach (@spec_files) { + print("Updating spec file $_\n"); + update_spec_file($directory."/".$_); +} +print("Updating version file $directory/.version\n"); +write_version_file("$directory/.version"); +print("Done.\n"); + +sub get_file_info($) +{ + my ($filename) = @_; + my ($sec, $min, $hour, $year, $month, $day); + my @stat; + my $gittime; + + return (0, 0, 0) if (!-e $filename); + @stat = stat($filename); + ($sec, $min, $hour, $day, $month, $year) = gmtime($stat[9]); + $year += 1900; + $month += 1; + + return (sprintf("%04d-%02d-%02d", $year, $month, $day), + sprintf("%04d%02d%02d%02d%02d.%02d", $year, $month, $day, + $hour, $min, $sec), + sprintf("%o", $stat[2] & 07777)); +} + +sub update_man_page($) +{ + my ($filename) = @_; + my @date = get_file_info($filename); + my $date_string = $date[0]; + local *IN; + local *OUT; + + $date_string =~ s/-/\\-/g; + open(IN, "<$filename") || die ("Error: cannot open $filename\n"); + open(OUT, ">$filename.new") || + die("Error: cannot create $filename.new\n"); + while () { + s/\"LCOV\s+\d+\.\d+\"/\"LCOV $version\"/g; + s/\d\d\d\d\\\-\d\d\\\-\d\d/$date_string/g; + print(OUT $_); + } + close(OUT); + close(IN); + chmod(oct($date[2]), "$filename.new"); + system("mv", "-f", "$filename.new", "$filename"); + system("touch", "$filename", "-t", $date[1]); +} + +sub update_bin_tool($) +{ + my ($filename) = @_; + my @date = get_file_info($filename); + local *IN; + local *OUT; + + open(IN, "<$filename") || die ("Error: cannot open $filename\n"); + open(OUT, ">$filename.new") || + die("Error: cannot create $filename.new\n"); + while () { + s/^(our\s+\$lcov_version\s*=).*$/$1 "LCOV version $full";/g; + print(OUT $_); + } + close(OUT); + close(IN); + chmod(oct($date[2]), "$filename.new"); + system("mv", "-f", "$filename.new", "$filename"); + system("touch", "$filename", "-t", $date[1]); +} + +sub update_txt_file($) +{ + my ($filename) = @_; + my @date = get_file_info($filename); + local *IN; + local *OUT; + + open(IN, "<$filename") || die ("Error: cannot open $filename\n"); + open(OUT, ">$filename.new") || + die("Error: cannot create $filename.new\n"); + while () { + s/(Last\s+changes:\s+)\d\d\d\d-\d\d-\d\d/$1$date[0]/g; + print(OUT $_); + } + close(OUT); + close(IN); + chmod(oct($date[2]), "$filename.new"); + system("mv", "-f", "$filename.new", "$filename"); + system("touch", "$filename", "-t", $date[1]); +} + +sub update_spec_file($) +{ + my ($filename) = @_; + my @date = get_file_info($filename); + local *IN; + local *OUT; + + open(IN, "<$filename") || die ("Error: cannot open $filename\n"); + open(OUT, ">$filename.new") || + die("Error: cannot create $filename.new\n"); + while () { + s/^(Version:\s*)\d+\.\d+.*$/$1$version/; + s/^(Release:\s*).*$/$1$release/; + print(OUT $_); + } + close(OUT); + close(IN); + system("mv", "-f", "$filename.new", "$filename"); + system("touch", "$filename", "-t", $date[1]); +} + +sub write_version_file($) +{ + my ($filename) = @_; + my $fd; + + open($fd, ">", $filename) or die("Error: cannot write $filename: $!\n"); + print($fd "VERSION=$version\n"); + print($fd "RELEASE=$release\n"); + print($fd "FULL=$full\n"); + close($fd); +}