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

CI: Mark CGO warnings as errors #3192

Merged
merged 1 commit into from
Sep 2, 2021

Conversation

rata
Copy link
Member

@rata rata commented Aug 31, 2021

This is a follow-up of: #3165. In particular, #3165 (comment).

As pointed out there by @kolyshkin and @tianon there, this adds the -Werror flag to the CI only.

Note that I kept the "-g -O2" that is the default from "go env CGO_CFLAGS". The reason is: the warning that we fixed recently (db8330c) is not seen if we don't use those flags. So, what is expected happens: if no env var CGO_CFLAGS is defined, it uses "-g -O2", but if it is defined, it uses what we specify. Therefore, if we add the env var CGO_CFLAGS to "-Werror" only, then it doesn't use "-g -O2", the warning is not produced and therefore not catched. So, I kept those things, but it is hardcoded (instead of append -Werror to whatever the output of "go env CGO_CFLAGS" is) because github actions need to know it statically if we apply them to all jobs

We can probably append "-Werror" to the output of "go env CGO_CFLAGS", but we need to do that in the "run:" section and, therefore, can't change it for all jobs (we can manually change all jobs if we want that, but we need to also remember in the future).

I prefer hardcoding "-g -O2" rather than changing all jobs or creating a new target that only compiles with -Werror, as we might have more buildtags in the future and IMHO it seems simpler to have all tests in the test workflow compile the same way. But let me know if you prefer otherwise :)

@kolyshkin
Copy link
Contributor

@rata thanks! Now, can you deliberately add a temporary second commit that deliberately introduces an warning to nsexec.c so we can see the CI jobs fail? (can just be a revert of commit db8330c)

Treat warning as errors only in the CI. We can enforce it in the source
code (like setting CFLAGS in libcontainer/nsenter/nsenter.go), but that
can force other downstream to patch the code if thei C compiler produces
warnings. For that reason, we do it only on the CI.

Todays CGO warnings are quite hidden in the CI (only shown for the
compilation step, that is collapsed) and CI is green anyways. With this
patch, CI fails if a warning is introduced.

Signed-off-by: Rodrigo Campos <rodrigo@kinvolk.io>
@rata rata force-pushed the rata/cgo-warnings branch from 9733ef6 to 347c371 Compare August 31, 2021 16:08
@rata
Copy link
Member Author

rata commented Aug 31, 2021

@kolyshkin yes, verified that in a fork before opening the PR already. I even tried with that same commit you mentioned, it works as expected :)

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM

@kolyshkin kolyshkin added this to the 1.1.0 milestone Aug 31, 2021
@AkihiroSuda AkihiroSuda merged commit bde65de into opencontainers:master Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants