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

Make original working directory available to commands that are run #3635

Closed
wants to merge 1 commit into from
Closed
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 @@ -73,7 +73,9 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Builds and run a target with the given command line arguments.
Expand Down Expand Up @@ -320,8 +322,11 @@ public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
env.getReporter().handle(Event.info(
null, "Running command line: " + ShellEscaper.escapeJoinAll(prettyCmdLine)));

Map<String, String> clientEnv = new HashMap<String, String>(env.getClientEnv());
clientEnv.put("BAZEL_PWD", env.getWorkingDirectory().getPathString());

com.google.devtools.build.lib.shell.Command command = new CommandBuilder()
.addArgs(cmdLine).setEnv(env.getClientEnv()).setWorkingDir(workingDir).build();
.addArgs(cmdLine).setEnv(clientEnv).setWorkingDir(workingDir).build();

try {
// Restore a raw EventHandler if it is registered. This allows for blaze run to produce the
Expand Down