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

build: turn warnings into errors for node sources #32685

Closed
wants to merge 5 commits into from

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Apr 6, 2020

This pr attempts to turn compilation warnings into errors for node's source code.

The motivation for this is to enable these errors to be reported by CI runs on pull requests and be able to fix them before they land.

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

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Apr 6, 2020
@nodejs-github-bot
Copy link
Collaborator

@mscdex
Copy link
Contributor

mscdex commented Apr 6, 2020

Will this cause issues for GCC < 8 and warnings from v8.h?

@addaleax
Copy link
Member

addaleax commented Apr 6, 2020

The motivation for this is to enable these errors to be reported by CI runs on pull requests and be able to fix them before they land.

Can we enable it only for CI then, in some way? I’m worried that we won’t know which environments consumers of our source code compile in and that we won’t know what warnings they receive, particularly warnings from future compiler versions that we aren’t yet aware of.

@danbev
Copy link
Contributor Author

danbev commented Apr 7, 2020

Will this cause issues for GCC < 8 and warnings from v8.h?

I'm not sure about GCC < 8 and for warnings from v8.h they would generate errors instead of warnings.

@danbev
Copy link
Contributor Author

danbev commented Apr 7, 2020

I’m worried that we won’t know which environments consumers of our source code compile in and that we won’t know what warnings they receive, particularly warnings from future compiler versions that we aren’t yet aware of.

That is a good point.

I'm not convinced this is actually worth the effort but I was asked to take a look at doing this and this is what I came up with. I don't see warnings as a big issue and they get fixed pretty quickly as it is.

@sam-github
Copy link
Contributor

I think it could fix a lot of churn if code with warnings (in src under our control!) failed CI, since we CI with known compiler levels, it should be stable-ish. I guess it won't stop all warnings... I'm using clang 11 locally, and its pretty strict.

For local builds, many projects have a ./configure --dev-mode or something of the sort that enables dep tracking, -Werror, etc, but the configure doesn't default to that, so casual devs and build consumers won't see it (but they will if they PR).

danbev added 3 commits April 17, 2020 08:04
This commit attempts to turn compilation warnings into errors for node's
source code.

The motivation for this is to enable these errors to be reported by CI
runs on pull requests and be able to fix them before they land.
Currently, the following warning is generated from the inspector
protocol:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:
In member function
‘virtual std::unique_ptr<node::inspector::protocol::Value>
    node::inspector::protocol::ListValue::clone() const’:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:739:21:
error: redundant move in return statement [-Werror=redundant-move]
  739 |     return std::move(result);
      |            ~~~~~~~~~^~~~~~~~

This commit removes the move for DictionaryValue and ListValue.
This commit adds a configuration time flag named error-on-warn:
$ ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

The motivation for this is that CI jobs can use this flag to turn
warnings into errors.
@danbev danbev force-pushed the warnings-as-errors branch from a3b474e to b9fa8f3 Compare April 17, 2020 07:02
@danbev
Copy link
Contributor Author

danbev commented Apr 17, 2020

I've added a commit with a suggestion for this.
A new configuration flag:

 ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

This can be tested by adding an unused variable to some code in node core:

$ ./configure
$ make -j8
../src/node.cc: In member function ‘int node::Environment::InitializeInspector(std::unique_ptr<node::inspector::ParentInspectorHandle>)’:
../src/node.cc:208:7: warning: unused variable ‘x’ [-Wunused-variable]
  208 |   int x = 10;
      |  

And using the new configuration option:

$ ./configure --error-on-warn
$ make -j8
../src/node.cc: In member function ‘int node::Environment::InitializeInspector(std::unique_ptr<node::inspector::ParentInspectorHandle>)’:
../src/node.cc:208:7: error: unused variable ‘x’ [-Werror=unused-variable]
  208 |   int x = 10;
      |       ^
cc1plus: all warnings being treated as errors

Would something like this work if we add it to the CI jobs?

common.gypi Outdated Show resolved Hide resolved
@richardlau
Copy link
Member

I've added a commit with a suggestion for this.
A new configuration flag:

 ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

Would something like this work if we add it to the CI jobs?

Sounds reasonable to me.

@nodejs-github-bot
Copy link
Collaborator

@richardlau
Copy link
Member

LGTM. For enabling on the CI by default we will need to edit the individual jobs. My plan would be:

  1. Land this PR
  2. Run a platform's node-test-commit-* job (e.g. https://ci.nodejs.org/job/node-test-commit-linux/) with the CONFIG_FLAGS parameter set to --error-on-warn. Check that the job succeeds (they won't at the moment until at least src: fix compiler warnings in node_http2.cc #33014 lands).
  3. If the job succeeds, edit the job to add --error-on-warn as a default parameter, otherwise if it fails raise an issue/PR for fixing the warning.

@danbev
Copy link
Contributor Author

danbev commented Apr 24, 2020

I'd like to land this but this is the first time I've seen a failure for the build-tarball job. Has anyone else see this before? (I'm able to run ./configure && make -j8 tar locally without any failure)

common.gypi Show resolved Hide resolved
node.gyp Show resolved Hide resolved
parser.add_option('--error-on-warn',
action='store_true',
dest='error_on_warn',
help='Turn compiler warnings into errors for node core sources.')
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to have this in the Windows vcbuild.bat also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. The problem for me is that I don't have a windows testing environment anymore. At least if this got merged we could enable this for pull requests.

Copy link
Contributor

@mmarchini mmarchini left a comment

Choose a reason for hiding this comment

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

Can be done on a follow up, but I think it makes sense to set this flag on Actions :)

danbev added a commit that referenced this pull request Apr 30, 2020
This commit adds a configuration time flag named error-on-warn:
$ ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

The motivation for this is that CI jobs can use this flag to turn
warnings into errors.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
danbev added a commit that referenced this pull request Apr 30, 2020
Currently, the following warning is generated from the inspector
protocol:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:
In member function
‘virtual std::unique_ptr<node::inspector::protocol::Value>
    node::inspector::protocol::ListValue::clone() const’:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:739:21:
error: redundant move in return statement [-Werror=redundant-move]
  739 |     return std::move(result);
      |            ~~~~~~~~~^~~~~~~~

This commit removes the move for DictionaryValue and ListValue.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
@danbev
Copy link
Contributor Author

danbev commented Apr 30, 2020

Landed in 2e441e1, and a7ae7aa.

@danbev danbev closed this Apr 30, 2020
@danbev danbev deleted the warnings-as-errors branch April 30, 2020 04:19
targos pushed a commit that referenced this pull request May 4, 2020
This commit adds a configuration time flag named error-on-warn:
$ ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

The motivation for this is that CI jobs can use this flag to turn
warnings into errors.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
targos pushed a commit that referenced this pull request May 4, 2020
Currently, the following warning is generated from the inspector
protocol:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:
In member function
‘virtual std::unique_ptr<node::inspector::protocol::Value>
    node::inspector::protocol::ListValue::clone() const’:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:739:21:
error: redundant move in return statement [-Werror=redundant-move]
  739 |     return std::move(result);
      |            ~~~~~~~~~^~~~~~~~

This commit removes the move for DictionaryValue and ListValue.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
@targos targos mentioned this pull request May 4, 2020
targos pushed a commit that referenced this pull request May 7, 2020
This commit adds a configuration time flag named error-on-warn:
$ ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

The motivation for this is that CI jobs can use this flag to turn
warnings into errors.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
targos pushed a commit that referenced this pull request May 7, 2020
Currently, the following warning is generated from the inspector
protocol:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:
In member function
‘virtual std::unique_ptr<node::inspector::protocol::Value>
    node::inspector::protocol::ListValue::clone() const’:
/out/Release/obj/gen/src/node/inspector/protocol/Protocol.cpp:739:21:
error: redundant move in return statement [-Werror=redundant-move]
  739 |     return std::move(result);
      |            ~~~~~~~~~^~~~~~~~

This commit removes the move for DictionaryValue and ListValue.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
richardlau pushed a commit that referenced this pull request May 11, 2020
This commit adds a configuration time flag named error-on-warn:
$ ./configure --help | grep -A1 error-on-warn
  --error-on-warn       Turn compiler warnings into errors for node core
                        sources.

The motivation for this is that CI jobs can use this flag to turn
warnings into errors.

PR-URL: #32685
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
@richardlau
Copy link
Member

I've cherry-picked a7ae7aa over to v13.x-staging and enabled the flag (after testing) for the UBI 8.1 Linux containered job (which only runs on Node.js 13+). I'd like to avoid, if possible, extra checks in the jobs to detect if the --error-on-warn flag exists, so other jobs will have to wait until we land the flag in 12.x and 10.x.

richardlau added a commit to richardlau/node-1 that referenced this pull request May 13, 2020
XCode builds on macOS do not appear to inherit the `cflags` setting.

Signed-off-by: Richard Lau <[email protected]>

PR-URL: nodejs#33357
Refs: nodejs#32685
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
richardlau added a commit to richardlau/node-1 that referenced this pull request May 13, 2020
Treat warnings as errors for non-deps code on Linux and macOS workflows.

Signed-off-by: Richard Lau <[email protected]>

PR-URL: nodejs#33357
Refs: nodejs#32685
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
codebytere pushed a commit that referenced this pull request May 16, 2020
XCode builds on macOS do not appear to inherit the `cflags` setting.

Signed-off-by: Richard Lau <[email protected]>

PR-URL: #33357
Refs: #32685
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
codebytere pushed a commit that referenced this pull request May 16, 2020
Treat warnings as errors for non-deps code on Linux and macOS workflows.

Signed-off-by: Richard Lau <[email protected]>

PR-URL: #33357
Refs: #32685
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
codebytere pushed a commit that referenced this pull request Jun 7, 2020
Treat warnings as errors for non-deps code on Linux and macOS workflows.

Signed-off-by: Richard Lau <[email protected]>

PR-URL: #33357
Refs: #32685
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants