use of com.facebook.buck.rules.macros.StringWithMacros in project buck by facebook.
the class CxxLibraryDescriptionTest method locationMacroExpandedPlatformLinkerFlagPlatformMatch.
@Test
public void locationMacroExpandedPlatformLinkerFlagPlatformMatch() throws Exception {
BuildTarget location = BuildTargetFactory.newInstance("//:loc");
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar").withFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR, CxxLibraryBuilder.createDefaultPlatform().getFlavor());
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.setPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile(CxxLibraryBuilder.createDefaultPlatform().getFlavor().toString()), ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location)))).build());
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build(), locBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
ExportFile loc = locBuilder.build(resolver, filesystem, targetGraph);
CxxLink lib = (CxxLink) libBuilder.build(resolver, filesystem, targetGraph);
assertThat(lib.getDeps(), hasItem(loc));
assertThat(Arg.stringify(lib.getArgs(), pathResolver), hasItem(String.format("-Wl,--version-script=%s", pathResolver.getAbsolutePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())))));
assertThat(Arg.stringify(lib.getArgs(), pathResolver), not(hasItem(pathResolver.getAbsolutePath(loc.getSourcePathToOutput()).toString())));
}
use of com.facebook.buck.rules.macros.StringWithMacros in project buck by facebook.
the class CxxLibraryDescriptionTest method locationMacroExpandedPlatformLinkerFlagNoPlatformMatch.
@Test
public void locationMacroExpandedPlatformLinkerFlagNoPlatformMatch() throws Exception {
BuildTarget location = BuildTargetFactory.newInstance("//:loc");
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar").withFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR, CxxLibraryBuilder.createDefaultPlatform().getFlavor());
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.setPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile("notarealplatform"), ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location)))).build());
TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build(), locBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ExportFile loc = locBuilder.build(resolver, filesystem, targetGraph);
CxxLink lib = (CxxLink) libBuilder.build(resolver, filesystem, targetGraph);
assertThat(lib.getDeps(), not(hasItem(loc)));
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
assertThat(Arg.stringify(lib.getArgs(), pathResolver), not(hasItem(containsString(pathResolver.getRelativePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())).toString()))));
}
use of com.facebook.buck.rules.macros.StringWithMacros in project buck by facebook.
the class CxxLibraryDescriptionTest method locationMacroExpandedExportedPlatformLinkerFlagNoPlatformMatch.
@Test
public void locationMacroExpandedExportedPlatformLinkerFlagNoPlatformMatch() throws Exception {
BuildTarget location = BuildTargetFactory.newInstance("//:loc");
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar").withFlavors(CxxLibraryBuilder.createDefaultPlatform().getFlavor());
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.setExportedPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile("notarealplatform"), ImmutableList.of(StringWithMacrosUtils.format("-Wl,--version-script=%s", LocationMacro.of(location)))).build());
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(), not(hasItem(loc)));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
assertThat(Arg.stringify(nativeLinkableInput.getArgs(), pathResolver), not(hasItem(containsString(pathResolver.getRelativePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())).toString()))));
}
Aggregations