use of com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory in project bazel by bazelbuild.
the class SpawnActionTest method testComputeKey.
@Test
public void testComputeKey() throws Exception {
final Artifact artifactA = getSourceArtifact("a");
final Artifact artifactB = getSourceArtifact("b");
ActionTester.runTest(64, new ActionCombinationFactory() {
@Override
public Action generate(int i) {
SpawnAction.Builder builder = builder();
builder.addOutput(destinationArtifact);
PathFragment executable = (i & 1) == 0 ? artifactA.getExecPath() : artifactB.getExecPath();
if ((i & 2) == 0) {
builder.setExecutable(executable);
} else {
builder.setJavaExecutable(executable, jarArtifact, "Main", ImmutableList.<String>of());
}
builder.setMnemonic((i & 4) == 0 ? "a" : "b");
if ((i & 8) == 0) {
builder.addRunfilesSupplier(runfilesSupplier(artifactA, new PathFragment("a")));
} else {
builder.addRunfilesSupplier(runfilesSupplier(artifactB, new PathFragment("a")));
}
if ((i & 16) == 0) {
builder.addRunfilesSupplier(runfilesSupplier(artifactA, new PathFragment("aa")));
} else {
builder.addRunfilesSupplier(runfilesSupplier(artifactA, new PathFragment("ab")));
}
Map<String, String> env = new HashMap<>();
if ((i & 32) == 0) {
env.put("foo", "bar");
}
builder.setEnvironment(env);
Action[] actions = builder.build(ActionsTestUtil.NULL_ACTION_OWNER, collectingAnalysisEnvironment, targetConfig);
collectingAnalysisEnvironment.registerAction(actions);
return actions[0];
}
});
}
use of com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory in project bazel by bazelbuild.
the class CppLinkActionTest method testComputeKeyStatic.
/**
* This mainly checks that static library links don't have identical keys, and it also compares
* them with simple dynamic library links.
*/
@Test
public void testComputeKeyStatic() throws Exception {
final RuleContext ruleContext = createDummyRuleContext();
final PathFragment staticOutputPath = new PathFragment("dummyRuleContext/output/path.a");
final PathFragment dynamicOutputPath = new PathFragment("dummyRuleContext/output/path.so");
final Artifact staticOutputFile = getBinArtifactWithNoOwner(staticOutputPath.getPathString());
final Artifact dynamicOutputFile = getBinArtifactWithNoOwner(dynamicOutputPath.getPathString());
final Artifact oFile = getSourceArtifact("cc/a.o");
final Artifact oFile2 = getSourceArtifact("cc/a2.o");
final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration();
ActionTester.runTest(4, new ActionCombinationFactory() {
@Override
public Action generate(int i) throws InterruptedException {
CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, (i & 2) == 0 ? staticOutputFile : dynamicOutputFile, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain")) {
};
builder.addCompilationInputs((i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2));
builder.setLinkType((i & 2) == 0 ? LinkTargetType.STATIC_LIBRARY : LinkTargetType.DYNAMIC_LIBRARY);
builder.setLibraryIdentifier("foo");
builder.setFeatureConfiguration(featureConfiguration);
return builder.build();
}
});
}
use of com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory in project bazel by bazelbuild.
the class LTOBackendActionTest method testComputeKey.
@Test
public void testComputeKey() throws Exception {
final Artifact artifactA = getSourceArtifact("a");
final Artifact artifactB = getSourceArtifact("b");
final Artifact artifactAimports = getSourceArtifact("a.imports");
final Artifact artifactBimports = getSourceArtifact("b.imports");
ActionTester.runTest(64, new ActionCombinationFactory() {
@Override
public Action generate(int i) {
LTOBackendAction.Builder builder = new LTOBackendAction.Builder();
builder.addOutput(destinationArtifact);
PathFragment executable = (i & 1) == 0 ? artifactA.getExecPath() : artifactB.getExecPath();
builder.setExecutable(executable);
if ((i & 2) == 0) {
builder.addImportsInfo(new HashMap<PathFragment, Artifact>(), artifactAimports);
} else {
builder.addImportsInfo(new HashMap<PathFragment, Artifact>(), artifactBimports);
}
builder.setMnemonic((i & 4) == 0 ? "a" : "b");
if ((i & 8) == 0) {
builder.addRunfilesSupplier(new RunfilesSupplierImpl(new PathFragment("a"), Runfiles.EMPTY, artifactA));
} else {
builder.addRunfilesSupplier(new RunfilesSupplierImpl(new PathFragment("a"), Runfiles.EMPTY, artifactB));
}
if ((i & 16) == 0) {
builder.addInput(artifactA);
} else {
builder.addInput(artifactB);
}
Map<String, String> env = new HashMap<>();
if ((i & 32) == 0) {
env.put("foo", "bar");
}
builder.setEnvironment(env);
Action[] actions = builder.build(ActionsTestUtil.NULL_ACTION_OWNER, collectingAnalysisEnvironment, targetConfig);
collectingAnalysisEnvironment.registerAction(actions);
return actions[0];
}
});
}
use of com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory in project bazel by bazelbuild.
the class CppLinkActionTest method testComputeKeyNonStatic.
/**
* This mainly checks that non-static links don't have identical keys. Many options are only
* allowed on non-static links, and we test several of them here.
*/
@Test
public void testComputeKeyNonStatic() throws Exception {
final RuleContext ruleContext = createDummyRuleContext();
final PathFragment exeOutputPath = new PathFragment("dummyRuleContext/output/path");
final PathFragment dynamicOutputPath = new PathFragment("dummyRuleContext/output/path.so");
final Artifact staticOutputFile = getBinArtifactWithNoOwner(exeOutputPath.getPathString());
final Artifact dynamicOutputFile = getBinArtifactWithNoOwner(dynamicOutputPath.getPathString());
final Artifact oFile = getSourceArtifact("cc/a.o");
final Artifact oFile2 = getSourceArtifact("cc/a2.o");
final FeatureConfiguration featureConfiguration = getMockFeatureConfiguration();
ActionTester.runTest(64, new ActionCombinationFactory() {
@Override
public Action generate(int i) throws InterruptedException {
CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, (i & 2) == 0 ? dynamicOutputFile : staticOutputFile, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain")) {
};
builder.addCompilationInputs((i & 1) == 0 ? ImmutableList.of(oFile) : ImmutableList.of(oFile2));
if ((i & 2) == 0) {
builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY);
builder.setLibraryIdentifier("foo");
} else {
builder.setLinkType(LinkTargetType.EXECUTABLE);
}
builder.setLinkStaticness(LinkStaticness.DYNAMIC);
builder.setNativeDeps((i & 4) == 0);
builder.setUseTestOnlyFlags((i & 8) == 0);
builder.setFake((i & 16) == 0);
builder.setRuntimeSolibDir((i & 32) == 0 ? null : new PathFragment("so1"));
builder.setFeatureConfiguration(featureConfiguration);
return builder.build();
}
});
}
use of com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory in project bazel by bazelbuild.
the class PopulateTreeArtifactActionTest method testComputeKey.
@Test
public void testComputeKey() throws Exception {
final Artifact archiveA = getSourceArtifact("myArchiveA.zip");
final Artifact archiveB = getSourceArtifact("myArchiveB.zip");
final Artifact treeArtifactToPopulateA = createTreeArtifact("testA/archive_member");
final Artifact treeArtifactToPopulateB = createTreeArtifact("testB/archive_member");
final Artifact archiveManifestA = getSourceArtifact("archiveManifestA.txt");
final Artifact archiveManifestB = getSourceArtifact("archiveManifestB.txt");
final FilesToRunProvider zipperA = FilesToRunProvider.fromSingleExecutableArtifact(getSourceArtifact("unzipBinaryA"));
final FilesToRunProvider zipperB = FilesToRunProvider.fromSingleExecutableArtifact(getSourceArtifact("unzipBinaryB"));
ActionTester.runTest(16, new ActionCombinationFactory() {
@Override
public Action generate(int i) {
Artifact archive = (i & 1) == 0 ? archiveA : archiveB;
Artifact treeArtifactToPopulate = (i & 2) == 0 ? treeArtifactToPopulateA : treeArtifactToPopulateB;
Artifact archiveManifest = (i & 4) == 0 ? archiveManifestA : archiveManifestB;
FilesToRunProvider zipper = (i & 8) == 0 ? zipperA : zipperB;
return new PopulateTreeArtifactAction(ActionsTestUtil.NULL_ACTION_OWNER, archive, archiveManifest, treeArtifactToPopulate, zipper);
}
});
}
Aggregations