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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Evan Lucas 2017-10-09 13:30:38 -05:00
parent 20b7805566
commit a0785845bf
2 changed files with 25 additions and 5 deletions

View File

@ -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 %: "

View File

@ -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' ],
}],