Search in sources :

Example 1 with ExportFile

use of com.facebook.buck.shell.ExportFile in project buck by facebook.

the class CxxLibraryDescriptionTest method locationMacroExpandedExportedPlatformLinkerFlagPlatformMatch.

@Test
public void locationMacroExpandedExportedPlatformLinkerFlagPlatformMatch() 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.setExportedPlatformLinkerFlags(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());
    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())));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with ExportFile

use of com.facebook.buck.shell.ExportFile 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())));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 3 with ExportFile

use of com.facebook.buck.shell.ExportFile in project buck by facebook.

the class CxxLibraryDescriptionTest method locationMacroExpandedLinkerFlag.

@Test
public void locationMacroExpandedLinkerFlag() 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.setLinkerFlags(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);
    CxxLink lib = (CxxLink) libBuilder.build(resolver, filesystem, targetGraph);
    assertThat(lib.getDeps(), hasItem(loc));
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    assertThat(Arg.stringify(lib.getArgs(), pathResolver), hasItem(containsString(pathResolver.getRelativePath(Preconditions.checkNotNull(loc.getSourcePathToOutput())).toString())));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 4 with ExportFile

use of com.facebook.buck.shell.ExportFile 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())));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 5 with ExportFile

use of com.facebook.buck.shell.ExportFile 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()))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExportFile(com.facebook.buck.shell.ExportFile) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 BuildTarget (com.facebook.buck.model.BuildTarget)6 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)6 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 PathSourcePath (com.facebook.buck.rules.PathSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 TargetGraph (com.facebook.buck.rules.TargetGraph)6 ExportFile (com.facebook.buck.shell.ExportFile)6 ExportFileBuilder (com.facebook.buck.shell.ExportFileBuilder)6 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)6 Test (org.junit.Test)6 StringWithMacros (com.facebook.buck.rules.macros.StringWithMacros)4