Skip to content

Commit

Permalink
Make SymlinkTreeAction properly use the configuration's environment
Browse files Browse the repository at this point in the history
In particular, fix its use of client make variables.

Fixes #4750.

PiperOrigin-RevId: 197545415
  • Loading branch information
ulfjack authored and Copybara-Service committed May 22, 2018
1 parent c29f34f commit 3da8929
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private static Artifact createRunfilesAction(
inputManifest,
outputManifest,
/*filesetTree=*/ false,
config.getLocalShellEnvironment(),
config.getActionEnvironment(),
config.runfilesEnabled()));
return outputManifest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.actions.ActionEnvironment;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
import com.google.devtools.build.lib.actions.ActionExecutionException;
import com.google.devtools.build.lib.actions.ActionKeyContext;
Expand All @@ -26,6 +27,8 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.util.Fingerprint;
import java.util.LinkedHashMap;
import java.util.Map;

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

/**
Expand All @@ -59,14 +61,13 @@ public SymlinkTreeAction(
Artifact inputManifest,
Artifact outputManifest,
boolean filesetTree,
ImmutableMap<String, String> shellEnvironment,
ActionEnvironment env,
boolean enableRunfiles) {
super(owner, ImmutableList.of(inputManifest), ImmutableList.of(outputManifest));
super(owner, ImmutableList.of(inputManifest), ImmutableList.of(outputManifest), env);
Preconditions.checkArgument(outputManifest.getPath().getBaseName().equals("MANIFEST"));
this.inputManifest = inputManifest;
this.outputManifest = outputManifest;
this.filesetTree = filesetTree;
this.shellEnvironment = shellEnvironment;
this.enableRunfiles = enableRunfiles;
}

Expand Down Expand Up @@ -96,15 +97,21 @@ protected String getRawProgressMessage() {
@Override
protected void computeKey(ActionKeyContext actionKeyContext, Fingerprint fp) {
fp.addString(GUID);
fp.addInt(filesetTree ? 1 : 0);
fp.addBoolean(filesetTree);
fp.addBoolean(enableRunfiles);
fp.addStringMap(env.getFixedEnv());
fp.addStrings(env.getInheritedEnv());
}

@Override
public ActionResult execute(ActionExecutionContext actionExecutionContext)
throws ActionExecutionException, InterruptedException {
Map<String, String> resolvedEnv = new LinkedHashMap<>();
env.resolve(resolvedEnv, actionExecutionContext.getClientEnv());
actionExecutionContext
.getContext(SymlinkTreeActionContext.class)
.createSymlinks(this, actionExecutionContext, shellEnvironment, enableRunfiles);
.createSymlinks(
this, actionExecutionContext, ImmutableMap.copyOf(resolvedEnv), enableRunfiles);
return ActionResult.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public interface SymlinkTreeActionContext extends ActionContext {

/**
* Creates the symlink tree.
*
* @return a list of SpawnResults created during symlink creation, if any
*/
void createSymlinks(
SymlinkTreeAction action,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ ManifestAndRunfiles createApkBuilderSymlinks(RuleContext ruleContext) {
inputManifest,
outputManifest,
false,
ruleContext.getConfiguration().getLocalShellEnvironment(),
ruleContext.getConfiguration().getActionEnvironment(),
ruleContext.getConfiguration().runfilesEnabled()));
return new ManifestAndRunfiles(outputManifest, sourceManifestAction.getGeneratedRunfiles());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.analysis.actions;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.ActionEnvironment;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.util.ActionTester;
import com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Tests {@link SymlinkTreeAction}.
*/
@RunWith(JUnit4.class)
public class SymlinkTreeActionTest extends BuildViewTestCase {
private enum KeyAttributes {
FILESET,
RUNFILES,
FIXED_ENVIRONMENT,
VARIABLE_ENVIRONMENT
}

@Test
public void testComputeKey() throws Exception {
final Artifact inputManifest = getBinArtifactWithNoOwner("dir/manifest.in");
final Artifact outputManifest = getBinArtifactWithNoOwner("dir/MANIFEST");

ActionTester.runTest(
KeyAttributes.class,
new ActionCombinationFactory<KeyAttributes>() {
@Override
public Action generate(ImmutableSet<KeyAttributes> attributesToFlip) {
boolean filesetTree = attributesToFlip.contains(KeyAttributes.FILESET);
boolean enableRunfiles = attributesToFlip.contains(KeyAttributes.RUNFILES);

ActionEnvironment env = ActionEnvironment.create(
attributesToFlip.contains(KeyAttributes.FIXED_ENVIRONMENT)
? ImmutableMap.of("a", "b") : ImmutableMap.of(),
attributesToFlip.contains(KeyAttributes.VARIABLE_ENVIRONMENT)
? ImmutableSet.of("c") : ImmutableSet.of());

return new SymlinkTreeAction(
ActionsTestUtil.NULL_ACTION_OWNER,
inputManifest,
outputManifest,
filesetTree,
env,
enableRunfiles);
}
},
actionKeyContext);
}
}

0 comments on commit 3da8929

Please sign in to comment.