Search in sources :

Example 46 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.

the class CxxLinkableEnhancerTest method getTransitiveNativeLinkableInputDoesNotTraversePastNonNativeLinkables.

@Test
public void getTransitiveNativeLinkableInputDoesNotTraversePastNonNativeLinkables() throws Exception {
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build()));
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    // Create a native linkable that sits at the bottom of the dep chain.
    String sentinel = "bottom";
    NativeLinkableInput bottomInput = NativeLinkableInput.of(ImmutableList.of(StringArg.of(sentinel)), ImmutableSet.of(), ImmutableSet.of());
    BuildRule bottom = createNativeLinkable("//:bottom", pathResolver, bottomInput, bottomInput);
    // Create a non-native linkable that sits in the middle of the dep chain, preventing
    // traversals to the bottom native linkable.
    BuildRule middle = new FakeBuildRule("//:middle", pathResolver, bottom);
    // Create a native linkable that sits at the top of the dep chain.
    NativeLinkableInput topInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
    BuildRule top = createNativeLinkable("//:top", pathResolver, topInput, topInput, middle);
    // Now grab all input via traversing deps and verify that the middle rule prevents pulling
    // in the bottom input.
    NativeLinkableInput totalInput = NativeLinkables.getTransitiveNativeLinkableInput(cxxPlatform, ImmutableList.of(top), Linker.LinkableDepType.STATIC, NativeLinkable.class::isInstance);
    assertThat(Arg.stringify(bottomInput.getArgs(), pathResolver), hasItem(sentinel));
    assertThat(Arg.stringify(totalInput.getArgs(), pathResolver), not(hasItem(sentinel)));
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 47 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.

the class RobolectricTestDescriptionTest method rulesExportedFromProvidedDepsBecomeFirstOrderDeps.

@Test
public void rulesExportedFromProvidedDepsBecomeFirstOrderDeps() throws Exception {
    SourcePathResolver emptyPathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    FakeBuildRule exportedRule = new FakeBuildRule("//:exported_rule", emptyPathResolver);
    FakeExportDependenciesRule exportingRule = new FakeExportDependenciesRule("//:exporting_rule", emptyPathResolver, exportedRule);
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(target).addProvidedDep(exportingRule.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(robolectricTestNode, FakeTargetNodeBuilder.build(exportedRule), FakeTargetNodeBuilder.build(exportingRule));
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricTestNode.getBuildTarget());
    assertThat(robolectricTest.getCompiledTestsLibrary().getDeps(), Matchers.<BuildRule>hasItem(exportedRule));
}
Also used : FakeExportDependenciesRule(com.facebook.buck.rules.FakeExportDependenciesRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 48 with FakeBuildRule

use of com.facebook.buck.rules.FakeBuildRule in project buck by facebook.

the class RobolectricTestDescriptionTest method rulesExportedFromDepsBecomeFirstOrderDeps.

@Test
public void rulesExportedFromDepsBecomeFirstOrderDeps() throws Exception {
    SourcePathResolver emptyPathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    FakeBuildRule exportedRule = new FakeBuildRule("//:exported_rule", emptyPathResolver);
    FakeExportDependenciesRule exportingRule = new FakeExportDependenciesRule("//:exporting_rule", emptyPathResolver, exportedRule);
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(target).addDep(exportingRule.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(robolectricTestNode, FakeTargetNodeBuilder.build(exportedRule), FakeTargetNodeBuilder.build(exportingRule));
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricTestNode.getBuildTarget());
    assertThat(robolectricTest.getCompiledTestsLibrary().getDeps(), Matchers.<BuildRule>hasItem(exportedRule));
}
Also used : FakeExportDependenciesRule(com.facebook.buck.rules.FakeExportDependenciesRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)48 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)46 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)46 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)44 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)43 Test (org.junit.Test)43 BuildTarget (com.facebook.buck.model.BuildTarget)34 BuildRule (com.facebook.buck.rules.BuildRule)24 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)14 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)12 RuleKey (com.facebook.buck.rules.RuleKey)11 SourcePath (com.facebook.buck.rules.SourcePath)10 BuildRuleEvent (com.facebook.buck.rules.BuildRuleEvent)9 BuckEventBus (com.facebook.buck.event.BuckEventBus)8 BuildEvent (com.facebook.buck.rules.BuildEvent)8 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)8 Clock (com.facebook.buck.timing.Clock)8 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 ParseEvent (com.facebook.buck.parser.ParseEvent)7