Skip to content

Commit bf82e7b

Browse files
authored
[6.3.0] Prevent CredentialHelperEnvironment crash when invoking Bazel outside of a workspace. (#18430)
PiperOrigin-RevId: 532048391 Change-Id: Id8138140f469d76469d417f622bc4ad45a10b914
1 parent 899692d commit bf82e7b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper/CredentialHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ private Subprocess spawnSubprocess(CredentialHelperEnvironment environment, Stri
158158
// WindowsSubprocessFactory cannot redirect stdin to subprocess.
159159
return new SubprocessBuilder(JavaSubprocessFactory.INSTANCE)
160160
.setArgv(ImmutableList.<String>builder().add(path.getPathString()).add(args).build())
161-
.setWorkingDirectory(environment.getWorkspacePath().getPathFile())
161+
.setWorkingDirectory(
162+
environment.getWorkspacePath() != null
163+
? environment.getWorkspacePath().getPathFile()
164+
: null)
162165
.setEnv(environment.getClientEnvironment())
163166
.setTimeoutMillis(environment.getHelperExecutionTimeout().toMillis())
164167
.start();

src/main/java/com/google/devtools/build/lib/authandtls/credentialhelper/CredentialHelperEnvironment.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.devtools.build.lib.events.Reporter;
2020
import com.google.devtools.build.lib.vfs.Path;
2121
import java.time.Duration;
22+
import javax.annotation.Nullable;
2223

2324
/** Environment for running {@link CredentialHelper}s in. */
2425
@AutoValue
@@ -27,10 +28,12 @@ public abstract class CredentialHelperEnvironment {
2728
public abstract Reporter getEventReporter();
2829

2930
/**
30-
* Returns the (absolute) path to the workspace.
31+
* Returns the absolute path to the workspace, or null if Bazel was invoked outside a workspace.
3132
*
32-
* <p>Used as working directory when invoking the subprocess.
33+
* <p>If available, it will be used as the working directory when invoking the helper subprocess.
34+
* Otherwise, the working directory is inherited from the Bazel server process.
3335
*/
36+
@Nullable
3437
public abstract Path getWorkspacePath();
3538

3639
/**
@@ -55,10 +58,9 @@ public abstract static class Builder {
5558
public abstract Builder setEventReporter(Reporter reporter);
5659

5760
/**
58-
* Sets the (absolute) path to the workspace to use as working directory when invoking the
59-
* subprocess.
61+
* Sets the absolute path to the workspace, or null if Bazel was invoked outside a workspace.
6062
*/
61-
public abstract Builder setWorkspacePath(Path path);
63+
public abstract Builder setWorkspacePath(@Nullable Path path);
6264

6365
/**
6466
* Sets the environment from the Bazel client to pass as environment variables to the

0 commit comments

Comments
 (0)