Search in sources :

Example 91 with PathSourcePath

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

the class CxxLibraryDescriptionTest method createCxxLibraryBuildRules.

@Test
public void createCxxLibraryBuildRules() throws Exception {
    Assume.assumeFalse("This test assumes no sandboxing", cxxBuckConfig.sandboxSources());
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    CxxPlatform cxxPlatform = CxxLibraryBuilder.createDefaultPlatform();
    // Setup a normal C++ source
    String sourceName = "test/bar.cpp";
    // Setup a genrule the generates a header we'll list.
    String genHeaderName = "test/foo.h";
    BuildTarget genHeaderTarget = BuildTargetFactory.newInstance("//:genHeader");
    GenruleBuilder genHeaderBuilder = GenruleBuilder.newGenruleBuilder(genHeaderTarget).setOut(genHeaderName);
    // Setup a genrule the generates a source we'll list.
    String genSourceName = "test/foo.cpp";
    BuildTarget genSourceTarget = BuildTargetFactory.newInstance("//:genSource");
    GenruleBuilder genSourceBuilder = GenruleBuilder.newGenruleBuilder(genSourceTarget).setOut(genSourceName);
    // Setup a C/C++ library that we'll depend on form the C/C++ binary description.
    BuildTarget depTarget = BuildTargetFactory.newInstance("//:dep");
    CxxLibraryBuilder depBuilder = new CxxLibraryBuilder(depTarget, cxxBuckConfig).setExportedHeaders(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("blah.h")))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.cpp"))));
    BuildTarget sharedLibraryDepTarget = BuildTarget.builder(depTarget).addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).addFlavors(cxxPlatform.getFlavor()).build();
    BuildTarget headerSymlinkTreeTarget = BuildTarget.builder(depTarget).addFlavors(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR).addFlavors(CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY.getFlavor()).build();
    // Setup the build params we'll pass to description when generating the build rules.
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    CxxSourceRuleFactory cxxSourceRuleFactoryPDC = CxxSourceRuleFactoryHelper.of(filesystem.getRootPath(), target, cxxPlatform, cxxBuckConfig, CxxSourceRuleFactory.PicType.PDC);
    CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(target, cxxBuckConfig).setExportedHeaders(ImmutableSortedMap.of(genHeaderName, new DefaultBuildTargetSourcePath(genHeaderTarget))).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath(sourceName)), SourceWithFlags.of(new DefaultBuildTargetSourcePath(genSourceTarget)))).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourcePath(new FakeSourcePath("/some/framework/path/s.dylib")), FrameworkPath.ofSourcePath(new FakeSourcePath("/another/framework/path/a.dylib")))).setDeps(ImmutableSortedSet.of(depTarget));
    // Build target graph.
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genHeaderBuilder.build(), genSourceBuilder.build(), depBuilder.build(), cxxLibraryBuilder.build());
    // Construct C/C++ library build rules.
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    genHeaderBuilder.build(resolver, filesystem, targetGraph);
    genSourceBuilder.build(resolver, filesystem, targetGraph);
    depBuilder.build(resolver, filesystem, targetGraph);
    CxxLibrary rule = (CxxLibrary) cxxLibraryBuilder.build(resolver, filesystem, targetGraph);
    // Verify the C/C++ preprocessor input is setup correctly.
    CxxPreprocessorInput publicInput = rule.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC);
    assertThat(publicInput.getFrameworks(), containsInAnyOrder(FrameworkPath.ofSourcePath(new PathSourcePath(filesystem, Paths.get("/some/framework/path/s.dylib"))), FrameworkPath.ofSourcePath(new PathSourcePath(filesystem, Paths.get("/another/framework/path/a.dylib")))));
    CxxSymlinkTreeHeaders publicHeaders = (CxxSymlinkTreeHeaders) publicInput.getIncludes().get(0);
    assertThat(publicHeaders.getIncludeType(), equalTo(CxxPreprocessables.IncludeType.LOCAL));
    assertThat(publicHeaders.getNameToPathMap(), equalTo(ImmutableMap.<Path, SourcePath>of(Paths.get(genHeaderName), new DefaultBuildTargetSourcePath(genHeaderTarget))));
    assertThat(publicHeaders.getHeaderMap(), equalTo(getHeaderMaps(filesystem, target, resolver, cxxPlatform, HeaderVisibility.PUBLIC)));
    // Verify that the archive rule has the correct deps: the object files from our sources.
    rule.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.STATIC);
    BuildRule staticRule = resolver.getRule(CxxDescriptionEnhancer.createStaticLibraryBuildTarget(target, cxxPlatform.getFlavor(), CxxSourceRuleFactory.PicType.PDC));
    assertNotNull(staticRule);
    assertEquals(ImmutableSet.of(cxxSourceRuleFactoryPDC.createCompileBuildTarget("test/bar.cpp"), cxxSourceRuleFactoryPDC.createCompileBuildTarget(genSourceName)), staticRule.getDeps().stream().map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
    // Verify that the compile rule for our user-provided source has correct deps setup
    // for the various header rules.
    BuildRule staticCompileRule1 = resolver.getRule(cxxSourceRuleFactoryPDC.createCompileBuildTarget("test/bar.cpp"));
    assertNotNull(staticCompileRule1);
    assertThat(DependencyAggregationTestUtil.getDisaggregatedDeps(staticCompileRule1).map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()), containsInAnyOrder(genHeaderTarget, headerSymlinkTreeTarget, CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor()), CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PUBLIC, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY.getFlavor())));
    // Verify that the compile rule for our user-provided source has correct deps setup
    // for the various header rules.
    BuildRule staticCompileRule2 = resolver.getRule(cxxSourceRuleFactoryPDC.createCompileBuildTarget(genSourceName));
    assertNotNull(staticCompileRule2);
    assertThat(DependencyAggregationTestUtil.getDisaggregatedDeps(staticCompileRule2).map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()), containsInAnyOrder(genHeaderTarget, genSourceTarget, headerSymlinkTreeTarget, CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor()), CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PUBLIC, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY.getFlavor())));
    // Verify that the archive rule has the correct deps: the object files from our sources.
    CxxSourceRuleFactory cxxSourceRuleFactoryPIC = CxxSourceRuleFactoryHelper.of(filesystem.getRootPath(), target, cxxPlatform, cxxBuckConfig, CxxSourceRuleFactory.PicType.PIC);
    rule.getNativeLinkableInput(cxxPlatform, Linker.LinkableDepType.SHARED);
    BuildRule sharedRule = resolver.getRule(CxxDescriptionEnhancer.createSharedLibraryBuildTarget(target, cxxPlatform.getFlavor(), Linker.LinkType.SHARED));
    assertNotNull(sharedRule);
    assertEquals(ImmutableSet.of(sharedLibraryDepTarget, cxxSourceRuleFactoryPIC.createCompileBuildTarget("test/bar.cpp"), cxxSourceRuleFactoryPIC.createCompileBuildTarget(genSourceName)), sharedRule.getDeps().stream().map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
    // Verify that the compile rule for our user-provided source has correct deps setup
    // for the various header rules.
    BuildRule sharedCompileRule1 = resolver.getRule(cxxSourceRuleFactoryPIC.createCompileBuildTarget("test/bar.cpp"));
    assertNotNull(sharedCompileRule1);
    assertThat(DependencyAggregationTestUtil.getDisaggregatedDeps(sharedCompileRule1).map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()), containsInAnyOrder(genHeaderTarget, headerSymlinkTreeTarget, CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor()), CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PUBLIC, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY.getFlavor())));
    // Verify that the compile rule for our user-provided source has correct deps setup
    // for the various header rules.
    BuildRule sharedCompileRule2 = resolver.getRule(cxxSourceRuleFactoryPIC.createCompileBuildTarget(genSourceName));
    assertNotNull(sharedCompileRule2);
    assertThat(DependencyAggregationTestUtil.getDisaggregatedDeps(sharedCompileRule2).map(BuildRule::getBuildTarget).collect(MoreCollectors.toImmutableSet()), containsInAnyOrder(genHeaderTarget, genSourceTarget, headerSymlinkTreeTarget, CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor()), CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PUBLIC, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY.getFlavor())));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Matchers.containsString(org.hamcrest.Matchers.containsString) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 92 with PathSourcePath

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

the class CxxLibraryDescriptionTest method thinArchiveSettingIsPropagatedToArchive.

@Test
public void thinArchiveSettingIsPropagatedToArchive() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildTarget target = BuildTargetFactory.newInstance("//:rule").withFlavors(CxxDescriptionEnhancer.STATIC_FLAVOR, CxxLibraryBuilder.createDefaultPlatform().getFlavor());
    CxxLibraryBuilder libBuilder = new CxxLibraryBuilder(target, new CxxBuckConfig(FakeBuckConfig.builder().setSections("[cxx]", "archive_contents=thin", "sandbox_sources=" + cxxBuckConfig.sandboxSources()).build()), CxxPlatformUtils.DEFAULT_PLATFORMS);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(libBuilder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    libBuilder.setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new PathSourcePath(filesystem, Paths.get("test.cpp")))));
    Archive lib = (Archive) libBuilder.build(resolver, filesystem, targetGraph);
    assertThat(lib.getContents(), equalTo(Archive.Contents.THIN));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 93 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath 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)

Example 94 with PathSourcePath

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

the class HeaderPathNormalizerTest method managedPrefixHeaderDir.

@Test
public void managedPrefixHeaderDir() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Path header = filesystem.getPath("foo/bar.pch");
    SourcePath headerPath = new PathSourcePath(filesystem, header);
    HeaderPathNormalizer normalizer = new HeaderPathNormalizer.Builder(pathResolver).addPrefixHeader(headerPath).build();
    assertThat(normalizer.getAbsolutePathForUnnormalizedPath(pathResolver.getAbsolutePath(headerPath)), Matchers.equalTo(Optional.of(pathResolver.getAbsolutePath(headerPath))));
    assertThat(normalizer.getSourcePathForAbsolutePath(pathResolver.getAbsolutePath(headerPath)), Matchers.equalTo(headerPath));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) 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 95 with PathSourcePath

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

the class HeaderPathNormalizerTest method managedHeaderWithRelativePath.

@Test
public void managedHeaderWithRelativePath() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Path header = filesystem.getPath("foo/bar.h");
    SourcePath headerPath = new PathSourcePath(filesystem, header);
    HeaderPathNormalizer normalizer = new HeaderPathNormalizer.Builder(pathResolver).addHeader(headerPath).build();
    assertThat(normalizer.getAbsolutePathForUnnormalizedPath(filesystem.resolve(header)), Matchers.equalTo(Optional.of(pathResolver.getAbsolutePath(headerPath))));
    assertThat(normalizer.getAbsolutePathForUnnormalizedPath(pathResolver.getAbsolutePath(headerPath)), Matchers.equalTo(Optional.of(pathResolver.getAbsolutePath(headerPath))));
    assertThat(normalizer.getSourcePathForAbsolutePath(pathResolver.getAbsolutePath(headerPath)), Matchers.equalTo(headerPath));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) 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)

Aggregations

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14