Search in sources :

Example 26 with DefaultTargetNodeToBuildRuleTransformer

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

the class AndroidTransitiveDependencyGraphTest method findManifestFilesWithTransitiveDeps.

@Test
public void findManifestFilesWithTransitiveDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule dep3 = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep3")).setManifestFile(new FakeSourcePath("manifest3.xml")).build(resolver);
    BuildRule dep2 = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep2")).addDep(dep3.getBuildTarget()).build(resolver);
    BuildRule dep1 = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep1")).setManifestFile(new FakeSourcePath("manifest1.xml")).addDep(dep2.getBuildTarget()).build(resolver);
    assertThat(new AndroidTransitiveDependencyGraph(ImmutableSortedSet.of(dep1)).findManifestFiles(), Matchers.containsInAnyOrder(new FakeSourcePath("manifest1.xml"), new FakeSourcePath("manifest3.xml")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 27 with DefaultTargetNodeToBuildRuleTransformer

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

the class ApkGenruleDescriptionTest method testClasspathTransitiveDepsBecomeFirstOrderDeps.

@Test
public void testClasspathTransitiveDepsBecomeFirstOrderDeps() throws Exception {
    SourcePathResolver emptyPathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget installableApkTarget = BuildTargetFactory.newInstance("//:installable");
    TargetNode<?, ?> installableApkNode = FakeTargetNodeBuilder.build(new FakeInstallable(installableApkTarget, emptyPathResolver));
    TargetNode<?, ?> transitiveDepNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:dep")).addSrc(Paths.get("Dep.java")).build();
    TargetNode<?, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//exciting:target")).addSrc(Paths.get("Other.java")).addDep(transitiveDepNode.getBuildTarget()).build();
    TargetNode<?, ?> genruleNode = ApkGenruleBuilder.create(BuildTargetFactory.newInstance("//:rule")).setOut("out").setCmd("$(classpath //exciting:target)").setApk(installableApkTarget).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(installableApkNode, transitiveDepNode, depNode, genruleNode);
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    BuildRule transitiveDep = resolver.requireRule(transitiveDepNode.getBuildTarget());
    BuildRule dep = resolver.requireRule(depNode.getBuildTarget());
    BuildRule genrule = resolver.requireRule(genruleNode.getBuildTarget());
    assertThat(genrule.getDeps(), Matchers.hasItems(dep, transitiveDep));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) 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 28 with DefaultTargetNodeToBuildRuleTransformer

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

the class DexProducedFromJavaLibraryThatContainsClassFilesTest method getOutputDoesNotAccessWrappedJavaLibrary.

@Test
public void getOutputDoesNotAccessWrappedJavaLibrary() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    JavaLibrary javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).build(ruleResolver);
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:target")).build();
    DexProducedFromJavaLibrary dexProducedFromJavaLibrary = new DexProducedFromJavaLibrary(params, javaLibrary);
    ObjectMapper mapper = ObjectMappers.newDefaultInstance();
    FakeOnDiskBuildInfo onDiskBuildInfo = new FakeOnDiskBuildInfo().putMetadata(DexProducedFromJavaLibrary.WEIGHT_ESTIMATE, "0").putMetadata(DexProducedFromJavaLibrary.CLASSNAMES_TO_HASHES, mapper.writeValueAsString(ImmutableMap.<String, String>of()));
    initialize(dexProducedFromJavaLibrary, onDiskBuildInfo);
    assertFalse(dexProducedFromJavaLibrary.hasOutput());
}
Also used : JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) FakeJavaLibrary(com.facebook.buck.jvm.java.FakeJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeOnDiskBuildInfo(com.facebook.buck.rules.FakeOnDiskBuildInfo) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 29 with DefaultTargetNodeToBuildRuleTransformer

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

the class DummyRDotJavaTest method testRDotJavaBinFolder.

@Test
public void testRDotJavaBinFolder() {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    DummyRDotJava dummyRDotJava = new DummyRDotJava(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//java/com/example:library")).build(), ruleFinder, ImmutableSet.of(), ANDROID_JAVAC_OPTIONS, /* forceFinalResourceIds */
    false, Optional.empty(), Optional.empty(), false);
    assertEquals(BuildTargets.getScratchPath(dummyRDotJava.getProjectFilesystem(), dummyRDotJava.getBuildTarget(), "__%s_rdotjava_bin__"), dummyRDotJava.getRDotJavaBinFolder());
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 30 with DefaultTargetNodeToBuildRuleTransformer

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

the class AppleBinaryDescriptionTest method linkerFlagsLocationMacro.

@Test
public void linkerFlagsLocationMacro() throws Exception {
    assumeThat(Platform.detect(), is(Platform.MACOS));
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule#sandbox," + FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_I386_PLATFORM.getFlavor());
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleBinaryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    AppleBinaryBuilder builder = new AppleBinaryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    BuildRule binary = ((CxxBinary) builder.build(resolver)).getLinkRule();
    assertThat(binary, Matchers.instanceOf(CxxLink.class));
    assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
    assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) CxxBinary(com.facebook.buck.cxx.CxxBinary) BuildRule(com.facebook.buck.rules.BuildRule) Genrule(com.facebook.buck.shell.Genrule) CxxLink(com.facebook.buck.cxx.CxxLink) 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

DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)579 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)578 Test (org.junit.Test)527 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)375 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)352 BuildTarget (com.facebook.buck.model.BuildTarget)257 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)238 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)204 TargetGraph (com.facebook.buck.rules.TargetGraph)182 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)115 SourcePath (com.facebook.buck.rules.SourcePath)110 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 PathSourcePath (com.facebook.buck.rules.PathSourcePath)90 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)70 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)68 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)49