Skip to content

Commit

Permalink
WIP: Let aquery print environment for all AbstractActions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 2, 2023
1 parent ca8103a commit bf14b1a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
import com.google.devtools.build.lib.actions.ActionExecutionMetadata;
import com.google.devtools.build.lib.actions.ActionKeyContext;
Expand All @@ -32,7 +33,6 @@
import com.google.devtools.build.lib.analysis.SourceManifestAction;
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.actions.Substitution;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionException;
Expand Down Expand Up @@ -174,11 +174,11 @@ private void dumpSingleAction(ConfiguredTarget configuredTarget, ActionAnalysisM
}

// store environment
if (action instanceof SpawnAction) {
SpawnAction spawnAction = (SpawnAction) action;
if (action instanceof AbstractAction) {
AbstractAction spawnAction = (AbstractAction) action;
// TODO(twerth): This handles the fixed environment. We probably want to output the inherited
// environment as well.
ImmutableMap<String, String> fixedEnvironment = spawnAction.getEnvironment().getFixedEnv();
ImmutableMap<String, String> fixedEnvironment = spawnAction.getEffectiveEnvironment(Map.of());
for (Map.Entry<String, String> environmentVariable : fixedEnvironment.entrySet()) {
actionBuilder.addEnvironmentVariables(
AnalysisProtosV2.KeyValuePair.newBuilder()
Expand Down
17 changes: 17 additions & 0 deletions src/test/shell/integration/aquery_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,23 @@ EOF
expect_log "ActionKey:"
}

function test_cc_toolchain_env_entries_included() {
local pkg="${FUNCNAME[0]}"
mkdir -p "$pkg"

touch "$pkg/main.cpp"
cat > "$pkg/BUILD" <<'EOF'
cc_binary(
name = "main",
srcs = ["main.cpp"],
)
EOF
bazel aquery --output=textproto \
"//$pkg:main" >output 2> "$TEST_log" || fail "Expected success"
cat output >> "$TEST_log"
assert_contains "^not_contained" output
}

# TODO(bazel-team): The non-text aquery output formats don't correctly handle
# non-ASCII fields (input/output paths, environment variables, etc).
function DISABLED_test_unicode_textproto() {
Expand Down
1 change: 1 addition & 0 deletions tools/cpp/windows_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def _get_vc_env_vars(repository_ctx, vc_path, msvc_vars_x64, target_arch):
env["INCLUDE"] = msvc_vars_x64["%{msvc_env_include_x64}"]
env["LIB"] = lib.replace("x64", target_arch)
env["PATH"] = escape_string(tools_path.replace("\\", "\\\\")) + ";" + msvc_vars_x64["%{msvc_env_path_x64}"]
print(env)
return env

def setup_vc_env_vars(repository_ctx, vc_path, envvars = [], allow_empty = False, escape = True):
Expand Down

0 comments on commit bf14b1a

Please sign in to comment.