From a0785845bf55685d9691ea09f009bc2257e9c093 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Mon, 9 Oct 2017 13:30:38 -0500 Subject: [PATCH] build: add c++ coverage support on macOS macOS requires passing the --coverage flag in OTHER_LDFLAGS and OTHER_CFLAGS in xcode_settings. PR-URL: https://github.com/nodejs/node/pull/16163 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: Gireesh Punathil Reviewed-By: Michael Dawson Reviewed-By: Khaidi Chu Reviewed-By: Joyee Cheung --- Makefile | 18 +++++++++++++----- node.gypi | 12 ++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d92024faf019bd..4b40837b81f2e9 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]') COVTESTS ?= test-cov GTEST_FILTER ?= "*" GNUMAKEFLAGS += --no-print-directory +GCOV ?= gcov ifdef JOBS PARALLEL_ARGS = -j $(JOBS) @@ -34,6 +35,10 @@ ifdef DISABLE_V8_I18N V8_BUILD_OPTIONS += i18nsupport=off endif +ifeq ($(OSTYPE), darwin) + GCOV = xcrun llvm-cov gcov +endif + BUILDTYPE_LOWER := $(shell echo $(BUILDTYPE) | tr '[A-Z]' '[a-z]') # Determine EXEEXT @@ -124,10 +129,12 @@ coverage-clean: $(RM) -r gcovr testing $(RM) -r out/$(BUILDTYPE)/.coverage $(RM) -r .cov_tmp coverage - $(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda + $(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcda $(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcda - $(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcno - $(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing*.gcno + $(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcno + $(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcno + $(RM) out/$(BUILDTYPE)/obj.target/cctest/src/*.gcno + $(RM) out/$(BUILDTYPE)/obj.target/cctest/test/cctest/*.gcno # Build and test with code coverage reporting. Leave the lib directory # instrumented for any additional runs the user may want to make. @@ -157,7 +164,7 @@ coverage-build: all coverage-test: coverage-build $(RM) -r out/$(BUILDTYPE)/.coverage $(RM) -r .cov_tmp - $(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda + $(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcda $(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcda -$(MAKE) $(COVTESTS) mv lib lib__ @@ -170,7 +177,8 @@ coverage-test: coverage-build --report-dir "../coverage") -(cd out && "../gcovr/scripts/gcovr" --gcov-exclude='.*deps' \ --gcov-exclude='.*usr' -v -r Release/obj.target/node \ - --html --html-detail -o ../coverage/cxxcoverage.html) + --html --html-detail -o ../coverage/cxxcoverage.html \ + --gcov-executable="$(GCOV)") mv lib lib_ mv lib__ lib @echo -n "Javascript coverage %: " diff --git a/node.gypi b/node.gypi index 6ef47849a7f624..507ca846ed27dd 100644 --- a/node.gypi +++ b/node.gypi @@ -333,6 +333,18 @@ '-O0' ], 'cflags!': [ '-O3' ] }], + [ 'OS=="mac" and node_shared=="false" and coverage=="true"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '--coverage', + ], + 'OTHER_CFLAGS+': [ + '--coverage', + '-g', + '-O0' + ], + } + }], [ 'OS=="sunos"', { 'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ], }],