Search in sources :

Example 96 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class CxxPrepareForLinkStepTest method testCreateCxxPrepareForLinkStep.

@Test
public void testCreateCxxPrepareForLinkStep() throws Exception {
    Path dummyPath = Paths.get("dummy");
    BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver));
    // Setup some dummy values for inputs to the CxxLinkStep
    ImmutableList<Arg> dummyArgs = ImmutableList.of(FileListableLinkerInputArg.withSourcePathArg(SourcePathArg.of(new FakeSourcePath("libb.a"))));
    CxxPrepareForLinkStep cxxPrepareForLinkStepSupportFileList = CxxPrepareForLinkStep.create(dummyPath, dummyPath, ImmutableList.of(StringArg.of("-filelist"), StringArg.of(dummyPath.toString())), dummyPath, dummyArgs, CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(buildRuleResolver), dummyPath, pathResolver);
    ImmutableList<Step> containingSteps = ImmutableList.copyOf(cxxPrepareForLinkStepSupportFileList.iterator());
    assertThat(containingSteps.size(), Matchers.equalTo(2));
    Step firstStep = containingSteps.get(0);
    Step secondStep = containingSteps.get(1);
    assertThat(firstStep, Matchers.instanceOf(CxxWriteArgsToFileStep.class));
    assertThat(secondStep, Matchers.instanceOf(CxxWriteArgsToFileStep.class));
    assertThat(firstStep, Matchers.not(secondStep));
    CxxPrepareForLinkStep cxxPrepareForLinkStepNoSupportFileList = CxxPrepareForLinkStep.create(dummyPath, dummyPath, ImmutableList.of(), dummyPath, dummyArgs, CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(buildRuleResolver), dummyPath, pathResolver);
    containingSteps = ImmutableList.copyOf(cxxPrepareForLinkStepNoSupportFileList.iterator());
    assertThat(containingSteps.size(), Matchers.equalTo(1));
    assertThat(containingSteps.get(0), Matchers.instanceOf(CxxWriteArgsToFileStep.class));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) FileListableLinkerInputArg(com.facebook.buck.rules.args.FileListableLinkerInputArg) Arg(com.facebook.buck.rules.args.Arg) Step(com.facebook.buck.step.Step) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 97 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class CxxLibraryDescriptionTest method sharedLibraryShouldLinkOwnRequiredLibraries.

@Test
public void sharedLibraryShouldLinkOwnRequiredLibraries() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
    CxxLibraryBuilder libraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:foo").withFlavors(platform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR), cxxBuckConfig);
    libraryBuilder.setLibraries(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("/usr/lib/libz.dylib"), Optional.empty())), FrameworkPath.ofSourcePath(new FakeSourcePath("/another/path/liba.dylib")))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.c"))));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libraryBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    CxxLink library = (CxxLink) libraryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(Arg.stringify(library.getArgs(), pathResolver), hasItems("-L", "/another/path", "$SDKROOT/usr/lib", "-la", "-lz"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 98 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class NativeLinkablesTest method gatherTransitiveSharedLibraries.

@Test
public void gatherTransitiveSharedLibraries() throws Exception {
    FakeNativeLinkable c = new FakeNativeLinkable("//:c", ImmutableList.of(), ImmutableList.of(), NativeLinkable.Linkage.ANY, NativeLinkableInput.builder().build(), ImmutableMap.of("libc.so", new FakeSourcePath("libc.so")));
    FakeNativeLinkable b = new FakeNativeLinkable("//:b", ImmutableList.of(c), ImmutableList.of(), NativeLinkable.Linkage.STATIC, NativeLinkableInput.builder().build(), ImmutableMap.of("libb.so", new FakeSourcePath("libb.so")));
    FakeNativeLinkable a = new FakeNativeLinkable("//:a", ImmutableList.of(b), ImmutableList.of(), NativeLinkable.Linkage.ANY, NativeLinkableInput.builder().build(), ImmutableMap.of("liba.so", new FakeSourcePath("liba.so")));
    ImmutableSortedMap<String, SourcePath> sharedLibs = NativeLinkables.getTransitiveSharedLibraries(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(a), NativeLinkable.class::isInstance);
    assertThat(sharedLibs, Matchers.equalTo(ImmutableSortedMap.<String, SourcePath>of("liba.so", new FakeSourcePath("liba.so"), "libc.so", new FakeSourcePath("libc.so"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Test(org.junit.Test)

Example 99 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class NativeLinkablesTest method duplicateIdenticalLibsDoNotConflict.

@Test
public void duplicateIdenticalLibsDoNotConflict() throws Exception {
    FakeSourcePath path = new FakeSourcePath("libc.so");
    FakeNativeLinkable a = new FakeNativeLinkable("//:a", ImmutableList.of(), ImmutableList.of(), NativeLinkable.Linkage.ANY, NativeLinkableInput.builder().build(), ImmutableMap.of("libc.so", path));
    FakeNativeLinkable b = new FakeNativeLinkable("//:b", ImmutableList.of(), ImmutableList.of(), NativeLinkable.Linkage.ANY, NativeLinkableInput.builder().build(), ImmutableMap.of("libc.so", path));
    ImmutableSortedMap<String, SourcePath> sharedLibs = NativeLinkables.getTransitiveSharedLibraries(CxxPlatformUtils.DEFAULT_PLATFORM, ImmutableList.of(a, b), NativeLinkable.class::isInstance);
    assertThat(sharedLibs, Matchers.equalTo(ImmutableSortedMap.<String, SourcePath>of("libc.so", path)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Test(org.junit.Test)

Example 100 with FakeSourcePath

use of com.facebook.buck.rules.FakeSourcePath in project buck by facebook.

the class PrebuiltCxxLibraryGroupDescriptionTest method supportedPlatforms.

@Test
public void supportedPlatforms() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    CxxLibrary dep1 = (CxxLibrary) new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).build(resolver);
    CxxLibrary dep2 = (CxxLibrary) new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep2")).build(resolver);
    BuildTarget target = BuildTargetFactory.newInstance("//:lib");
    SourcePath lib1 = new FakeSourcePath("dir/lib1.so");
    SourcePath lib2 = new FakeSourcePath("dir/lib2.so");
    BuildRule buildRule = new PrebuiltCxxLibraryGroupBuilder(target).setSharedLink(ImmutableList.of("$(lib lib1.so)", "$(lib lib2.so)")).setSharedLibs(ImmutableMap.of("lib1.so", lib1)).setProvidedSharedLibs(ImmutableMap.of("lib2.so", lib2)).setExportedDeps(ImmutableSortedSet.of(dep1.getBuildTarget())).setDeps(ImmutableSortedSet.of(dep2.getBuildTarget())).setSupportedPlatformsRegex(Pattern.compile("nothing")).build(resolver);
    NativeLinkable lib = (NativeLinkable) buildRule;
    assertThat(lib.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED), Matchers.equalTo(NativeLinkableInput.of()));
    assertThat(lib.getNativeLinkableExportedDepsForPlatform(CxxPlatformUtils.DEFAULT_PLATFORM), Matchers.emptyIterable());
    assertThat(lib.getNativeLinkableDepsForPlatform(CxxPlatformUtils.DEFAULT_PLATFORM), Matchers.emptyIterable());
    assertThat(lib.getSharedLibraries(CxxPlatformUtils.DEFAULT_PLATFORM), Matchers.anEmptyMap());
    CxxPreprocessorDep cxxPreprocessorDep = (CxxPreprocessorDep) buildRule;
    assertThat(cxxPreprocessorDep.getCxxPreprocessorDeps(CxxPlatformUtils.DEFAULT_PLATFORM), Matchers.emptyIterable());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)318 Test (org.junit.Test)297 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)188 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)188 BuildTarget (com.facebook.buck.model.BuildTarget)182 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)116 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)104 SourcePath (com.facebook.buck.rules.SourcePath)90 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)85 TargetGraph (com.facebook.buck.rules.TargetGraph)84 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)68 Path (java.nio.file.Path)67 BuildRule (com.facebook.buck.rules.BuildRule)52 PathSourcePath (com.facebook.buck.rules.PathSourcePath)48 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)46 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)45 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)45 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)35 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)25 NSString (com.dd.plist.NSString)24