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

Silence setlocale warnings in Java stub #17670

Closed
wants to merge 1 commit into from

Conversation

jmmv
Copy link
Contributor

@jmmv jmmv commented Mar 6, 2023

Since 17cfa01, the java_stub_template.txt file calls into the locale tool to check for the presence of cetain locales. These calls correctly send error messages to stderr.

Unfortunately, bash itself is doing locale lookups as soon as it sees that the LANG or LC_* variables are touched, and this results in warnings that pollute the output. In our builds, the output is polluted with hundreds of warnings like these:

bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 100: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 102: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory

There is nothing we can do to avoid these warnings. Trying to set the LANG or LC_* variables via --action_env and --host_action_env has no effect (other than trigger more/different warnings).

The problem stems from https://bugzilla.redhat.com/show_bug.cgi?id=1361965, which has been fixed in various distros but hasn't made its way to the one we are currently using.

Given that it's bash that is complaining, we can easily side-step this issue by patching the template and wrapping the problematic invocations behind "env". In this way, bash never gets to see the locale changes. This change does precisely this.

@google-cla
Copy link

google-cla bot commented Mar 6, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@jmmv jmmv force-pushed the java-locale branch 2 times, most recently from 8500e19 to ab012d7 Compare March 6, 2023 19:07
@fmeum
Copy link
Collaborator

fmeum commented Mar 6, 2023

@cushon Could you review this as you also reviewed my PR that caused the issue?

@jmmv
Copy link
Contributor Author

jmmv commented Mar 6, 2023

Thanks for taking such a quick look! And sorry for the force-push mess; I've been trying to get authorship correctly configured according to something we are trying, and it has been tricky.

@fmeum
Copy link
Collaborator

fmeum commented Mar 6, 2023

Maybe add a comment and a link to the bug to the template? Just to ensure that nobody goes ahead and simplifies it back to its original, buggy state.

@jmmv
Copy link
Contributor Author

jmmv commented Mar 6, 2023

Sure thing. Comment added!

@fmeum
Copy link
Collaborator

fmeum commented Mar 6, 2023

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Mar 6, 2023
@keertk
Copy link
Member

keertk commented Mar 6, 2023

@bazel-io fork 6.2.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Mar 6, 2023
@sgowroji sgowroji added the team-Rules-Java Issues for Java rules label Mar 7, 2023
Since 17cfa01, the java_stub_template.txt file calls into the locale
tool to check for the presence of cetain locales.  These calls correctly
send error messages to stderr.

Unfortunately, *bash* itself is doing locale lookups as soon as it sees
that the LANG or LC_* variables are touched, and this results in
warnings that pollute the output.  In our builds, the output is
polluted with hundreds of warnings like these:

bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 100: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 102: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory

There is nothing we can do to avoid these warnings.  Trying to set the
LANG or LC_* variables via --action_env and --host_action_env has no
effect (other than trigger more/different warnings).

The problem stems from https://bugzilla.redhat.com/show_bug.cgi?id=1361965,
which has been fixed in various distros but hasn't made its way to the one
we are currently using.

Given that it's bash that is complaining, we can easily side-step this
issue by patching the template and wrapping the problematic invocations
behind "env".  In this way, bash never gets to see the locale changes.
This change does precisely this.
@cushon cushon added the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Mar 7, 2023
@copybara-service copybara-service bot closed this in 10587b1 Mar 9, 2023
@sgowroji sgowroji removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Mar 9, 2023
ShreeM01 pushed a commit to ShreeM01/bazel that referenced this pull request Mar 11, 2023
Since 17cfa01, the java_stub_template.txt file calls into the locale tool to check for the presence of cetain locales.  These calls correctly send error messages to stderr.

Unfortunately, *bash* itself is doing locale lookups as soon as it sees that the LANG or LC_* variables are touched, and this results in warnings that pollute the output.  In our builds, the output is polluted with hundreds of warnings like these:

```
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 100: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 102: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
```

There is nothing we can do to avoid these warnings.  Trying to set the LANG or LC_* variables via --action_env and --host_action_env has no effect (other than trigger more/different warnings).

The problem stems from https://bugzilla.redhat.com/show_bug.cgi?id=1361965, which has been fixed in various distros but hasn't made its way to the one we are currently using.

Given that it's bash that is complaining, we can easily side-step this issue by patching the template and wrapping the problematic invocations behind "env".  In this way, bash never gets to see the locale changes. This change does precisely this.

Closes bazelbuild#17670.

PiperOrigin-RevId: 515350095
Change-Id: I1887003802aa329e7fb96f644a2fba906daf5165
ShreeM01 added a commit that referenced this pull request Mar 11, 2023
Since 17cfa01, the java_stub_template.txt file calls into the locale tool to check for the presence of cetain locales.  These calls correctly send error messages to stderr.

Unfortunately, *bash* itself is doing locale lookups as soon as it sees that the LANG or LC_* variables are touched, and this results in warnings that pollute the output.  In our builds, the output is polluted with hundreds of warnings like these:

```
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 100: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 102: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
```

There is nothing we can do to avoid these warnings.  Trying to set the LANG or LC_* variables via --action_env and --host_action_env has no effect (other than trigger more/different warnings).

The problem stems from https://bugzilla.redhat.com/show_bug.cgi?id=1361965, which has been fixed in various distros but hasn't made its way to the one we are currently using.

Given that it's bash that is complaining, we can easily side-step this issue by patching the template and wrapping the problematic invocations behind "env".  In this way, bash never gets to see the locale changes. This change does precisely this.

Closes #17670.

PiperOrigin-RevId: 515350095
Change-Id: I1887003802aa329e7fb96f644a2fba906daf5165

Co-authored-by: Julio Merino <julio.merino+oss@snowflake.com>
@fmeum
Copy link
Collaborator

fmeum commented Apr 14, 2023

@jmmv I am still seeing this issue in logs: https://buildkite.com/bazel/bazel-bazel-github-presubmit/builds/15347#01877f7c-1fd5-4606-9e19-e98ba8b227ba/281-313
Do you know whether there are other possible sources for this warning?

@jmmv
Copy link
Contributor Author

jmmv commented Apr 16, 2023

@fmeum The line numbers in those messages don't match the new code. It looks like the fix is not in 6.1.1.

@jmmv jmmv deleted the java-locale branch May 24, 2023 16:19
fweikert pushed a commit to fweikert/bazel that referenced this pull request May 25, 2023
Since 17cfa01, the java_stub_template.txt file calls into the locale tool to check for the presence of cetain locales.  These calls correctly send error messages to stderr.

Unfortunately, *bash* itself is doing locale lookups as soon as it sees that the LANG or LC_* variables are touched, and this results in warnings that pollute the output.  In our builds, the output is polluted with hundreds of warnings like these:

```
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 100: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
bazel-out/aarch64-opt-exec-CF41B97/bin/external/bfg/lang/java/src/main/java/com/google/devtools/build/bfg/JavaSourceFileParserCli: line 102: warning: setlocale: LC_CTYPE: cannot change locale (): No such file or directory
```

There is nothing we can do to avoid these warnings.  Trying to set the LANG or LC_* variables via --action_env and --host_action_env has no effect (other than trigger more/different warnings).

The problem stems from https://bugzilla.redhat.com/show_bug.cgi?id=1361965, which has been fixed in various distros but hasn't made its way to the one we are currently using.

Given that it's bash that is complaining, we can easily side-step this issue by patching the template and wrapping the problematic invocations behind "env".  In this way, bash never gets to see the locale changes. This change does precisely this.

Closes bazelbuild#17670.

PiperOrigin-RevId: 515350095
Change-Id: I1887003802aa329e7fb96f644a2fba906daf5165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants