Skip to content

Commit 43edf43

Browse files
committed
build: add support to gcov and codecov
Add support to gcov through a `npm install` flag (`--llnode_coverage=true`), and update Travis settings to upload coverage report to CodeCov on success. PR-URL: #258 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 59b65c4 commit 43edf43

File tree

6 files changed

+55
-13
lines changed

6 files changed

+55
-13
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ package-lock.json
1515
# Generated by scripts/configure.js
1616
config.gypi
1717
llnode.js
18+
*.gcov
19+
*.info

.travis.yml

+28-11
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,42 @@ matrix:
1010
dist: trusty
1111
before_install:
1212
- sudo apt-get -qq update
13-
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
14-
install: npm install --llnode_build_addon=true
13+
- sudo apt-get install lldb-3.9 liblldb-3.9-dev lcov -y
14+
install:
15+
- npm install --llnode_build_addon=true --llnode_coverage=true
1516
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
1617
node_js: "6"
18+
after_success:
19+
- npm run coverage
20+
- npm run codecov-upload
1721

1822
- name: "[Trusty] Node.js v8.x"
1923
sudo: required
2024
dist: trusty
2125
before_install:
2226
- sudo apt-get -qq update
23-
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
24-
install: npm install --llnode_build_addon=true
27+
- sudo apt-get install lldb-3.9 liblldb-3.9-dev lcov -y
28+
install:
29+
- npm install --llnode_build_addon=true
2530
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
2631
node_js: "8"
32+
after_success:
33+
- npm run coverage
34+
- npm run codecov-upload
2735

2836
- name: "[Trusty] Node.js v10.x"
2937
sudo: required
3038
dist: trusty
3139
before_install:
3240
- sudo apt-get -qq update
33-
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
34-
install: npm install --llnode_build_addon=true
41+
- sudo apt-get install lldb-3.9 liblldb-3.9-dev lcov -y
42+
install:
43+
- npm install --llnode_build_addon=true --llnode_coverage=true
3544
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
3645
node_js: "10"
37-
46+
after_success:
47+
- npm run coverage
48+
- npm run codecov-upload
3849

3950
###########################
4051
# Nightlies & V8 Canaries #
@@ -47,13 +58,16 @@ matrix:
4758
dist: trusty
4859
before_install:
4960
- sudo apt-get -qq update
50-
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
61+
- sudo apt-get install lldb-3.9 liblldb-3.9-dev lcov -y
5162
install:
5263
- npm install --nodedir=$(dirname $(dirname $(which node)))/include/node
53-
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-plugin
64+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test
5465
env:
5566
- NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly
5667
- NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly
68+
after_success:
69+
- npm run coverage
70+
- npm run codecov-upload
5771

5872
# Addon is not tested due to lack of node-addon-api
5973
- name: "[Trusty] Node.js V8 Canary"
@@ -62,13 +76,16 @@ matrix:
6276
dist: trusty
6377
before_install:
6478
- sudo apt-get -qq update
65-
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
79+
- sudo apt-get install lldb-3.9 liblldb-3.9-dev lcov -y
6680
install:
6781
- npm install --nodedir=$(dirname $(dirname $(which node)))/include/node
68-
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-plugin
82+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test
6983
env:
7084
- NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/v8-canary
7185
- NODEJS_ORG_MIRROR=https://nodejs.org/download/v8-canary
86+
after_success:
87+
- npm run coverage
88+
- npm run codecov-upload
7289

7390
########
7491
# OS X #

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ plugin: configure
4444
addon: configure-with-addon
4545
node-gyp rebuild
4646

47+
.PHONY: coverage
48+
coverage:
49+
lcov --capture --directory build/ --output-file coverage-cc.info
50+
lcov --remove coverage-cc.info "/usr/*" "*/deps/*" "*/node_modules/*" --output-file coverage-cc.info # filter system-files
51+
lcov --list coverage-cc.info
52+
4753
.PHONY: clean
4854
clean:
4955
$(RM) -r build

binding.gyp

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"lldb_lib_dir%": "",
1111
"lldb_lib_so%": "",
1212
"build_addon": "false",
13+
"coverage": "false",
1314
},
1415

1516
"target_defaults": {
@@ -39,6 +40,10 @@
3940
"<(lldb_lib_dir)/<(lldb_lib)",
4041
],
4142
}],
43+
[ "coverage == 'true'", {
44+
"cflags": [ "--coverage" ],
45+
"ldflags" : [ "--coverage" ],
46+
}],
4247
]
4348
},
4449

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"test-plugin": "tape test/plugin/*-test.js",
1717
"test-addon": "tape test/addon/*-test.js",
1818
"test-all": "npm run test-addon && npm run test-plugin",
19-
"test": "npm run test-plugin"
19+
"test": "npm run test-plugin",
20+
"coverage": "make coverage",
21+
"codecov-upload": "codecov --disable=gcov --file=coverage-cc.info"
2022
},
2123
"repository": {
2224
"type": "git",
@@ -44,6 +46,7 @@
4446
},
4547
"homepage": "https://github.com/nodejs/llnode#readme",
4648
"devDependencies": {
49+
"codecov": "^3.1.0",
4750
"tape": "^4.4.0"
4851
},
4952
"dependencies": {

scripts/configure.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@ function main() {
1919

2020
main();
2121

22-
// Do not build addon by default until it's less experimental
2322
function configureBuildOptions(config) {
23+
// Do not build addon by default until it's less experimental
2424
const build_addon = (process.env.npm_config_llnode_build_addon ||
2525
process.env.LLNODE_BUILD_ADDON);
2626
if (build_addon) {
2727
config.variables.build_addon = build_addon;
2828
} else {
2929
config.variables.build_addon = 'false';
3030
}
31+
32+
// Optionally build with support for gcov
33+
const coverage = (process.env.npm_config_llnode_coverage ||
34+
process.env.LLNODE_COVERAGE);
35+
if (coverage) {
36+
config.variables.coverage = coverage;
37+
} else {
38+
config.variables.coverage = 'false';
39+
}
3140
}
3241

3342
/**

0 commit comments

Comments
 (0)