[gcov] Add gcov-force-options package. 71/208871/3 accepted/tizen/base/20190704.235733 submit/tizen_base/20190703.121846
authorPavel Kopyl <p.kopyl@samsung.com>
Wed, 28 Mar 2018 19:59:15 +0000 (22:59 +0300)
committerDongkyun Son <dongkyun.s@samsung.com>
Wed, 3 Jul 2019 11:26:57 +0000 (20:26 +0900)
Change-Id: I48c2d7afdb7e234a77c6e6606139757dc316bb2b

packaging/extract-gcov-info [new file with mode: 0644]
packaging/gcc-contrib.spec
packaging/macros.gcov [new file with mode: 0644]

diff --git a/packaging/extract-gcov-info b/packaging/extract-gcov-info
new file mode 100644 (file)
index 0000000..58146c2
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+set -xe
+
+#extract-gcov-info - automagically generate collects gcov info(*.gcno files) and file list
+#for inclusion in an rpm spec file.
+#
+# Usage: extract-gcov-info [-o gcnofiles.list] [builddir]
+#
+# If using normal root, avoid changing anything.
+if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
+        exit 0
+fi
+
+BUILDDIR=.
+while [ $# -gt 0 ]; do
+  case "$1" in
+  -o)
+    out=$2
+    shift
+    ;;
+  *)
+    BUILDDIR=$1
+    shift
+    break
+    ;;
+  esac
+  shift
+done
+
+BUILDDIR=${BUILDDIR%/}
+PREFIX=gcnofiles
+
+mkdir -p "${RPM_BUILD_ROOT}/${PREFIX}"
+
+get_gcovfn()
+{
+  dn=$(dirname "${1#$BUILDDIR}")
+  bn=$(basename "$1")
+  gcovdn="${RPM_BUILD_ROOT}/${PREFIX}/${dn}"
+  gcovfn="${gcovdn}/${bn}"
+}
+
+set -o pipefail
+
+find $BUILDDIR -name "*.gcno" | sort |
+while read f; do
+  get_gcovfn $f
+  mkdir -p $gcovdn
+  cp $f $gcovfn
+done
+
+if ! find "${RPM_BUILD_ROOT}/${PREFIX}" -mindepth 1 -print -quit | grep -q .; then
+  touch "${RPM_BUILD_ROOT}/${PREFIX}/fake.gcno"
+fi
index bebd73d..e425802 100644 (file)
@@ -48,6 +48,7 @@
 %define ubsan_force_options -fsanitize=undefined,bounds-strict,float-divide-by-zero,float-cast-overflow
 %define isan_force_options -fsanitize=unsigned-integer-overflow
 %define tsan_force_options -fsanitize=thread -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread
+%define gcov_force_options -fprofile-arcs -ftest-coverage
 %define asan_runtime_options halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:full_address_space=true:handle_segv=0:log_path=/tmp/asan.log:log_exe_name=1:fast_unwind_on_fatal=1:allocator_may_return_null=1
 %define esan_force_options -fsanitize=efficiency-working-set -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread
 %define esan_cache_force_options -fsanitize=efficiency-cache-frag -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread
@@ -75,6 +76,8 @@ Source22: macros.asan
 Source23: cc1
 Source24: macros.gcc_warning
 Source25: extract-gcc-warning-logs
+Source26: macros.gcov
+Source27: extract-gcov-info
 Group:         Development/Building
 Summary:       GCC related scripts
 License:       MIT
@@ -244,6 +247,51 @@ chmod a-w %{libsubdir}
 /usr/bin/gcc-unforce-options
 [ -d /emul/ ] && chmod a-w /emul/usr/bin/
 
+
+%package -n gcov-force-options
+Summary:    Scripts to enable automatic package coverage instrumentation
+Group:      System Environment
+Requires:   gcc
+
+%description -n gcov-force-options
+Scripts for gcov instrumentation
+
+%post -n gcov-force-options
+# Change mode to allow all users to run gcc-force/unforce-options
+chmod a+w /usr/bin
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
+/usr/bin/gcc-force-options %gcov_force_options
+# Add gcov-related macros
+cat >> /usr/lib/rpm/tizen_macros << EOF
+
+%%gcov_force_options %{gcov_force_options}
+%%gcc_unforce_options /usr/bin/gcc-unforce-options
+%%gcc_force_options /usr/bin/gcc-force-options
+%%gcc_force_default_options %%gcc_force_options %%gcov_force_options
+EOF
+
+%preun -n gcov-force-options
+# Restore read-only mode
+chmod a-w /usr/bin
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
+/usr/bin/gcc-unforce-options
+
+%package -n gcov-build-env
+Summary:    Gcov build environment
+Group:      System Environment
+Requires:   gcc
+Requires:   rpm
+
+%description -n gcov-build-env
+Gcov build environment support files and scripts
+
+%post -n gcov-build-env
+cat %{_rpmconfigdir}/macros.gcov >> %{_rpmconfigdir}/tizen_macros
+
 %package -n tsan-force-options
 Summary:    Scripts to enable automatic package sanitization
 Group:      System Environment
@@ -578,6 +626,8 @@ mkdir -p %{buildroot}/usr/lib/gcc-log-wrapper
 install -m 0755 %{SOURCE23} %{buildroot}/usr/lib/gcc-log-wrapper/
 install -m 0644 %{SOURCE24} %{buildroot}/%{_rpmconfigdir}/
 install -m 0755 %{SOURCE25} %{buildroot}/%{_rpmconfigdir}/tizen/
+install -m 0644 %{SOURCE26} %{buildroot}/%{_rpmconfigdir}/
+install -m 0755 %{SOURCE27} %{buildroot}/%{_rpmconfigdir}/tizen/
 
 %files
 #%manifest gcc-contrib.manifest
@@ -598,6 +648,11 @@ install -m 0755 %{SOURCE25} %{buildroot}/%{_rpmconfigdir}/tizen/
 %{_prefix}/bin/gcc-force-options
 %{_prefix}/bin/gcc-unforce-options
 
+%files -n gcov-force-options
+%defattr(-,root,root,-)
+%{_prefix}/bin/gcc-force-options
+%{_prefix}/bin/gcc-unforce-options
+
 %ifarch %lsan_arch
 %files -n lsan-force-options
 #%manifest gcc-contrib.manifest
@@ -653,6 +708,11 @@ install -m 0755 %{SOURCE25} %{buildroot}/%{_rpmconfigdir}/tizen/
 /TSAN_OPTIONS
 %endif
 
+%files -n gcov-build-env
+%defattr(-,root,root,-)
+%{_rpmconfigdir}/macros.gcov
+%{_rpmconfigdir}/tizen/extract-gcov-info
+
 %ifarch %ubsan_arch
 %files -n ubsan-build-env
 %defattr(-,root,root,-)
diff --git a/packaging/macros.gcov b/packaging/macros.gcov
new file mode 100644 (file)
index 0000000..d1ab2ed
--- /dev/null
@@ -0,0 +1,39 @@
+# /etc/rpm/macros.gcov
+
+%_enable_gcov_packages 1
+
+%__gcov_install_post   %{_rpmconfigdir}/tizen/extract-gcov-info
+
+# See original macro (before expansion) and correct lines after the first one.
+# Mine is from Fedora RPM macros, YMMV.
+%__spec_install_post\
+    %{?__gcov_package:%{__gcov_install_post}}\
+    %{?__debug_package:%{__debug_install_post}}\
+    %{__arch_install_post}\
+    %{__os_install_post}\
+%{nil}
+
+# Same goes here, see your original macro.
+%install %{?_enable_gcov_packages:%{gcov_package}}\
+%{?_enable_debug_packages:%{debug_package}}\
+%%install\
+LANG=C\
+export LANG\
+unset DISPLAY\
+rm -rf %{?buildroot:%{buildroot}} \
+mkdir -p %{?buildroot:%{buildroot}} \
+%{nil}
+
+#       Template for gcov profile data sub-package.
+%gcov_package \
+%global __gcov_package 1\
+%package gcovinfo\
+Summary: Gcov files (*.gcno) for package %{name}\
+Group: Development/Gcov\
+AutoReqProv: 0\
+%description gcovinfo\
+This package provides gcov files for package %{name}.\
+%files gcovinfo\
+%defattr(-,root,root)\
+/gcno*\
+%{nil}