Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.3.0] Prevent CredentialHelperEnvironment crash when invoking Bazel outside of a workspace. #18430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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