Skip to content

Commit

Permalink
build: add c++ coverage support on macOS
Browse files Browse the repository at this point in the history
macOS requires passing the --coverage flag in OTHER_LDFLAGS and
OTHER_CFLAGS in xcode_settings.

PR-URL: #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>
  • Loading branch information
evanlucas authored and MylesBorins committed Oct 23, 2017
1 parent 97b8271 commit 2cfcc45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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__
Expand All @@ -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 %: "
Expand Down
12 changes: 12 additions & 0 deletions node.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
}],
Expand Down

0 comments on commit 2cfcc45

Please sign in to comment.