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