Skip to content

Commit

Permalink
[6.3.0] Prevent CredentialHelperEnvironment crash when invoking Bazel…
Browse files Browse the repository at this point in the history
… outside of a workspace. (bazelbuild#18430)

PiperOrigin-RevId: 532048391
Change-Id: Id8138140f469d76469d417f622bc4ad45a10b914
  • Loading branch information
tjgq authored May 17, 2023
1 parent 899692d commit bf82e7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ private Subprocess spawnSubprocess(CredentialHelperEnvironment environment, Stri
// WindowsSubprocessFactory cannot redirect stdin to subprocess.
return new SubprocessBuilder(JavaSubprocessFactory.INSTANCE)
.setArgv(ImmutableList.<String>builder().add(path.getPathString()).add(args).build())
.setWorkingDirectory(environment.getWorkspacePath().getPathFile())
.setWorkingDirectory(
environment.getWorkspacePath() != null
? environment.getWorkspacePath().getPathFile()
: null)
.setEnv(environment.getClientEnvironment())
.setTimeoutMillis(environment.getHelperExecutionTimeout().toMillis())
.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.vfs.Path;
import java.time.Duration;
import javax.annotation.Nullable;

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

/**
* Returns the (absolute) path to the workspace.
* Returns the absolute path to the workspace, or null if Bazel was invoked outside a workspace.
*
* <p>Used as working directory when invoking the subprocess.
* <p>If available, it will be used as the working directory when invoking the helper subprocess.
* Otherwise, the working directory is inherited from the Bazel server process.
*/
@Nullable
public abstract Path getWorkspacePath();

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

/**
* Sets the (absolute) path to the workspace to use as working directory when invoking the
* subprocess.
* Sets the absolute path to the workspace, or null if Bazel was invoked outside a workspace.
*/
public abstract Builder setWorkspacePath(Path path);
public abstract Builder setWorkspacePath(@Nullable Path path);

/**
* Sets the environment from the Bazel client to pass as environment variables to the
Expand Down

0 comments on commit bf82e7b

Please sign in to comment.