-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Conversation
Will this cause issues for GCC < 8 and warnings from v8.h? |
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. |
I'm not sure about |
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. |
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 |
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.
a3b474e
to
b9fa8f3
Compare
I've added a commit with a suggestion for this. ./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? |
Sounds reasonable to me. |
LGTM. For enabling on the CI by default we will need to edit the individual jobs. My plan would be:
|
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 |
parser.add_option('--error-on-warn', | ||
action='store_true', | ||
dest='error_on_warn', | ||
help='Turn compiler warnings into errors for node core sources.') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 :)
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
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 <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
I've cherry-picked a7ae7aa over to |
XCode builds on macOS do not appear to inherit the `cflags` setting. Signed-off-by: Richard Lau <riclau@uk.ibm.com> PR-URL: nodejs#33357 Refs: nodejs#32685 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Treat warnings as errors for non-deps code on Linux and macOS workflows. Signed-off-by: Richard Lau <riclau@uk.ibm.com> PR-URL: nodejs#33357 Refs: nodejs#32685 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
XCode builds on macOS do not appear to inherit the `cflags` setting. Signed-off-by: Richard Lau <riclau@uk.ibm.com> PR-URL: #33357 Refs: #32685 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Treat warnings as errors for non-deps code on Linux and macOS workflows. Signed-off-by: Richard Lau <riclau@uk.ibm.com> PR-URL: #33357 Refs: #32685 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Treat warnings as errors for non-deps code on Linux and macOS workflows. Signed-off-by: Richard Lau <riclau@uk.ibm.com> PR-URL: #33357 Refs: #32685 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
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), orvcbuild test
(Windows) passes