From 6792d789521a104f78a9a702672672387831d78c Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Fri, 19 Feb 2016 15:31:29 +0200 Subject: [PATCH] [tests] Use ENABLE_COVERAGE=1 envvar to enable coverage This detaches coverage data collection from typical debug build. --- Makefile | 2 +- gyp/common.gypi | 21 +++++++++++++++------ platform/linux/mapboxgl-app.gypi | 6 +++++- scripts/collect-coverage.sh | 5 +++++ scripts/main.mk | 5 +++++ test/test.gypi | 6 +++++- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 4504fa6b8..bc09b72d4 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,7 @@ xtest: ; $(RUN) HOST=osx HOST_VERSION=x86_64 Xcode/test endif .PHONY: check -check: ; $(RUN) BUILDTYPE=Debug check +check: ; $(RUN) BUILDTYPE=Debug ENABLE_COVERAGE=1 check .PHONY: render render: ; $(RUN) Makefile/mbgl-render diff --git a/gyp/common.gypi b/gyp/common.gypi index 685242057..13565b04e 100644 --- a/gyp/common.gypi +++ b/gyp/common.gypi @@ -97,8 +97,12 @@ '-fno-common', '--coverage', ], - 'ldflags': [ - '--coverage', + 'conditions': [ + ['enable_coverage=="1"', { + 'cflags_cc': [ '<@(cflags_cc)', '--coverage' ], + }, { + 'ldflags': [ '--coverage' ], + }], ], 'defines': [ 'DEBUG' ], 'xcode_settings': { @@ -106,10 +110,15 @@ 'GCC_GENERATE_DEBUGGING_SYMBOLS': 'YES', 'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES', 'DEAD_CODE_STRIPPING': 'NO', - 'GCC_INSTRUMENT_PROGRAM_FLOW_ARCS': 'YES', - 'GCC_GENERATE_TEST_COVERAGE_FILES': 'YES', - 'OTHER_CPLUSPLUSFLAGS': [ '-fno-omit-frame-pointer','-fwrapv', '-fstack-protector-all', '-fno-common', '-fprofile-arcs', '-ftest-coverage' ], - } + 'OTHER_CPLUSPLUSFLAGS': [ '-fno-omit-frame-pointer','-fwrapv', '-fstack-protector-all', '-fno-common' ], + 'conditions': [ + ['enable_coverage=="1"', { + 'GCC_INSTRUMENT_PROGRAM_FLOW_ARCS': 'YES', + 'GCC_GENERATE_TEST_COVERAGE_FILES': 'YES', + 'OTHER_CPLUSPLUSFLAGS': [ '<@(OTHER_CPLUSPLUSFLAGS)', '-fprofile-arcs', '-ftest-coverage' ], + }], + ], + }, }, 'Release': { 'cflags_cc': [ '-g', '-O3' ], diff --git a/platform/linux/mapboxgl-app.gypi b/platform/linux/mapboxgl-app.gypi index 4f9c6317c..19c17f624 100644 --- a/platform/linux/mapboxgl-app.gypi +++ b/platform/linux/mapboxgl-app.gypi @@ -51,7 +51,11 @@ 'configurations': { 'Debug': { 'xcode_settings': { - 'OTHER_LDFLAGS': [ '--coverage' ], + 'conditions': [ + ['enable_coverage=="1"', { + 'OTHER_LDFLAGS': [ '--coverage' ], + }], + ], }, }, }, diff --git a/scripts/collect-coverage.sh b/scripts/collect-coverage.sh index 65f96a0b2..0007eebd5 100755 --- a/scripts/collect-coverage.sh +++ b/scripts/collect-coverage.sh @@ -3,6 +3,11 @@ set -e set -o pipefail +if [ -z ${ENABLE_COVERAGE} ] ; then + echo "ENABLE_COVERAGE environment variable is not set, aborting." + exit 1 +fi + function usage() { echo "Error: LCOV and genhtml are required for generating coverage reports." if [ `uname -s` = 'Linux' ]; then diff --git a/scripts/main.mk b/scripts/main.mk index b11e9053a..de49c9967 100644 --- a/scripts/main.mk +++ b/scripts/main.mk @@ -83,6 +83,11 @@ GYP_FLAGS += -Dcxx_host=$(CXX_HOST) GYP_FLAGS += --depth=. GYP_FLAGS += -Goutput_dir=. GYP_FLAGS += --generator-output=./build/$(HOST_SLUG) +ifeq ($(ENABLE_COVERAGE),1) +GYP_FLAGS += -Denable_coverage=1 +else ifneq ($(ENABLE_COVERAGE),1) +GYP_FLAGS += -Denable_coverage=0 +endif .PHONY: Makefile/__project__ Makefile/__project__: print-env $(SUBMODULES) config/$(HOST_SLUG).gypi diff --git a/test/test.gypi b/test/test.gypi index f648657c8..1842a807f 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -129,7 +129,11 @@ 'configurations': { 'Debug': { 'xcode_settings': { - 'OTHER_LDFLAGS': [ '--coverage' ], + 'conditions': [ + ['enable_coverage=="1"', { + 'OTHER_LDFLAGS': [ '--coverage' ], + }], + ], }, }, },