Search in sources :

Example 11 with AllExistingProjectFilesystem

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")));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 12 with AllExistingProjectFilesystem

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));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 13 with AllExistingProjectFilesystem

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);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) LinkOption(java.nio.file.LinkOption) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 14 with AllExistingProjectFilesystem

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));
    }
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 15 with AllExistingProjectFilesystem

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")));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) NativeLinkStrategy(com.facebook.buck.cxx.NativeLinkStrategy) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)26 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)26 Test (org.junit.Test)26 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)24 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)22 TargetGraph (com.facebook.buck.rules.TargetGraph)18 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)9 PathSourcePath (com.facebook.buck.rules.PathSourcePath)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)8 BuildTarget (com.facebook.buck.model.BuildTarget)5 SourcePath (com.facebook.buck.rules.SourcePath)4 Path (java.nio.file.Path)3 PBXShellScriptBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase)2 ReactNativeBuckConfig (com.facebook.buck.js.ReactNativeBuckConfig)2 CellPathResolver (com.facebook.buck.rules.CellPathResolver)2 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)2 RuleKey (com.facebook.buck.rules.RuleKey)2 LinkOption (java.nio.file.LinkOption)2