Search in sources :

Example 1 with ActionCombinationFactory

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];
        }
    });
}
Also used : ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) AbstractAction(com.google.devtools.build.lib.actions.AbstractAction) Action(com.google.devtools.build.lib.actions.Action) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 2 with ActionCombinationFactory

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();
        }
    });
}
Also used : ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) Action(com.google.devtools.build.lib.actions.Action) RuleContext(com.google.devtools.build.lib.analysis.RuleContext) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 3 with ActionCombinationFactory

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];
        }
    });
}
Also used : AbstractAction(com.google.devtools.build.lib.actions.AbstractAction) Action(com.google.devtools.build.lib.actions.Action) HashMap(java.util.HashMap) TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ActionCombinationFactory

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();
        }
    });
}
Also used : ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) Action(com.google.devtools.build.lib.actions.Action) RuleContext(com.google.devtools.build.lib.analysis.RuleContext) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) FeatureConfiguration(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 5 with ActionCombinationFactory

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);
        }
    });
}
Also used : ActionCombinationFactory(com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) Action(com.google.devtools.build.lib.actions.Action) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Aggregations

Action (com.google.devtools.build.lib.actions.Action)5 Artifact (com.google.devtools.build.lib.actions.Artifact)5 ActionCombinationFactory (com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory)5 Test (org.junit.Test)5 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 AbstractAction (com.google.devtools.build.lib.actions.AbstractAction)2 RuleContext (com.google.devtools.build.lib.analysis.RuleContext)2 FeatureConfiguration (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)1 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)1