Search in sources :

Example 1 with VersionedAliasBuilder

use of com.facebook.buck.versions.VersionedAliasBuilder in project buck by facebook.

the class AuditClasspathCommandTest method testClassPathWithVersions.

@Test
public void testClassPathWithVersions() throws Exception {
    // Build the test target graph.
    TargetNode<?, ?> javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-java-library")).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
    TargetNode<?, ?> androidLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-android-library")).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(javaLibrary.getBuildTarget()).build();
    TargetNode<?, ?> version = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:version")).setVersions("1.0", "//:test-android-library").build();
    TargetNode<?, ?> binary = new JavaBinaryRuleBuilder(BuildTargetFactory.newInstance("//:rule")).setDeps(ImmutableSortedSet.of(version.getBuildTarget())).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibrary, androidLibrary, version, binary);
    // Run the command.
    auditClasspathCommand.printClasspath(params.withBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("build", ImmutableMap.of("versions", "true"))).build()), targetGraph, ImmutableSet.of(androidLibrary.getBuildTarget(), javaLibrary.getBuildTarget()));
    // Verify output.
    Path root = javaLibrary.getBuildTarget().getUnflavoredBuildTarget().getCellPath();
    ImmutableSortedSet<String> expectedPaths = ImmutableSortedSet.of(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), androidLibrary.getBuildTarget(), "lib__%s__output").resolve(androidLibrary.getBuildTarget().getShortName() + ".jar")).toString(), root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar")).toString());
    String expectedClasspath = Joiner.on("\n").join(expectedPaths) + "\n";
    assertEquals(expectedClasspath, console.getTextWrittenToStdOut());
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) Test(org.junit.Test)

Example 2 with VersionedAliasBuilder

use of com.facebook.buck.versions.VersionedAliasBuilder in project buck by facebook.

the class AuditClasspathCommandTest method testJsonClassPathWithVersions.

@Test
public void testJsonClassPathWithVersions() throws Exception {
    // Build the test target graph.
    TargetNode<?, ?> javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-java-library")).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
    TargetNode<?, ?> androidLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-android-library")).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(javaLibrary.getBuildTarget()).build();
    TargetNode<?, ?> version = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:version")).setVersions("1.0", "//:test-android-library").build();
    TargetNode<?, ?> binary = new JavaBinaryRuleBuilder(BuildTargetFactory.newInstance("//:rule")).setDeps(ImmutableSortedSet.of(version.getBuildTarget())).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibrary, androidLibrary, version, binary);
    // Run the command.
    auditClasspathCommand.printJsonClasspath(params.withBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("build", ImmutableMap.of("versions", "true"))).build()), targetGraph, ImmutableSet.of(androidLibrary.getBuildTarget(), javaLibrary.getBuildTarget()));
    // Verify output.
    Path root = javaLibrary.getBuildTarget().getCellPath();
    ObjectMapper mapper = ObjectMappers.newDefaultInstance();
    String expected = String.format(EXPECTED_JSON, mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar"))), mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), androidLibrary.getBuildTarget(), "lib__%s__output").resolve(androidLibrary.getBuildTarget().getShortName() + ".jar"))), mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar"))));
    assertEquals(expected, console.getTextWrittenToStdOut());
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) Test(org.junit.Test)

Example 3 with VersionedAliasBuilder

use of com.facebook.buck.versions.VersionedAliasBuilder in project buck by facebook.

the class PythonLibraryDescriptionTest method versionedSrcs.

@Test
public void versionedSrcs() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
    SourcePath matchedSource = new FakeSourcePath("foo/a.py");
    SourcePath unmatchedSource = new FakeSourcePath("foo/b.py");
    GenruleBuilder transitiveDepBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:tdep")).setOut("out");
    VersionedAliasBuilder depBuilder = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:dep")).setVersions(ImmutableMap.of(Version.of("1.0"), transitiveDepBuilder.getTarget(), Version.of("2.0"), transitiveDepBuilder.getTarget()));
    AbstractNodeBuilder<?, ?, ?> builder = new PythonLibraryBuilder(target).setVersionedSrcs(VersionMatchedCollection.<SourceList>builder().add(ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(matchedSource))).add(ImmutableMap.of(depBuilder.getTarget(), Version.of("2.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(unmatchedSource))).build());
    TargetGraph targetGraph = VersionedTargetGraphBuilder.transform(new FixedVersionSelector(ImmutableMap.of(builder.getTarget(), ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")))), TargetGraphAndBuildTargets.of(TargetGraphFactory.newInstance(transitiveDepBuilder.build(), depBuilder.build(), builder.build()), ImmutableSet.of(builder.getTarget())), new ForkJoinPool()).getTargetGraph();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PythonLibrary library = (PythonLibrary) resolver.requireRule(builder.getTarget());
    assertThat(library.getPythonPackageComponents(PythonTestUtils.PYTHON_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORM).getModules().values(), Matchers.contains(matchedSource));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) CxxGenruleBuilder(com.facebook.buck.cxx.CxxGenruleBuilder) FixedVersionSelector(com.facebook.buck.versions.FixedVersionSelector) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) SourceList(com.facebook.buck.rules.coercer.SourceList) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test)

Example 4 with VersionedAliasBuilder

use of com.facebook.buck.versions.VersionedAliasBuilder in project buck by facebook.

the class CxxGenruleDescriptionTest method versionedTargetReferenceIsTranslatedInVersionedGraph.

@Test
public void versionedTargetReferenceIsTranslatedInVersionedGraph() throws Exception {
    VersionPropagatorBuilder dep = new VersionPropagatorBuilder("//:dep");
    VersionedAliasBuilder versionedDep = new VersionedAliasBuilder("//:versioned").setVersions("1.0", "//:dep");
    CxxGenruleBuilder genruleBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setCmd("$(ldflags-shared //:versioned)");
    TargetGraph graph = TargetGraphFactory.newInstance(dep.build(), versionedDep.build(), genruleBuilder.build());
    TargetGraphAndBuildTargets transformed = VersionedTargetGraphBuilder.transform(new NaiveVersionSelector(), TargetGraphAndBuildTargets.of(graph, ImmutableSet.of(genruleBuilder.getTarget())), POOL);
    CxxGenruleDescription.Arg arg = extractArg(transformed.getTargetGraph().get(genruleBuilder.getTarget()), CxxGenruleDescription.Arg.class);
    assertThat(arg.cmd, OptionalMatchers.present(Matchers.equalTo("$(ldflags-shared //:dep)")));
}
Also used : NaiveVersionSelector(com.facebook.buck.versions.NaiveVersionSelector) VersionPropagatorBuilder(com.facebook.buck.versions.VersionPropagatorBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) Test(org.junit.Test)

Example 5 with VersionedAliasBuilder

use of com.facebook.buck.versions.VersionedAliasBuilder in project buck by facebook.

the class CxxGenruleDescriptionTest method versionPropagatorTargetReferenceIsTranslatedInVersionedGraph.

@Test
public void versionPropagatorTargetReferenceIsTranslatedInVersionedGraph() throws Exception {
    VersionPropagatorBuilder transitiveDep = new VersionPropagatorBuilder("//:transitive_dep");
    VersionedAliasBuilder versionedDep = new VersionedAliasBuilder("//:versioned").setVersions("1.0", "//:transitive_dep");
    VersionPropagatorBuilder dep = new VersionPropagatorBuilder("//:dep").setDeps("//:versioned");
    CxxGenruleBuilder genruleBuilder = new CxxGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setCmd("$(ldflags-shared //:dep)");
    TargetGraph graph = TargetGraphFactory.newInstance(transitiveDep.build(), versionedDep.build(), dep.build(), genruleBuilder.build());
    TargetGraphAndBuildTargets transformed = VersionedTargetGraphBuilder.transform(new NaiveVersionSelector(), TargetGraphAndBuildTargets.of(graph, ImmutableSet.of(genruleBuilder.getTarget())), POOL);
    CxxGenruleDescription.Arg arg = extractArg(transformed.getTargetGraph().get(genruleBuilder.getTarget()), CxxGenruleDescription.Arg.class);
    assertThat(arg.cmd, OptionalMatchers.present(Matchers.matchesPattern(Pattern.quote("$(ldflags-shared //:dep#v") + "[a-zA-Z0-9]*" + Pattern.quote(")"))));
}
Also used : NaiveVersionSelector(com.facebook.buck.versions.NaiveVersionSelector) VersionPropagatorBuilder(com.facebook.buck.versions.VersionPropagatorBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) Test(org.junit.Test)

Aggregations

TargetGraph (com.facebook.buck.rules.TargetGraph)6 VersionedAliasBuilder (com.facebook.buck.versions.VersionedAliasBuilder)6 Test (org.junit.Test)6 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 CxxGenruleBuilder (com.facebook.buck.cxx.CxxGenruleBuilder)2 JavaBinaryRuleBuilder (com.facebook.buck.jvm.java.JavaBinaryRuleBuilder)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 SourcePath (com.facebook.buck.rules.SourcePath)2 TargetGraphAndBuildTargets (com.facebook.buck.rules.TargetGraphAndBuildTargets)2 SourceList (com.facebook.buck.rules.coercer.SourceList)2 GenruleBuilder (com.facebook.buck.shell.GenruleBuilder)2 FixedVersionSelector (com.facebook.buck.versions.FixedVersionSelector)2 NaiveVersionSelector (com.facebook.buck.versions.NaiveVersionSelector)2 VersionPropagatorBuilder (com.facebook.buck.versions.VersionPropagatorBuilder)2 Path (java.nio.file.Path)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1