use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method nativeLinkTargetMode.
@Test
public void nativeLinkTargetMode() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:rule")).setSoname("libsoname.so");
TargetGraph targetGraph = TargetGraphFactory.newInstance(prebuiltCxxLibraryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary rule = (PrebuiltCxxLibrary) prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
assertThat(rule.getNativeLinkTarget(CXX_PLATFORM).get().getNativeLinkTargetMode(CXX_PLATFORM), Matchers.equalTo(NativeLinkTargetMode.library("libsoname.so")));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method headerOnly.
@Test
public void headerOnly() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
PrebuiltCxxLibraryBuilder libBuilder = new PrebuiltCxxLibraryBuilder(TARGET).setHeaderOnly(true);
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PrebuiltCxxLibrary lib = (PrebuiltCxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
// Verify static native linkable input.
NativeLinkableInput expectedStaticLinkableInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedStaticLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.STATIC));
// Verify shared native linkable input.
NativeLinkableInput expectedSharedLinkableInput = NativeLinkableInput.of(ImmutableList.of(), ImmutableSet.of(), ImmutableSet.of());
assertEquals(expectedSharedLinkableInput, lib.getNativeLinkableInput(CXX_PLATFORM, Linker.LinkableDepType.SHARED));
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class DefaultJavaLibraryTest method testRuleKeyIsOrderInsensitiveForSourcesAndResources.
@Test
public void testRuleKeyIsOrderInsensitiveForSourcesAndResources() throws Exception {
// Note that these filenames were deliberately chosen to have identical hashes to maximize
// the chance of order-sensitivity when being inserted into a HashMap. Just using
// {foo,bar}.{java,txt} resulted in a passing test even for the old broken code.
ProjectFilesystem filesystem = new AllExistingProjectFilesystem() {
@Override
public boolean isDirectory(Path path, LinkOption... linkOptionsk) {
return false;
}
};
BuildRuleResolver resolver1 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder1 = new SourcePathRuleFinder(resolver1);
SourcePathResolver pathResolver1 = new SourcePathResolver(ruleFinder1);
DefaultJavaLibrary rule1 = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//lib:lib")).addSrc(Paths.get("agifhbkjdec.java")).addSrc(Paths.get("bdeafhkgcji.java")).addSrc(Paths.get("bdehgaifjkc.java")).addSrc(Paths.get("cfiabkjehgd.java")).addResource(new FakeSourcePath("becgkaifhjd.txt")).addResource(new FakeSourcePath("bkhajdifcge.txt")).addResource(new FakeSourcePath("cabfghjekid.txt")).addResource(new FakeSourcePath("chkdbafijge.txt")).build(resolver1, filesystem);
BuildRuleResolver resolver2 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder2 = new SourcePathRuleFinder(resolver2);
SourcePathResolver pathResolver2 = new SourcePathResolver(ruleFinder2);
DefaultJavaLibrary rule2 = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//lib:lib")).addSrc(Paths.get("cfiabkjehgd.java")).addSrc(Paths.get("bdehgaifjkc.java")).addSrc(Paths.get("bdeafhkgcji.java")).addSrc(Paths.get("agifhbkjdec.java")).addResource(new FakeSourcePath("chkdbafijge.txt")).addResource(new FakeSourcePath("cabfghjekid.txt")).addResource(new FakeSourcePath("bkhajdifcge.txt")).addResource(new FakeSourcePath("becgkaifhjd.txt")).build(resolver2, filesystem);
ImmutableMap.Builder<String, String> fileHashes = ImmutableMap.builder();
for (String filename : ImmutableList.of("agifhbkjdec.java", "bdeafhkgcji.java", "bdehgaifjkc.java", "cfiabkjehgd.java", "becgkaifhjd.txt", "bkhajdifcge.txt", "cabfghjekid.txt", "chkdbafijge.txt")) {
fileHashes.put(filename, Hashing.sha1().hashString(filename, Charsets.UTF_8).toString());
}
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(fileHashes.build()), pathResolver1, ruleFinder1);
DefaultRuleKeyFactory ruleKeyFactory2 = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(fileHashes.build()), pathResolver2, ruleFinder2);
RuleKey key1 = ruleKeyFactory.build(rule1);
RuleKey key2 = ruleKeyFactory2.build(rule2);
assertEquals(key1, key2);
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PythonTestDescriptionTest method nonBuildDepsDoNotAffectRuleKey.
@Test
public void nonBuildDepsDoNotAffectRuleKey() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) {
// First, calculate the rule key of a python binary with no deps.
PythonTestBuilder pythonTestBuilder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:bin")).setPackageStyle(packageStyle);
TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonTestBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PythonTest pythonTestWithoutDep = pythonTestBuilder.build(resolver, filesystem, targetGraph);
RuleKey ruleKeyWithoutDep = calculateRuleKey(resolver, pythonTestWithoutDep);
// Next, calculate the rule key of a python binary with a deps on another binary.
CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
pythonTestBuilder.setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
targetGraph = TargetGraphFactory.newInstance(cxxBinaryBuilder.build(), pythonTestBuilder.build());
resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
cxxBinaryBuilder.build(resolver, filesystem, targetGraph);
PythonTest pythonBinaryWithDep = pythonTestBuilder.build(resolver, filesystem, targetGraph);
RuleKey ruleKeyWithDep = calculateRuleKey(resolver, pythonBinaryWithDep);
// Verify that the rule keys are identical.
assertThat(ruleKeyWithoutDep, Matchers.equalTo(ruleKeyWithDep));
}
}
use of com.facebook.buck.testutil.AllExistingProjectFilesystem in project buck by facebook.
the class PythonBinaryDescriptionTest method explicitDepOnlinkWholeLibPullsInSharedLibrary.
@Test
public void explicitDepOnlinkWholeLibPullsInSharedLibrary() throws Exception {
for (final NativeLinkStrategy strategy : NativeLinkStrategy.values()) {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep1")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.c")))).setForceStatic(true);
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep2")).setForceStatic(true);
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {
@Override
public NativeLinkStrategy getNativeLinkStrategy() {
return strategy;
}
};
PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
binaryBuilder.setMainModule("main");
binaryBuilder.setDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget(), prebuiltCxxLibraryBuilder.getTarget()));
TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), prebuiltCxxLibraryBuilder.build(), binaryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
cxxLibraryBuilder.build(resolver, filesystem, targetGraph);
prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
PythonBinary binary = binaryBuilder.build(resolver, filesystem, targetGraph);
assertThat("Using " + strategy, binary.getComponents().getNativeLibraries().keySet(), Matchers.hasItems(Paths.get("libdep1.so"), Paths.get("libdep2.so")));
}
}
Aggregations