use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxPlatformsTest method invalidArchiverOverrideFails.
@Test
public void invalidArchiverOverrideFails() {
ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("ar", Paths.get("fake_path").toString(), "archiver_platform", "WRONG_PLATFORM"));
CxxBuckConfig buckConfig = new CxxBuckConfig(FakeBuckConfig.builder().setSections(sections).setFilesystem(new FakeProjectFilesystem(ImmutableSet.of(Paths.get("fake_path")))).build());
expectedException.expect(RuntimeException.class);
((LazyDelegatingArchiver) CxxPlatformUtils.build(buckConfig).getAr()).getDelegate();
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxHeadersDirTest method dirContentsAffectsRuleKey.
@Test
public void dirContentsAffectsRuleKey() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Path headerDir = filesystem.getPath("foo");
filesystem.mkdirs(headerDir);
CxxHeadersDir cxxHeaders = CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, headerDir));
filesystem.writeContentsToPath("something", headerDir.resolve("bar.h"));
RuleKey ruleKey1 = getRuleKey(filesystem, cxxHeaders);
filesystem.writeContentsToPath("something else", headerDir.resolve("bar.h"));
RuleKey ruleKey2 = getRuleKey(filesystem, cxxHeaders);
assertThat(ruleKey1, Matchers.not(Matchers.equalTo(ruleKey2)));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxHeadersDirTest method typeAffectsRuleKey.
@Test
public void typeAffectsRuleKey() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Path headerDir = filesystem.getPath("foo");
filesystem.mkdirs(headerDir);
RuleKey ruleKey1 = getRuleKey(filesystem, CxxHeadersDir.of(CxxPreprocessables.IncludeType.LOCAL, new PathSourcePath(filesystem, headerDir)));
RuleKey ruleKey2 = getRuleKey(filesystem, CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, new PathSourcePath(filesystem, headerDir)));
assertThat(ruleKey1, Matchers.not(Matchers.equalTo(ruleKey2)));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem 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.testutil.FakeProjectFilesystem in project buck by facebook.
the class CxxLibraryDescriptionTest method locationMacroExpandedExportedLinkerFlag.
@Test
public void locationMacroExpandedExportedLinkerFlag() throws Exception {
BuildTarget location = BuildTargetFactory.newInstance("//:loc");
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
ExportFileBuilder locBuilder = ExportFileBuilder.newExportFileBuilder(location);
locBuilder.setOut("somewhere.over.the.rainbow");
CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, cxxBuckConfig);
libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
libBuilder.setExportedLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location))));
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build(), locBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ExportFile loc = locBuilder.build(resolver, filesystem, targetGraph);
CxxLibrary lib = (CxxLibrary) libBuilder.build(resolver, filesystem, targetGraph);
NativeLinkableInput nativeLinkableInput = lib.getNativeLinkableInput(CxxLibraryBuilder.createDefaultPlatform(), Linker.LinkableDepType.SHARED);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
assertThat(FluentIterable.from(nativeLinkableInput.getArgs()).transformAndConcat(arg -> arg.getDeps(ruleFinder)).toSet(), hasItem(loc));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver), hasItem(containsString(pathResolver.getRelativePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())).toString())));
}
Aggregations