You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows, Java: non-fatal Java header compilation error while building Bazel #4096
Description of the problem / feature request / question:
Java worker fails with "The filename or extension is too long." error, though this doesn't fail the whole build. The path is actually well below 259 characters, so the error message seems to be misguided.
INFO: From Compiling Java headers src/main/java/com/google/devtools/build/lib/libbuild-base-hjar.jar (441 files):
Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/processes-jni.cc(410): nativeCreateProcess(D:\bazel_build\execroot\io_bazel\external\local_jdk\bin\java.exe): The filename or extension is too long.
If possible, provide a minimal example to reproduce the problem:
// if the direct input spawn failed, try again with transitive inputs to produce better
// better messages
try {
returncontext.exec(
getSpawn(actionExecutionContext.getClientEnv()),
actionExecutionContext);
the build reports an error but succeeds on Windows because the first command's length is above the 32K limit (as the error says) but the second one's isn't -- I found this by logging the lengths of spawn.arguments() and of getSpawn(...).arguments():
JavaHeaderCompileAction must compare that length to the platform command line length limit, and create a parameter file if needed -- /cc @cushon@iirina
to compute the length of the CustomCommandLine, we have multiple options:
naive: flatten it and observe the length
smart: implement a CountingCustomCommandLine that computes the length in its Builder -- /cc @tomlu: WDYT of this?
changed the title [-]Windows, non-fatal Java worker error: "The filename or extension is too long."[/-][+]Windows, Java: non-fatal Java header compilation error while building Bazel[/+]on Mar 28, 2018
This problem isn't specific to Windows, Bazel might trigger it on other platforms too, if the two-tiered spawn's first command is longer than the platform's limit but the second one isn't.
I talked with @aehlig and @dslomov about this problem. Here's what we thought out:
Evaluating the CustomCommandLine to count its length beats the purpose of using one, and a CountingCustomCommandLine (or its Builder) would still need to flatten NestedSets. However that is exactly what SpawnAction.Builder.buildCommandLine() does:
The ...SpawnRunner objects could provide ground truth of the platform limitations such as command length limits, but they lack the ability to turn a specific long command line into a short parameter-file using one, nor do they know whether the executable supports params files anyway. Only the ConfiguredTarget creating the Action knows all this.
Therefore: if the rule anticipates its action exceeding the command length limit, then let the rule create the action with a fallback command line that's guaranteed to be short. We already have a similar machinery in SpawnAction.Builder (see .buildCommandLine() earlier), but we need a generic, Spawn-level solution. The SpawnRunner would evaluate the main command line, compare to the limit, and respectively use the main command line or create a parameter file and use the alternative command line.
Keeping two command lines in sync is error-prone, let's maybe add a state-changing method to CustomCommandLine.Builder that says "all following arguments may go into a params file, and here's the argument to pass this params file".
Deferred params files happened, so this should be easy to fix if it's still happening. We aren't doing the two-tiered spawn thing for header compilation anymore, though, so maybe it's no longer a problem?
Activity
Windows,JNI: check cmd length for CreateProcess
laszlocsomor commentedon Mar 28, 2018
This is still not fixed, see first message on #4924.
I found the culprit:
JavaHeaderCompileActioncreates a "two-tiered spawn":bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
Lines 472 to 476 in 73088a8
bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
Lines 145 to 153 in 73088a8
spawn.arguments()and ofgetSpawn(...).arguments():bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
Line 143 in 73088a8
bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
Line 152 in 73088a8
Solution:
JavaHeaderCompileActionmust compute the length ofdirectCommandLine:bazel/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
Line 492 in 73088a8
JavaHeaderCompileActionmust compare that length to the platform command line length limit, and create a parameter file if needed -- /cc @cushon @iirinaCustomCommandLine, we have multiple options:CountingCustomCommandLinethat computes the length in itsBuilder-- /cc @tomlu: WDYT of this?[-]Windows, non-fatal Java worker error: "The filename or extension is too long."[/-][+]Windows, Java: non-fatal Java header compilation error while building Bazel[/+]laszlocsomor commentedon Mar 28, 2018
This problem isn't specific to Windows, Bazel might trigger it on other platforms too, if the two-tiered spawn's first command is longer than the platform's limit but the second one isn't.
laszlocsomor commentedon Mar 28, 2018
The failing command is in turbine-failure.txt.
Using a parameter file works:
laszlocsomor commentedon Mar 28, 2018
I talked with @aehlig and @dslomov about this problem. Here's what we thought out:
CustomCommandLineto count its length beats the purpose of using one, and aCountingCustomCommandLine(or itsBuilder) would still need to flatten NestedSets. However that is exactly whatSpawnAction.Builder.buildCommandLine()does:bazel/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
Line 689 in 73088a8
...SpawnRunnerobjects could provide ground truth of the platform limitations such as command length limits, but they lack the ability to turn a specific long command line into a short parameter-file using one, nor do they know whether the executable supports params files anyway. Only the ConfiguredTarget creating the Action knows all this.SpawnAction.Builder(see.buildCommandLine()earlier), but we need a generic, Spawn-level solution. The SpawnRunner would evaluate the main command line, compare to the limit, and respectively use the main command line or create a parameter file and use the alternative command line.CustomCommandLine.Builderthat says "all following arguments may go into a params file, and here's the argument to pass this params file".@tomlu , WDYT?
4 remaining items
cushon commentedon Nov 17, 2018
Deferred params files happened, so this should be easy to fix if it's still happening. We aren't doing the two-tiered spawn thing for header compilation anymore, though, so maybe it's no longer a problem?
laszlocsomor commentedon Feb 28, 2019
I haven't seen this issue in a long time, maybe it was accidentally fixed. Setting P3.
meisterT commentedon May 12, 2020
Closing the issue since it seems to be fixed.