Skip to content

Commit

Permalink
Pass environment variables from BlazeCidrLauncher down to bazel
Browse files Browse the repository at this point in the history
fixes #5770, fixes #2042
  • Loading branch information
ujohnny committed Nov 24, 2023
1 parent bf1ea24 commit ef8d38c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.CommandLineState;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.filters.Filter;
import com.intellij.execution.filters.TextConsoleBuilderImpl;
Expand Down Expand Up @@ -193,7 +194,7 @@ private ProcessHandler getScopedProcessHandler(
throws ExecutionException {
return new ScopedBlazeProcessHandler(
project,
blazeCommand,
new GeneralCommandLine(blazeCommand.toList()),
workspaceRoot,
new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,16 @@ public interface ScopedProcessHandlerDelegate {
/**
* Construct a process handler and a context to be used for the life of the process.
*
* @param blazeCommand the blaze command to run
* @param command the blaze command to run
* @param workspaceRoot workspace root
* @param scopedProcessHandlerDelegate delegate methods that will be run with the process's
* context.
* @throws ExecutionException
*/
public ScopedBlazeProcessHandler(
Project project,
BlazeCommand blazeCommand,
WorkspaceRoot workspaceRoot,
ScopedProcessHandlerDelegate scopedProcessHandlerDelegate)
throws ExecutionException {
this(project, blazeCommand.toList(), workspaceRoot, scopedProcessHandlerDelegate);
}

public ScopedBlazeProcessHandler(
Project project,
List<String> command,
GeneralCommandLine command,
WorkspaceRoot workspaceRoot,
ScopedProcessHandlerDelegate scopedProcessHandlerDelegate)
throws ExecutionException {
Expand Down Expand Up @@ -132,7 +124,7 @@ public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
}

private static class CommandLineWithRemappedPath extends GeneralCommandLine {
CommandLineWithRemappedPath(List<String> command) {
CommandLineWithRemappedPath(GeneralCommandLine command) {
super(command);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static class Editor implements RunConfigurationStateEditor {
private final EnvironmentVariablesComponent component = new EnvironmentVariablesComponent();

private Editor() {
component.setText("&Environment variables (only set when debugging)");
component.setText("&Environment variables");
}

@Override
Expand Down
14 changes: 8 additions & 6 deletions clwb/src/com/google/idea/blaze/clwb/run/BlazeCidrLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ private ProcessHandler createProcess(CommandLineState state, List<String> extraB
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
final BlazeCommand command = commandBuilder.build();

final GeneralCommandLine commandLine = new GeneralCommandLine(command.toList());

EnvironmentVariablesData envState = handlerState.getEnvVarsState().getData();
commandLine.withParentEnvironmentType(
envState.isPassParentEnvs() ? ParentEnvironmentType.SYSTEM : ParentEnvironmentType.NONE);
commandLine.getEnvironment().putAll(envState.getEnvs());

return new ScopedBlazeProcessHandler(
project,
command,
commandLine,
workspaceRoot,
new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {
@Override
Expand Down Expand Up @@ -234,11 +241,6 @@ public CidrDebugProcess createDebugProcess(CommandLineState state, XDebugSession
commandLine.addParameters(handlerState.getExeFlagsState().getFlagsForExternalProcesses());
commandLine.addParameters(handlerState.getTestArgs());

EnvironmentVariablesData envState = handlerState.getEnvVarsState().getData();
commandLine.withParentEnvironmentType(
envState.isPassParentEnvs() ? ParentEnvironmentType.SYSTEM : ParentEnvironmentType.NONE);
commandLine.getEnvironment().putAll(envState.getEnvs());

if (CppBlazeRules.RuleTypes.CC_TEST.getKind().equals(configuration.getTargetKind())) {
convertBlazeTestFilterToExecutableFlag().ifPresent(commandLine::addParameters);
}
Expand Down

0 comments on commit ef8d38c

Please sign in to comment.