-
Notifications
You must be signed in to change notification settings - Fork 118
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
Disable gtest warning when building in Release #298
Conversation
@@ -87,6 +87,7 @@ macro(_ament_cmake_gtest_find_gtest) | |||
# mark gtest targets with EXCLUDE_FROM_ALL to only build | |||
# when tests are built which depend on them | |||
set_target_properties(gtest gtest_main PROPERTIES EXCLUDE_FROM_ALL 1) | |||
target_compile_options(gtest PRIVATE -Wno-null-dereference) |
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.
There are a couple of problems here.
The small problem is that the indentation is wrong.
The larger problem is that this won't work in a cross-platform way. It might work on clang on macOS, but it definitely will not work on MSVC on Windows. So we can't do it this way. My preference would be to actually fix the problem in googletest itself with a patch to https://github.com/google/googletest. If we can't get traction there, then a patch to https://github.com/ament/googletest would also work.
Which brings me to my last question. We recently updated the Rolling version of Googletest to 1.10.0. Is the issue fixed there?
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.
I apologize for the indentation error, I was careless.
Regarding the MSVC/macOS, I could check the compiler/OS before adding that flag.
I'm currently working on Foxy, I'll give it a shot in rolling.
I'm using the docker ros:rolling, but the last version of gtest_vendor I can install is 1.8.9000-2focal.20200910.213617
How could I try the latest version?
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.
How could I try the latest version?
That's right, it was released after the latest Rolling sync. The easiest thing to do is to enable the rolling testing repository, by changing your /etc/apt/sources.list.d/ros2-latest.list to look like:
deb http://packages.ros.org/ros2-testing/ubuntu focal main
Thanks. Yes it is still an issue in 1.10, slightly different line, probably due to some added code:
If I restricted this change to Linux or gcc/clang would it be acceptable? |
I still think we should fix this in the upstream googletest (or worst case, our googletest fork). Otherwise, we are disabling this flag for all code that is in tests, which could lead to some bugs. |
I believe it will only affect the gtest library since it's I've tested forcing a nulptr dereference with this changes and it was detected. Also fixing it is not trivial, I just added a few of the errors in there, but there are quite a few:
|
16b56d5
to
0c2e78d
Compare
I've rewritten the changes following https://github.com/ament/ament_cmake/blob/master/ament_cmake_gmock/ament_cmake_gmock-extras.cmake#L88 but changing it to target_compile_flags which is more modern CMake. The PRIVATE keyword ensures that this flags don't extend to libraries that link against gtest/gmock . https://cmake.org/cmake/help/v3.5/command/target_compile_options.html |
@v-lopez FYI, DCO check is failing. |
While I understand the need (and convenience), this looks a lot like a problem resulting from not scoping CMake target configurations properly. Arguably because We shouldn't have to change how we build |
In my case I'm trying to apply company wide stricter build flags, which I do by asking my colleagues to find_package() a package which runs I'm not familiar enough with imported targets so I don't know how it would affect the issue here. I could also ask my colleagues to add the compile options per target, but it's much harder to enforce on our side, but it would remove the need of this PR. But since some warnings were disabled too here https://github.com/ament/ament_cmake/blob/master/ament_cmake_gmock/ament_cmake_gmock-extras.cmake#L88 I was hoping we could disable this one too. I'll fix the DCO right away. |
543218e
to
4695c97
Compare
Hmm, #94 suggests so (although it seems like a workaround that was due to break, and it did for you). @clalancette WDYT? |
That's a fair argument. As long as this is scoped just to the compile of gtest itself, I'm OK with it. Here is CI on this: |
Oh right, this doesn't work as-is because you can't specify this compiler flag on Windows. This will have to be surrounded with |
google/googletest#1303 Signed-off-by: Victor Lopez <victor.lopez@pal-robotics.com>
I added the |
All right, the unstable Windows builds are unstable in the nightlies too, so this is good to go. I'll go ahead and merge. |
A lot of warnings appear when compiling in release, which becomes a blocking issue if your package uses
-Werror=null-dereference
.This removes PR this warning (or error) from the gtest target.
Also discussed but ignored here:
google/googletest#1303