8000 Make warnings errors by isaacbrodsky · Pull Request #70 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make warnings errors #70

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

Merged
merged 10 commits into from
Jun 8, 2018
Merged

Conversation

isaacbrodsky
Copy link
Collaborator

I think we're already at or near 0 warnings, so we could make warnings errors to preserve that. It's also possible some of the compilers in CI have warnings which we don't notice when developing.

Thoughts?

@coveralls
Copy link
coveralls commented Jun 4, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 08e4f1a on isaacbrodsky:warnings-as-errors into abbc693 on uber:master.

Copy link
Contributor
@isaachier isaachier left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -18,7 +18,7 @@ set(CMAKE_C_STANDARD 11)
if(NOT WIN32)
# Compiler options are set only on non-Windows, since these options
# are not correct for MSVC.
set(CMAKE_C_FLAGS_INIT "-Wall")
set(CMAKE_C_FLAGS_INIT "-Wall -Werror")
string(CONCAT CMAKE_C_FLAGS_DEBUG_INIT
"-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types "
"--coverage")
Copy link
Contributor

Choose a reason for hiding this comment

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

Totally unrelated question, where did these flags come from? They look pretty specialized. Why not use defaults and append --coverage to that?

8000
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At least a few of these were added by @dfellis in #8 (1bfa863). Not sure about some of the others.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK thanks. At some point it might be worth revisiting the flags here. I am not sure if they are the best options and if there is a better way to use the toolchain file.

Copy link
Collaborator
@nrabinowitz nrabinowitz left a comment

Choose a reason for hiding this comment

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

Seems good to me.

@isaacbrodsky
Copy link
Collaborator Author
isaacbrodsky commented Jun 5, 2018

Made an update to this PR, warnings as errors are still defaulted on, but also has an option to disable.

edit: and once more for moving the option out of the toolchain file.

CMakeLists.txt Outdated
@@ -47,6 +47,14 @@ set(H3_SOVERSION 1)

project(h3 VERSION ${H3_VERSION})

set(H3_FLAGS "")
if(NOT WIN32)
option(WARNINGS_AS_ERRORS "Warnings are treated as errors" ON)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

CMakeLists.txt Outdated
@@ -47,6 +47,14 @@ set(H3_SOVERSION 1)

project(h3 VERSION ${H3_VERSION})

set(H3_FLAGS "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are the other flags? I'd remove them from cmake/toolchain.cmake and put them here instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems reasonable. I've moved the other flags here.

Copy link
Contributor
@isaachier isaachier left a comment

Choose a reason for hiding this comment

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

Just one more small change.

CMakeLists.txt Outdated
# are not correct for MSVC.
string(CONCAT H3_FLAGS ${H3_FLAGS} "-Wall ")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
Copy link
Contributor

Choose a reason for hiding this comment

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

So I once thought this was a good idea too. Turns out, checking for "Debug" build might be done at build time instead of configuration time, so you need to use a generator expression here. Something like this should do it:

string(CONCAT H3_FLAGS "$<$<CONFIG:Debug>:-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types> ")

More on this topic here: https://stackoverflow.com/a/24470998/1930331.

For the record, I'm not convinced it's a good idea to use -O0 or -g in these options because CMake will add them as the default debug flags.

Copy link
Contributor
8000

Choose a reason for hiding this comment

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

To be clear, please remove the if statement entirely and you can append this generator expression to the earlier -Wall if you'd like.

@isaachier
Copy link
Contributor

I see some of the tests are failing. I've had this issue too, and it has to do with target_compile_options expecting a list instead of a string. This is actually a good thing because now you no longer have to worry about spaces and string concatenation. Just unquote the options above so everything works (for generator expression, just do $<$<CONFIG:Debug>:...> with no wrapping quotes).

CMakeLists.txt Outdated

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND H3_COMPILE_FLAGS
-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the generator expression?

8000

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Haven't been pushed yet, still running some tests locally

@isaacbrodsky
Copy link
Collaborator Author

There was also a second issue that --coverage was no longer passed to the linker, which required adding an additional option there.

CMakeLists.txt Outdated
list(APPEND H3_COMPILE_FLAGS --coverage)
# --coverage is not passed to the linker, so this option is needed
# to fully enable coverage.
list(APPEND H3_LINK_FLAGS -fprofile-arcs)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think --coverage would work here too (at least for GCC and clang). But you are right for adding the linker flags in general.

CMakeLists.txt Outdated
# are not correct for MSVC.
list(APPEND H3_COMPILE_FLAGS -Wall)

list(APPEND H3_COMPILE_FLAGS $<$<CONFIG:Debug>:-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types>)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove -O0 and -g. They don't serve the same purpose here as in the toolchain file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see -g is in the default flags for Debug, but I don't see -O0. What is the reason for removing that option?

CMakeLists.txt Outdated
@@ -147,6 +171,9 @@ set(ALL_SOURCE_FILES
# Build the H3 library
add_library(h3 ${LIB_SOURCE_FILES})

target_compile_options(h3 PRIVATE ${H3_COMPILE_FLAGS})
target_link_libraries(h3 PUBLIC ${H3_LINK_FLAGS})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this PUBLIC?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking of writing this in a different way but didn't update, will fix it.

CHANGELOG.md Outdated
@@ -10,6 +10,7 @@ The public API of this library consists of the functions declared in file
- Generator for the faceCenterPoint table (#67)
### Changed
- Moved Vec3d structure to `vec3d.h` (#67)
- Added CMake `WARNINGS_AS_ERRORS` option, defauled on, for Clang and GCC (#70)
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo, should be defaulted on.

Copy link
Contributor
@isaachier isaachier left a comment

Choose a reason for hiding this comment

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

LGTM

@isaacbrodsky isaacbrodsky merged commit 74bccff into uber:master Jun 8, 2018
@isaacbrodsky isaacbrodsky deleted the warnings-as-errors branch June 8, 2018 16:19
mrdvt92 pushed a commit to mrdvt92/h3 that referenced this pull request Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0