Skip to content

Commit 3da8929

Browse files
ulfjackCopybara-Service
authored and
Copybara-Service
committed
Make SymlinkTreeAction properly use the configuration's environment
In particular, fix its use of client make variables. Fixes bazelbuild#4750. PiperOrigin-RevId: 197545415
1 parent c29f34f commit 3da8929

File tree

5 files changed

+86
-10
lines changed

5 files changed

+86
-10
lines changed

src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private static Artifact createRunfilesAction(
359359
inputManifest,
360360
outputManifest,
361361
/*filesetTree=*/ false,
362-
config.getLocalShellEnvironment(),
362+
config.getActionEnvironment(),
363363
config.runfilesEnabled()));
364364
return outputManifest;
365365
}

src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeAction.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.common.collect.ImmutableList;
1818
import com.google.common.collect.ImmutableMap;
1919
import com.google.devtools.build.lib.actions.AbstractAction;
20+
import com.google.devtools.build.lib.actions.ActionEnvironment;
2021
import com.google.devtools.build.lib.actions.ActionExecutionContext;
2122
import com.google.devtools.build.lib.actions.ActionExecutionException;
2223
import com.google.devtools.build.lib.actions.ActionKeyContext;
@@ -26,6 +27,8 @@
2627
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
2728
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
2829
import com.google.devtools.build.lib.util.Fingerprint;
30+
import java.util.LinkedHashMap;
31+
import java.util.Map;
2932

3033
/**
3134
* Action responsible for the symlink tree creation.
@@ -40,7 +43,6 @@ public final class SymlinkTreeAction extends AbstractAction {
4043
private final Artifact inputManifest;
4144
private final Artifact outputManifest;
4245
private final boolean filesetTree;
43-
private final ImmutableMap<String, String> shellEnvironment;
4446
private final boolean enableRunfiles;
4547

4648
/**
@@ -59,14 +61,13 @@ public SymlinkTreeAction(
5961
Artifact inputManifest,
6062
Artifact outputManifest,
6163
boolean filesetTree,
62-
ImmutableMap<String, String> shellEnvironment,
64+
ActionEnvironment env,
6365
boolean enableRunfiles) {
64-
super(owner, ImmutableList.of(inputManifest), ImmutableList.of(outputManifest));
66+
super(owner, ImmutableList.of(inputManifest), ImmutableList.of(outputManifest), env);
6567
Preconditions.checkArgument(outputManifest.getPath().getBaseName().equals("MANIFEST"));
6668
this.inputManifest = inputManifest;
6769
this.outputManifest = outputManifest;
6870
this.filesetTree = filesetTree;
69-
this.shellEnvironment = shellEnvironment;
7071
this.enableRunfiles = enableRunfiles;
7172
}
7273

@@ -96,15 +97,21 @@ protected String getRawProgressMessage() {
9697
@Override
9798
protected void computeKey(ActionKeyContext actionKeyContext, Fingerprint fp) {
9899
fp.addString(GUID);
99-
fp.addInt(filesetTree ? 1 : 0);
100+
fp.addBoolean(filesetTree);
101+
fp.addBoolean(enableRunfiles);
102+
fp.addStringMap(env.getFixedEnv());
103+
fp.addStrings(env.getInheritedEnv());
100104
}
101105

102106
@Override
103107
public ActionResult execute(ActionExecutionContext actionExecutionContext)
104108
throws ActionExecutionException, InterruptedException {
109+
Map<String, String> resolvedEnv = new LinkedHashMap<>();
110+
env.resolve(resolvedEnv, actionExecutionContext.getClientEnv());
105111
actionExecutionContext
106112
.getContext(SymlinkTreeActionContext.class)
107-
.createSymlinks(this, actionExecutionContext, shellEnvironment, enableRunfiles);
113+
.createSymlinks(
114+
this, actionExecutionContext, ImmutableMap.copyOf(resolvedEnv), enableRunfiles);
108115
return ActionResult.EMPTY;
109116
}
110117
}

src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkTreeActionContext.java

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public interface SymlinkTreeActionContext extends ActionContext {
2525

2626
/**
2727
* Creates the symlink tree.
28-
*
29-
* @return a list of SpawnResults created during symlink creation, if any
3028
*/
3129
void createSymlinks(
3230
SymlinkTreeAction action,

src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ManifestAndRunfiles createApkBuilderSymlinks(RuleContext ruleContext) {
186186
inputManifest,
187187
outputManifest,
188188
false,
189-
ruleContext.getConfiguration().getLocalShellEnvironment(),
189+
ruleContext.getConfiguration().getActionEnvironment(),
190190
ruleContext.getConfiguration().runfilesEnabled()));
191191
return new ManifestAndRunfiles(outputManifest, sourceManifestAction.getGeneratedRunfiles());
192192
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2018 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.google.devtools.build.lib.analysis.actions;
15+
16+
import com.google.common.collect.ImmutableMap;
17+
import com.google.common.collect.ImmutableSet;
18+
import com.google.devtools.build.lib.actions.Action;
19+
import com.google.devtools.build.lib.actions.ActionEnvironment;
20+
import com.google.devtools.build.lib.actions.Artifact;
21+
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
22+
import com.google.devtools.build.lib.analysis.util.ActionTester;
23+
import com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory;
24+
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.JUnit4;
28+
29+
/**
30+
* Tests {@link SymlinkTreeAction}.
31+
*/
32+
@RunWith(JUnit4.class)
33+
public class SymlinkTreeActionTest extends BuildViewTestCase {
34+
private enum KeyAttributes {
35+
FILESET,
36+
RUNFILES,
37+
FIXED_ENVIRONMENT,
38+
VARIABLE_ENVIRONMENT
39+
}
40+
41+
@Test
42+
public void testComputeKey() throws Exception {
43+
final Artifact inputManifest = getBinArtifactWithNoOwner("dir/manifest.in");
44+
final Artifact outputManifest = getBinArtifactWithNoOwner("dir/MANIFEST");
45+
46+
ActionTester.runTest(
47+
KeyAttributes.class,
48+
new ActionCombinationFactory<KeyAttributes>() {
49+
@Override
50+
public Action generate(ImmutableSet<KeyAttributes> attributesToFlip) {
51+
boolean filesetTree = attributesToFlip.contains(KeyAttributes.FILESET);
52+
boolean enableRunfiles = attributesToFlip.contains(KeyAttributes.RUNFILES);
53+
54+
ActionEnvironment env = ActionEnvironment.create(
55+
attributesToFlip.contains(KeyAttributes.FIXED_ENVIRONMENT)
56+
? ImmutableMap.of("a", "b") : ImmutableMap.of(),
57+
attributesToFlip.contains(KeyAttributes.VARIABLE_ENVIRONMENT)
58+
? ImmutableSet.of("c") : ImmutableSet.of());
59+
60+
return new SymlinkTreeAction(
61+
ActionsTestUtil.NULL_ACTION_OWNER,
62+
inputManifest,
63+
outputManifest,
64+
filesetTree,
65+
env,
66+
enableRunfiles);
67+
}
68+
},
69+
actionKeyContext);
70+
}
71+
}

0 commit comments

Comments
 (0)