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