-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build bootclasspath in a UTF-8 environment
Copybara Import from #243 BEGIN_PUBLIC Build bootclasspath in a UTF-8 environment (#243) `java` and `javac` convert file and classpaths to absolute paths and thus require a UTF-8 locale to work under a path that contains non-ASCII characters. Unblocks bazelbuild/bazel#24457 Closes #243 END_PUBLIC COPYBARA_INTEGRATE_REVIEW=#243 from fmeum:utf8-environment 05813e4 PiperOrigin-RevId: 700695134 Change-Id: I2f5753720ec3c838a4dd8b6aabf1050c6935ef3d
- Loading branch information
Showing
7 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
load(":bootclasspath_tests.bzl", "bootclasspath_tests") | ||
|
||
bootclasspath_tests( | ||
name = "bootclasspath_tests", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Tests for the bootclasspath rule.""" | ||
|
||
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite") | ||
load("@rules_testing//lib:truth.bzl", "subjects") | ||
|
||
def _test_utf_8_environment(name): | ||
analysis_test( | ||
name = name, | ||
impl = _test_utf_8_environment_impl, | ||
target = Label("//toolchains:platformclasspath"), | ||
) | ||
|
||
def _test_utf_8_environment_impl(env, target): | ||
for action in target.actions: | ||
env_subject = env.expect.where(action = action).that_dict(action.env) | ||
env_subject.keys().contains("LC_CTYPE") | ||
env_subject.get("LC_CTYPE", factory = subjects.str).contains("UTF-8") | ||
|
||
def bootclasspath_tests(name): | ||
test_suite( | ||
name = name, | ||
tests = [ | ||
_test_utf_8_environment, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Determines the environment required for Java actions to support UTF-8. | ||
""" | ||
|
||
visibility("private") | ||
|
||
Utf8EnvironmentInfo = provider( | ||
doc = "The environment required for Java actions to support UTF-8.", | ||
fields = { | ||
"environment": "The environment to use for Java actions to support UTF-8.", | ||
}, | ||
) | ||
|
||
# The default UTF-8 locale on all recent Linux distributions. It is also available in Cygwin and | ||
# MSYS2, but doesn't matter for determining the JVM's platform encoding on Windows, which always | ||
# uses the active code page. | ||
_DEFAULT_UTF8_ENVIRONMENT = Utf8EnvironmentInfo(environment = {"LC_CTYPE": "C.UTF-8"}) | ||
|
||
# macOS doesn't have the C.UTF-8 locale, but en_US.UTF-8 is available and works the same way. | ||
_MACOS_UTF8_ENVIRONMENT = Utf8EnvironmentInfo(environment = {"LC_CTYPE": "en_US.UTF-8"}) | ||
|
||
def _utf8_environment_impl(ctx): | ||
if ctx.target_platform_has_constraint(ctx.attr._macos_constraint[platform_common.ConstraintValueInfo]): | ||
return _MACOS_UTF8_ENVIRONMENT | ||
else: | ||
return _DEFAULT_UTF8_ENVIRONMENT | ||
|
||
utf8_environment = rule( | ||
_utf8_environment_impl, | ||
attrs = { | ||
"_macos_constraint": attr.label(default = "@platforms//os:macos"), | ||
}, | ||
doc = "Returns a suitable environment for Java actions to support UTF-8.", | ||
) |