Search in sources :

Example 6 with RuleContext

use of com.google.devtools.build.lib.analysis.RuleContext in project bazel by bazelbuild.

the class CppLinkActionTest method testCommandLineSplitting.

@Test
public void testCommandLineSplitting() throws Exception {
    RuleContext ruleContext = createDummyRuleContext();
    Artifact output = getDerivedArtifact(new PathFragment("output/path.xyz"), getTargetConfiguration().getBinDirectory(RepositoryName.MAIN), ActionsTestUtil.NULL_ARTIFACT_OWNER);
    final Artifact outputIfso = getDerivedArtifact(new PathFragment("output/path.ifso"), getTargetConfiguration().getBinDirectory(RepositoryName.MAIN), ActionsTestUtil.NULL_ARTIFACT_OWNER);
    CppLinkActionBuilder builder = new CppLinkActionBuilder(ruleContext, output, CppHelper.getToolchain(ruleContext, ":cc_toolchain"), CppHelper.getFdoSupport(ruleContext, ":cc_toolchain"));
    builder.setLinkType(LinkTargetType.STATIC_LIBRARY);
    assertTrue(builder.canSplitCommandLine());
    builder.setLinkType(LinkTargetType.DYNAMIC_LIBRARY);
    assertTrue(builder.canSplitCommandLine());
    builder.setInterfaceOutput(outputIfso);
    assertFalse(builder.canSplitCommandLine());
    builder.setInterfaceOutput(null);
    builder.setLinkType(LinkTargetType.INTERFACE_DYNAMIC_LIBRARY);
    assertFalse(builder.canSplitCommandLine());
}
Also used : RuleContext(com.google.devtools.build.lib.analysis.RuleContext) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 7 with RuleContext

use of com.google.devtools.build.lib.analysis.RuleContext in project bazel by bazelbuild.

the class FileWriteActionTest method testTransparentCompressionFlagOn.

@Test
public void testTransparentCompressionFlagOn() throws Exception {
    Artifact outputArtifact = getBinArtifactWithNoOwner("destination.txt");
    String contents = generateLongRandomString();
    useConfiguration("--experimental_transparent_compression=true");
    ConfiguredTarget target = scratchConfiguredTarget("a", "a", "filegroup(name='a', srcs=[])");
    RuleContext context = getRuleContext(target);
    FileWriteAction action = FileWriteAction.create(context, outputArtifact, contents, /*makeExecutable=*/
    false);
    assertThat(action.usesCompression()).isTrue();
}
Also used : RuleContext(com.google.devtools.build.lib.analysis.RuleContext) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) LazyString(com.google.devtools.build.lib.util.LazyString) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 8 with RuleContext

use of com.google.devtools.build.lib.analysis.RuleContext 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)

Aggregations

RuleContext (com.google.devtools.build.lib.analysis.RuleContext)8 Artifact (com.google.devtools.build.lib.actions.Artifact)7 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)5 Test (org.junit.Test)5 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)3 FeatureConfiguration (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration)3 Action (com.google.devtools.build.lib.actions.Action)2 ActionCombinationFactory (com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory)2 LazyString (com.google.devtools.build.lib.util.LazyString)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)1 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)1 RunfilesSupport (com.google.devtools.build.lib.analysis.RunfilesSupport)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)1 LinkStaticness (com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness)1 LinkTargetType (com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType)1 LibraryToLink (com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink)1 ExecutionInfoProvider (com.google.devtools.build.lib.rules.test.ExecutionInfoProvider)1 SkylarkCallable (com.google.devtools.build.lib.skylarkinterface.SkylarkCallable)1 LinkedHashMap (java.util.LinkedHashMap)1