Search in sources :

Example 36 with BuildRule

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

the class NdkLibraryDescriptionTest method transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule.

@Test
public void transitiveCxxLibraryDepsBecomeFirstOrderDepsOfNdkBuildRule() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule transitiveInput = resolver.addToIndex(new FakeBuildRule("//:transitive_input", pathResolver));
    transitiveInput.setOutputFile("out");
    FakeNativeLinkable transitiveDep = resolver.addToIndex(new FakeNativeLinkable("//:transitive_dep", pathResolver, transitiveInput.getSourcePathToOutput()));
    FakeBuildRule firstOrderInput = resolver.addToIndex(new FakeBuildRule("//:first_order_input", pathResolver));
    firstOrderInput.setOutputFile("out");
    FakeNativeLinkable firstOrderDep = resolver.addToIndex(new FakeNativeLinkable("//:first_order_dep", pathResolver, firstOrderInput.getSourcePathToOutput(), transitiveDep));
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRule ndkLibrary = new NdkLibraryBuilder(target).addDep(firstOrderDep.getBuildTarget()).build(resolver);
    assertThat(ndkLibrary.getDeps(), Matchers.allOf(Matchers.<BuildRule>hasItem(firstOrderInput), Matchers.<BuildRule>hasItem(transitiveInput)));
}
Also used : FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) 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 37 with BuildRule

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

the class RobolectricTestRuleTest method runtimeDepsIncludeTransitiveResources.

@Test
public void runtimeDepsIncludeTransitiveResources() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem(temporaryFolder.getRoot());
    BuildTarget genRuleTarget = BuildTargetFactory.newInstance("//:gen");
    TargetNode<?, ?> genRuleNode = GenruleBuilder.newGenruleBuilder(genRuleTarget).setOut("out").build();
    BuildTarget res2RuleTarget = BuildTargetFactory.newInstance("//:res2");
    TargetNode<?, ?> res2Node = AndroidResourceBuilder.createBuilder(res2RuleTarget).setRes(new DefaultBuildTargetSourcePath(genRuleTarget)).setRDotJavaPackage("foo.bar").build();
    BuildTarget robolectricBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base/robolectricTest:robolectricTest");
    TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(robolectricBuildTarget, filesystem).addDep(res2RuleTarget).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genRuleNode, res2Node, robolectricTestNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule genRule = resolver.requireRule(genRuleTarget);
    RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricBuildTarget);
    assertThat(robolectricTest.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(genRule.getBuildTarget()));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 38 with BuildRule

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

the class MultiarchFileTest method descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile.

@SuppressWarnings({ "unchecked" })
@Test
public void descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64");
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64,sandbox");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleLibraryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRule multiarchRule = nodeBuilderFactory.getNodeBuilder(target).build(resolver, filesystem);
    assertThat(multiarchRule, instanceOf(MultiarchFile.class));
    ImmutableList<Step> steps = multiarchRule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    ShellStep step = Iterables.getLast(Iterables.filter(steps, ShellStep.class));
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList<String> command = step.getShellCommand(executionContext);
    assertThat(command, Matchers.contains(endsWith("lipo"), equalTo("-create"), equalTo("-output"), containsString("foo/thing#"), containsString("/thing#"), containsString("/thing#")));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) ShellStep(com.facebook.buck.shell.ShellStep) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 39 with BuildRule

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

the class ApplePackageDescriptionTest method descriptionExpandsLocationMacrosAndTracksDependencies.

@Test
public void descriptionExpandsLocationMacrosAndTracksDependencies() throws Exception {
    ApplePackageDescription description = descriptionWithCommand("echo $(location :exportfile)");
    BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//foo:binary");
    BuildTarget bundleBuildTarget = BuildTargetFactory.newInstance("//foo:bundle");
    BuildTarget exportFileBuildTarget = BuildTargetFactory.newInstance("//foo:exportfile");
    TargetGraph graph = TargetGraphFactory.newInstance(ExportFileBuilder.newExportFileBuilder(exportFileBuildTarget).build(), AppleBinaryBuilder.createBuilder(binaryBuildTarget).build(), AppleBundleBuilder.createBuilder(bundleBuildTarget).setBinary(binaryBuildTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).build());
    ApplePackageDescription.Arg arg = description.createUnpopulatedConstructorArg();
    arg.bundle = bundleBuildTarget;
    BuildTarget packageBuildTarget = BuildTargetFactory.newInstance("//foo:package#macosx-x86_64");
    BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(packageBuildTarget).build();
    resolver.requireAllRules(description.findDepsForTargetFromConstructorArgs(packageBuildTarget, params.getCellRoots(), arg));
    BuildRule rule = description.createBuildRule(graph, params, resolver, arg);
    assertThat(rule.getDeps(), hasItem(resolver.getRule(exportFileBuildTarget)));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 40 with BuildRule

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

the class ApplePackageDescriptionTest method descriptionCreatesExternallyBuiltPackageRuleIfConfigExists.

@Test
public void descriptionCreatesExternallyBuiltPackageRuleIfConfigExists() throws Exception {
    ApplePackageDescription description = descriptionWithCommand("echo");
    BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//foo:binary");
    BuildTarget bundleBuildTarget = BuildTargetFactory.newInstance("//foo:bundle");
    TargetGraph graph = TargetGraphFactory.newInstance(AppleBinaryBuilder.createBuilder(binaryBuildTarget).build(), AppleBundleBuilder.createBuilder(bundleBuildTarget).setBinary(binaryBuildTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).build());
    ApplePackageDescription.Arg arg = description.createUnpopulatedConstructorArg();
    arg.bundle = bundleBuildTarget;
    BuildTarget packageBuildTarget = BuildTargetFactory.newInstance("//foo:package#macosx-x86_64");
    BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(packageBuildTarget).build();
    resolver.requireAllRules(description.findDepsForTargetFromConstructorArgs(packageBuildTarget, params.getCellRoots(), arg));
    BuildRule rule = description.createBuildRule(graph, new FakeBuildRuleParamsBuilder(packageBuildTarget).build(), resolver, arg);
    assertThat(rule, instanceOf(ExternallyBuiltApplePackage.class));
    assertThat(rule.getDeps(), hasItem(resolver.getRule(bundleBuildTarget.withFlavors(InternalFlavor.of("macosx-x86_64")))));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

BuildRule (com.facebook.buck.rules.BuildRule)361 BuildTarget (com.facebook.buck.model.BuildTarget)199 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)190 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 Test (org.junit.Test)175 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)165 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)162 SourcePath (com.facebook.buck.rules.SourcePath)118 Path (java.nio.file.Path)95 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)70 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)70 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)66 TargetGraph (com.facebook.buck.rules.TargetGraph)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)61 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)61 ImmutableList (com.google.common.collect.ImmutableList)58 PathSourcePath (com.facebook.buck.rules.PathSourcePath)51 ImmutableSet (com.google.common.collect.ImmutableSet)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 RuleKey (com.facebook.buck.rules.RuleKey)43