use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class OmnibusTest method excludedAndIncludedDeps.
@Test
public void excludedAndIncludedDeps() throws NoSuchBuildTargetException {
NativeLinkable a = new OmnibusNode("//:a");
NativeLinkable b = new OmnibusSharedOnlyNode("//:b");
NativeLinkTarget root = new OmnibusRootNode("//:root", ImmutableList.of(a, b));
// Verify the spec.
Omnibus.OmnibusSpec spec = Omnibus.buildSpec(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(root), ImmutableList.of());
assertThat(spec.getGraph().getNodes(), Matchers.containsInAnyOrder(a.getBuildTarget()));
assertThat(spec.getBody().keySet(), Matchers.containsInAnyOrder(a.getBuildTarget()));
assertThat(spec.getRoots().keySet(), Matchers.containsInAnyOrder(root.getBuildTarget()));
assertThat(spec.getDeps().keySet(), Matchers.containsInAnyOrder(b.getBuildTarget()));
assertThat(spec.getExcluded().keySet(), Matchers.containsInAnyOrder(b.getBuildTarget()));
// Verify the libs.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableMap<String, SourcePath> libs = toSonameMap(Omnibus.getSharedLibraries(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:rule")).build(), resolver, ruleFinder, CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(), ImmutableList.of(root), ImmutableList.of()));
assertThat(libs.keySet(), Matchers.containsInAnyOrder(root.getBuildTarget().toString(), b.getBuildTarget().toString(), "libomnibus.so"));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get(root.getBuildTarget().toString())), pathResolver, root.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM), b.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED));
assertThat(libs.get(b.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get("libomnibus.so")), pathResolver, a.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class OmnibusTest method excludedDepExcludesTransitiveDep.
@Test
public void excludedDepExcludesTransitiveDep() throws NoSuchBuildTargetException {
NativeLinkable a = new OmnibusNode("//:a");
NativeLinkable b = new OmnibusNode("//:b");
NativeLinkable c = new OmnibusSharedOnlyNode("//:c", ImmutableList.of(b));
NativeLinkTarget root = new OmnibusRootNode("//:root", ImmutableList.of(a, c));
// Verify the spec.
Omnibus.OmnibusSpec spec = Omnibus.buildSpec(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(root), ImmutableList.of());
assertThat(spec.getGraph().getNodes(), Matchers.containsInAnyOrder(a.getBuildTarget()));
assertThat(spec.getBody().keySet(), Matchers.containsInAnyOrder(a.getBuildTarget()));
assertThat(spec.getRoots().keySet(), Matchers.containsInAnyOrder(root.getBuildTarget()));
assertThat(spec.getDeps().keySet(), Matchers.containsInAnyOrder(c.getBuildTarget()));
assertThat(spec.getExcluded().keySet(), Matchers.containsInAnyOrder(b.getBuildTarget(), c.getBuildTarget()));
// Verify the libs.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableMap<String, SourcePath> libs = toSonameMap(Omnibus.getSharedLibraries(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:rule")).build(), resolver, ruleFinder, CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(), ImmutableList.of(root), ImmutableList.of()));
assertThat(libs.keySet(), Matchers.containsInAnyOrder(root.getBuildTarget().toString(), b.getBuildTarget().toString(), c.getBuildTarget().toString(), "libomnibus.so"));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get(root.getBuildTarget().toString())), pathResolver, root.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM), c.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED));
assertThat(libs.get(b.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
assertThat(libs.get(c.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get("libomnibus.so")), pathResolver, a.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class OmnibusTest method depOfExcludedRoot.
@Test
public void depOfExcludedRoot() throws NoSuchBuildTargetException {
NativeLinkable a = new OmnibusNode("//:a");
NativeLinkTarget root = new OmnibusRootNode("//:root", ImmutableList.of(a));
NativeLinkable b = new OmnibusNode("//:b");
NativeLinkable excludedRoot = new OmnibusNode("//:excluded_root", ImmutableList.of(b));
// Verify the spec.
Omnibus.OmnibusSpec spec = Omnibus.buildSpec(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(root), ImmutableList.of(excludedRoot));
assertThat(spec.getGraph().getNodes(), Matchers.containsInAnyOrder(a.getBuildTarget()));
assertThat(spec.getBody().keySet(), Matchers.containsInAnyOrder(a.getBuildTarget()));
assertThat(spec.getRoots().keySet(), Matchers.containsInAnyOrder(root.getBuildTarget()));
assertThat(spec.getDeps().keySet(), Matchers.empty());
assertThat(spec.getExcluded().keySet(), Matchers.containsInAnyOrder(excludedRoot.getBuildTarget(), b.getBuildTarget()));
// Verify the libs.
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableMap<String, SourcePath> libs = toSonameMap(Omnibus.getSharedLibraries(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:rule")).build(), resolver, ruleFinder, CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(), ImmutableList.of(root), ImmutableList.of(excludedRoot)));
assertThat(libs.keySet(), Matchers.containsInAnyOrder(root.getBuildTarget().toString(), excludedRoot.getBuildTarget().toString(), b.getBuildTarget().toString(), "libomnibus.so"));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get(root.getBuildTarget().toString())), pathResolver, root.getNativeLinkTargetInput(CxxPlatformUtils.DEFAULT_PLATFORM));
assertThat(libs.get(excludedRoot.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
assertThat(libs.get(b.getBuildTarget().toString()), Matchers.not(Matchers.instanceOf(ExplicitBuildTargetSourcePath.class)));
assertCxxLinkContainsNativeLinkableInput(getCxxLinkRule(ruleFinder, libs.get("libomnibus.so")), pathResolver, a.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class DefaultJavaLibraryTest method createDefaultJavaLibraryRuleWithAbiKey.
private BuildRule createDefaultJavaLibraryRuleWithAbiKey(BuildTarget buildTarget, ImmutableSet<String> srcs, ImmutableSortedSet<BuildRule> deps, ImmutableSortedSet<BuildRule> exportedDeps, Optional<AbstractJavacOptions.SpoolMode> spoolMode, ImmutableList<String> postprocessClassesCommands) {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
ImmutableSortedSet<? extends SourcePath> srcsAsPaths = FluentIterable.from(srcs).transform(Paths::get).transform(p -> new PathSourcePath(projectFilesystem, p)).toSortedSet(Ordering.natural());
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.copyOf(deps)).build();
JavacOptions javacOptions = spoolMode.isPresent() ? JavacOptions.builder(DEFAULT_JAVAC_OPTIONS).setSpoolMode(spoolMode.get()).build() : DEFAULT_JAVAC_OPTIONS;
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(buildRuleParams, new SourcePathResolver(ruleFinder), ruleFinder, srcsAsPaths, /* resources */
ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
Optional.empty(), postprocessClassesCommands, exportedDeps, /* providedDeps */
ImmutableSortedSet.of(), ImmutableSortedSet.of(), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), /* resourcesRoot */
Optional.empty(), /* manifest file */
Optional.empty(), /* mavenCoords */
Optional.empty(), /* tests */
ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of()) {
};
ruleResolver.addToIndex(defaultJavaLibrary);
return defaultJavaLibrary;
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class JavaBinaryTest method testGetExecutableCommand.
@Test
public void testGetExecutableCommand() throws Exception {
// prebuilt_jar //third_party/generator:generator
PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/generator:generator")).setBinaryJar(PATH_TO_GENERATOR_JAR).build();
// prebuilt_jar //third_party/guava:guava
TargetNode<?, ?> guavaNode = PrebuiltJarBuilder.createBuilder(BuildTargetFactory.newInstance("//third_party/guava:guava")).setBinaryJar(PATH_TO_GUAVA_JAR).build();
// java_library //java/com/facebook/base:base
TargetNode<?, ?> libraryNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/facebook/base:base")).addSrc(Paths.get("java/com/facebook/base/Base.java")).addDep(guavaNode.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(guavaNode, libraryNode);
BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildRule libraryRule = ruleResolver.requireRule(libraryNode.getBuildTarget());
BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//java/com/facebook/base:Main")).setDeclaredDeps(ImmutableSortedSet.of(libraryRule)).build();
// java_binary //java/com/facebook/base:Main
JavaBinary javaBinary = ruleResolver.addToIndex(new JavaBinary(params, new ExternalJavaRuntimeLauncher("/foobar/java"), "com.facebook.base.Main", null, /* merge manifests */
true, null, /* blacklist */
ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), /* cache */
true));
// Strip the trailing "." from the absolute path to the current directory.
final String basePath = new File(".").getAbsolutePath().replaceFirst("\\.$", "");
// Each classpath entry is specified via its absolute path so that the executable command can be
// run from a /tmp directory, if necessary.
String expectedClasspath = basePath + pathResolver.getRelativePath(javaBinary.getSourcePathToOutput());
List<String> expectedCommand = ImmutableList.of("/foobar/java", "-jar", expectedClasspath);
assertEquals(expectedCommand, javaBinary.getExecutableCommand().getCommandPrefix(pathResolver));
assertFalse("Library rules that are used exclusively by genrules should not be part of the classpath.", expectedClasspath.contains(PATH_TO_GENERATOR_JAR.toString()));
}
Aggregations