Skip to content

Commit a078584

Browse files
committed
build: add c++ coverage support on macOS
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>
1 parent 20b7805 commit a078584

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Makefile

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]')
1313
COVTESTS ?= test-cov
1414
GTEST_FILTER ?= "*"
1515
GNUMAKEFLAGS += --no-print-directory
16+
GCOV ?= gcov
1617

1718
ifdef JOBS
1819
PARALLEL_ARGS = -j $(JOBS)
@@ -34,6 +35,10 @@ ifdef DISABLE_V8_I18N
3435
V8_BUILD_OPTIONS += i18nsupport=off
3536
endif
3637

38+
ifeq ($(OSTYPE), darwin)
39+
GCOV = xcrun llvm-cov gcov
40+
endif
41+
3742
BUILDTYPE_LOWER := $(shell echo $(BUILDTYPE) | tr '[A-Z]' '[a-z]')
3843

3944
# Determine EXEEXT
@@ -124,10 +129,12 @@ coverage-clean:
124129
$(RM) -r gcovr testing
125130
$(RM) -r out/$(BUILDTYPE)/.coverage
126131
$(RM) -r .cov_tmp coverage
127-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda
132+
$(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcda
128133
$(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcda
129-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcno
130-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing*.gcno
134+
$(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcno
135+
$(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcno
136+
$(RM) out/$(BUILDTYPE)/obj.target/cctest/src/*.gcno
137+
$(RM) out/$(BUILDTYPE)/obj.target/cctest/test/cctest/*.gcno
131138

132139
# Build and test with code coverage reporting. Leave the lib directory
133140
# instrumented for any additional runs the user may want to make.
@@ -157,7 +164,7 @@ coverage-build: all
157164
coverage-test: coverage-build
158165
$(RM) -r out/$(BUILDTYPE)/.coverage
159166
$(RM) -r .cov_tmp
160-
$(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda
167+
$(RM) out/$(BUILDTYPE)/obj.target/node/{src,gen}/*.gcda
161168
$(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcda
162169
-$(MAKE) $(COVTESTS)
163170
mv lib lib__
@@ -170,7 +177,8 @@ coverage-test: coverage-build
170177
--report-dir "../coverage")
171178
-(cd out && "../gcovr/scripts/gcovr" --gcov-exclude='.*deps' \
172179
--gcov-exclude='.*usr' -v -r Release/obj.target/node \
173-
--html --html-detail -o ../coverage/cxxcoverage.html)
180+
--html --html-detail -o ../coverage/cxxcoverage.html \
181+
--gcov-executable="$(GCOV)")
174182
mv lib lib_
175183
mv lib__ lib
176184
@echo -n "Javascript coverage %: "

node.gypi

+12
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@
333333
'-O0' ],
334334
'cflags!': [ '-O3' ]
335335
}],
336+
[ 'OS=="mac" and node_shared=="false" and coverage=="true"', {
337+
'xcode_settings': {
338+
'OTHER_LDFLAGS': [
339+
'--coverage',
340+
],
341+
'OTHER_CFLAGS+': [
342+
'--coverage',
343+
'-g',
344+
'-O0'
345+
],
346+
}
347+
}],
336348
[ 'OS=="sunos"', {
337349
'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ],
338350
}],

0 commit comments

Comments
 (0)