Skip to content

Commit

Permalink
Add --incompatible_utf8_locale_in_action_env
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Apr 8, 2022
1 parent 2b3bd3e commit cdedef8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ public static class StrictActionEnvOptions extends FragmentOptions {
+ "can prevent cross-user caching if a shared cache is used.")
public boolean useStrictActionEnv;

@Option(
name = "incompatible_utf8_locale_in_action_env",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE}
)
public boolean setUtf8LocaleInActionEnv;

@Override
public StrictActionEnvOptions getHost() {
StrictActionEnvOptions host = (StrictActionEnvOptions) getDefault();
Expand Down Expand Up @@ -184,6 +193,8 @@ public StrictActionEnvConfiguration(BuildOptions buildOptions) {}
public static final Function<BuildOptions, ActionEnvironment> SHELL_ACTION_ENV =
(BuildOptions options) -> {
boolean strictActionEnv = options.get(StrictActionEnvOptions.class).useStrictActionEnv;
boolean utf8LocaleInActionEnv = options.get(
StrictActionEnvOptions.class).setUtf8LocaleInActionEnv;
OS os = OS.getCurrent();
PathFragment shellExecutable = SHELL_EXECUTABLE.apply(options);
TreeMap<String, String> env = new TreeMap<>();
Expand Down Expand Up @@ -211,6 +222,13 @@ public StrictActionEnvConfiguration(BuildOptions buildOptions) {}
env.put("PATH", null);
}

if (utf8LocaleInActionEnv) {
// Without setting this variable, tools (e.g. the JVM) may fall back to supporting only
// ASCII file paths and/or contents. The semantically ideal value would be "C.UTF-8", but
// this locale is not universally supported.
env.put("LC_CTYPE", "en_US.UTF-8");
}

// Shell environment variables specified via options take precedence over the
// ones inherited from the fragments. In the long run, these fragments will
// be replaced by appropriate default rc files anyway.
Expand Down
28 changes: 28 additions & 0 deletions src/test/shell/bazel/unicode_filenames_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,32 @@ function test_utf8_source_artifact_in_bep() {
expect_log '"name":"pkg/srcs/ünïcödë fïlë.txt"'
}

function test_utf8_filename_in_java_test() {
touch WORKSPACE
mkdir pkg

cat >pkg/BUILD <<'EOF'
java_test(
name = "Test",
srcs = ["Test.java"],
main_class = "Test",
use_testrunner = False,
)
EOF

cat >pkg/Test.java <<'EOF'
import java.nio.file.Files;
import java.io.IOException;
class Test {
public static void main(String[] args) throws IOException {
Files.createTempFile("æøå", null);
}
}
EOF

bazel test //pkg:Test --incompatible_utf8_locale_in_action_env \
--test_output=errors 2>$TEST_log || fail "Test should pass"
}

run_suite "Tests for handling of Unicode filenames"

0 comments on commit cdedef8

Please sign in to comment.