Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: fix c++ code coverage on macOS #24004

Closed
wants to merge 1 commit into from

Conversation

evanlucas
Copy link
Contributor

Recent libtool on macOS does not support the --coverage flag that was
being passed through in the final linking stage.
This change patches gyp-mac-tool to not pass the --coverage flag through
to libtool. It is now possible to generate code coverage for src/ on macOS.

Fixes: #19057

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Recent libtool on macOS does not support the --coverage flag that was
being passed through in the final linking stage.
This change patches gyp-mac-tool to not pass the --coverage flag through
to libtool. It is now possible to generate code coverage for src/ on
macOS.

Fixes: nodejs#19057
@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. tools Issues and PRs related to the tools directory. labels Oct 31, 2018
@richardlau
Copy link
Member

Can we not remove --coverage from ldflags/OTHER_LDFLAGS on macOS instead, or would that also break coverage?

node/node.gypi

Lines 272 to 291 in c515e5c

[ 'OS in "mac freebsd linux" and node_shared=="false"'
' and coverage=="true"', {
'ldflags': [ '--coverage',
'-g',
'-O0' ],
'cflags': [ '--coverage',
'-g',
'-O0' ],
'cflags!': [ '-O3' ],
'xcode_settings': {
'OTHER_LDFLAGS': [
'--coverage',
],
'OTHER_CFLAGS+': [
'--coverage',
'-g',
'-O0'
],
}
}],

@evanlucas
Copy link
Contributor Author

@richardlau that broke coverage when I tried it

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -949,6 +949,8 @@ def GetLibtoolflags(self, configname):
libtoolflags = []

for libtoolflag in self._Settings().get('OTHER_LDFLAGS', []):
if libtoolflag == "--coverage":
Copy link
Contributor

@refack refack Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok after some digging is seem like the native libtool does not accept any flag that starts with --
Can I suggest this instead of the whole for expression (From L948 to L955)

    self.configname = configname
    libtoolflags = self._Settings().get('OTHER_LDFLAGS', [])
    # Native macOS libtool does not except any flags with '--' prefix
    libtoolflags = [f for f in libtoolflags if not f.startswith('--')]
    # TODO(thakis): ARCHS?

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO there should be a more direct way.

@refack
Copy link
Contributor

refack commented Oct 31, 2018

Hello @evanlucas I'm going to look into solving this by a more direct means. If I can't I'll dismiss my review.

/CC @nodejs/python @nodejs/gyp

@@ -949,6 +949,8 @@ def GetLibtoolflags(self, configname):
libtoolflags = []

for libtoolflag in self._Settings().get('OTHER_LDFLAGS', []):
if libtoolflag == "--coverage":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok after some digging is seem like the native libtool does not accept any flag that starts with --
Can I suggest this instead of the whole for expression (From L948 to L955)

    self.configname = configname
    libtoolflags = self._Settings().get('OTHER_LDFLAGS', [])
    # Native macOS libtool does not except any flags with '--' prefix
    libtoolflags = [f for f in libtoolflags if not f.startswith('--')]
    # TODO(thakis): ARCHS?

@refack
Copy link
Contributor

refack commented Oct 31, 2018

I've tested my suggestion and it generate the same make scaffolding as the current PR. And allows building make coverage.

@refack refack added the python PRs and issues that require attention from people who are familiar with Python. label Oct 31, 2018
@refack
Copy link
Contributor

refack commented Oct 31, 2018

there should be a more direct way.

I've been thinking about this some more, and I think the settings in

node/node.gypi

Lines 272 to 291 in c515e5c

[ 'OS in "mac freebsd linux" and node_shared=="false"'
' and coverage=="true"', {
'ldflags': [ '--coverage',
'-g',
'-O0' ],
'cflags': [ '--coverage',
'-g',
'-O0' ],
'cflags!': [ '-O3' ],
'xcode_settings': {
'OTHER_LDFLAGS': [
'--coverage',
],
'OTHER_CFLAGS+': [
'--coverage',
'-g',
'-O0'
],
}
}],

are wrong. They should only be applied to the binary target, not to the libnode.lib indermidiary. I'll work on that tomorrow...

@antsmartian
Copy link
Contributor

Thanks. I added your change and tried running make coverage, I end up in seeing the below error:

mkdir -p coverage .cov_tmp
./node ./node_modules/.bin/nyc merge 'out/Release/.coverage' \
		.cov_tmp/libcov.json
coverage files in out/Release/.coverage merged into .cov_tmp/libcov.json
(cd lib && ../node ../node_modules/.bin/nyc report \
		--temp-directory "/Users/anto/programs/node/node/.cov_tmp" \
		--report-dir "/Users/anto/programs/node/node/coverage")
/Users/anto/programs/node/node/node_modules/nyc/node_modules/yargs/yargs.js:1133
      else throw err
           ^

Error: ENOENT: no such file or directory, scandir '/Users/anto/programs/node/node/lib/.nyc_output'
    at Object.readdirSync (fs.js:22200:3)
    at NYC.eachReport (/Users/anto/programs/node/node/node_modules/nyc/index.js:525:31)
    at NYC.getCoverageMapFromAllCoverageFiles (/Users/anto/programs/node/node/node_modules/nyc/index.js:424:8)
    at NYC.report (/Users/anto/programs/node/node/node_modules/nyc/index.js:442:18)
    at Object.exports.handler (/Users/anto/programs/node/node/node_modules/nyc/lib/commands/report.js:48:7)
    at Object.runCommand (/Users/anto/programs/node/node/node_modules/nyc/node_modules/yargs/lib/command.js:235:44)
    at Object.parseArgs [as _parseArgs] (/Users/anto/programs/node/node/node_modules/nyc/node_modules/yargs/yargs.js:1046:30)
    at Object.parse (/Users/anto/programs/node/node/node_modules/nyc/node_modules/yargs/yargs.js:551:25)
    at Object.<anonymous> (/Users/anto/programs/node/node/node_modules/nyc/bin/nyc.js:24:35)
    at Module._compile (internal/modules/cjs/loader.js:10564:30)

I'm on Mojave 0.14. I even tried cleaning up coverage and run several times, but ended up in the same issue above. Anything I'm missing?

@Trott
Copy link
Member

Trott commented Nov 4, 2018

Thanks. I added your change and tried running make coverage, I end up in seeing the below error:

@antsmartian Do you mean @refack's change or @cjihrig's changes in this PR or something else?

@antsmartian
Copy link
Contributor

antsmartian commented Nov 4, 2018

@Trott I have added the changes from this PR:

 if libtoolflag == "--coverage":
        continue

@Trott Trott added wip Issues and PRs that are still a work in progress. and removed wip Issues and PRs that are still a work in progress. labels Nov 4, 2018
@cjihrig
Copy link
Contributor

cjihrig commented Nov 4, 2018

or @cjihrig's changes in this PR

I assume this was supposed to be @evanlucas, but please let me know if I missed something.

@richardlau
Copy link
Member

@antsmartian Maybe check what version of nyc is being used? The error looks similar to #23690 and #23769 pinned the npm install to nyc@13 (but the npm install is only done if node_modules/nyc doesn't exist).

@Trott
Copy link
Member

Trott commented Nov 18, 2018

@nodejs/platform-macos @evanlucas @refack Any chance someone can get this unstuck? Seems like it's close....

@refack
Copy link
Contributor

refack commented Nov 20, 2018

Alternative PR: #24520
(figuring out how to test)

@Trott
Copy link
Member

Trott commented Dec 1, 2018

Since #24520 landed, I assume this can be closed. But if I'm wrong about that, please re-open!

@Trott Trott closed this Dec 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. python PRs and issues that require attention from people who are familiar with Python. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants