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)));
}
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()));
}
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#")));
}
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)));
}
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")))));
}
Aggregations