Search in sources :

Example 46 with TargetNode

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

the class VersionedTargetGraphBuilder method getVersionInfo.

/**
   * Get/cache the transitive version info for this node.
   */
private VersionInfo getVersionInfo(TargetNode<?, ?> node) {
    VersionInfo info = this.versionInfo.get(node.getBuildTarget());
    if (info != null) {
        return info;
    }
    Map<BuildTarget, ImmutableSet<Version>> versionDomain = new HashMap<>();
    Optional<TargetNode<VersionedAliasDescription.Arg, ?>> versionedNode = TargetGraphVersionTransformations.getVersionedNode(node);
    if (versionedNode.isPresent()) {
        ImmutableMap<Version, BuildTarget> versions = versionedNode.get().getConstructorArg().versions;
        // Merge in the versioned deps and the version domain.
        versionDomain.put(node.getBuildTarget(), versions.keySet());
        // it's transitive deps in an implication constraint.
        if (versions.size() == 1) {
            Map.Entry<Version, BuildTarget> ent = versions.entrySet().iterator().next();
            VersionInfo depInfo = getVersionInfo(getNode(ent.getValue()));
            versionDomain.putAll(depInfo.getVersionDomain());
        } else {
            // implication dependent on the specific version that pulls them in.
            for (Map.Entry<Version, BuildTarget> ent : versions.entrySet()) {
                VersionInfo depInfo = getVersionInfo(getNode(ent.getValue()));
                versionDomain.putAll(depInfo.getVersionDomain());
            }
        }
    } else {
        // Merge in the constraints and version domain/deps from transitive deps.
        for (BuildTarget depTarget : TargetGraphVersionTransformations.getDeps(node)) {
            TargetNode<?, ?> dep = getNode(depTarget);
            if (TargetGraphVersionTransformations.isVersionPropagator(dep) || TargetGraphVersionTransformations.getVersionedNode(dep).isPresent()) {
                VersionInfo depInfo = getVersionInfo(dep);
                versionDomain.putAll(depInfo.getVersionDomain());
            }
        }
    }
    info = VersionInfo.of(versionDomain);
    this.versionInfo.put(node.getBuildTarget(), info);
    return info;
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 47 with TargetNode

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

the class AbstractFlavorSearchTargetNodeFinder method getBaseTargetFlavorMap.

// Build the flavor map, which maps all unflavored targets to the flavors they have in the
// graph.  We sort the list of flavor sets from largest to smallest, so that look ups pick the
// more flavored sets first.
@Value.Derived
ImmutableMap<UnflavoredBuildTarget, ImmutableSet<ImmutableSet<Flavor>>> getBaseTargetFlavorMap() {
    Map<UnflavoredBuildTarget, List<ImmutableSet<Flavor>>> flavorMapRawBuilder = new LinkedHashMap<>();
    for (Map.Entry<BuildTarget, TargetNode<?, ?>> ent : getBaseTargetIndex().entrySet()) {
        BuildTarget baseTarget = ent.getKey();
        UnflavoredBuildTarget unflavoredTarget = baseTarget.getUnflavoredBuildTarget();
        if (!flavorMapRawBuilder.containsKey(unflavoredTarget)) {
            flavorMapRawBuilder.put(unflavoredTarget, new ArrayList<>());
        }
        flavorMapRawBuilder.get(unflavoredTarget).add(baseTarget.getFlavors());
    }
    ImmutableMap.Builder<UnflavoredBuildTarget, ImmutableSet<ImmutableSet<Flavor>>> flavorMapBuilder = ImmutableMap.builder();
    for (Map.Entry<UnflavoredBuildTarget, List<ImmutableSet<Flavor>>> ent : flavorMapRawBuilder.entrySet()) {
        ent.getValue().sort((o1, o2) -> Integer.compare(o2.size(), o1.size()));
        flavorMapBuilder.put(ent.getKey(), ImmutableSet.copyOf(ent.getValue()));
    }
    return flavorMapBuilder.build();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) Flavor(com.facebook.buck.model.Flavor) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableSet(com.google.common.collect.ImmutableSet) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 48 with TargetNode

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

the class ProjectGeneratorTest method getBuildRuleResolverWithRulesForNodeFunction.

private Function<TargetNode<?, ?>, BuildRuleResolver> getBuildRuleResolverWithRulesForNodeFunction(final TargetGraph targetGraph) throws NoSuchBuildTargetException {
    final BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    for (TargetNode<?, ?> node : targetGraph.getNodes()) {
        ruleResolver.requireRule(node.getBuildTarget());
        ruleResolver.requireRule(node.getBuildTarget().withFlavors());
    }
    return input -> ruleResolver;
}
Also used : ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget(com.facebook.buck.apple.project_generator.ProjectGeneratorTestUtils.assertTargetExistsAndReturnTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) AppleBundleExtension(com.facebook.buck.apple.AppleBundleExtension) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) AppleLibraryBuilder(com.facebook.buck.apple.AppleLibraryBuilder) InternalFlavor(com.facebook.buck.model.InternalFlavor) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FlavorDomain(com.facebook.buck.model.FlavorDomain) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSDictionary(com.dd.plist.NSDictionary) FileAttribute(java.nio.file.attribute.FileAttribute) BuildTarget(com.facebook.buck.model.BuildTarget) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Assert.assertFalse(org.junit.Assert.assertFalse) StringWithMacrosUtils(com.facebook.buck.rules.macros.StringWithMacrosUtils) ByteStreams(com.google.common.io.ByteStreams) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuckEventBus(com.facebook.buck.event.BuckEventBus) PBXSourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase) Iterables(com.google.common.collect.Iterables) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) PBXHeadersBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) PosixFilePermissions(java.nio.file.attribute.PosixFilePermissions) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) HalideLibraryDescription(com.facebook.buck.halide.HalideLibraryDescription) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) AppleBinaryBuilder(com.facebook.buck.apple.AppleBinaryBuilder) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) StringWithMacros(com.facebook.buck.rules.macros.StringWithMacros) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) AppleAssetCatalogBuilder(com.facebook.buck.apple.AppleAssetCatalogBuilder) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Assert.assertTrue(org.junit.Assert.assertTrue) ProductType(com.facebook.buck.apple.xcode.xcodeproj.ProductType) AppleResourceBuilder(com.facebook.buck.apple.AppleResourceBuilder) Test(org.junit.Test) IOException(java.io.IOException) PBXResourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase) SceneKitAssetsBuilder(com.facebook.buck.apple.SceneKitAssetsBuilder) CxxSource(com.facebook.buck.cxx.CxxSource) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) HalideLibraryBuilder(com.facebook.buck.halide.HalideLibraryBuilder) Paths(java.nio.file.Paths) AppleLibraryDescription(com.facebook.buck.apple.AppleLibraryDescription) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) Assert.assertEquals(org.junit.Assert.assertEquals) IosReactNativeLibraryBuilder(com.facebook.buck.js.IosReactNativeLibraryBuilder) CoreMatchers.is(org.hamcrest.CoreMatchers.is) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) XcodePostbuildScriptBuilder(com.facebook.buck.apple.XcodePostbuildScriptBuilder) Matchers.hasKey(org.hamcrest.Matchers.hasKey) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) Assert.assertThat(org.junit.Assert.assertThat) AppleConfig(com.facebook.buck.apple.AppleConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Cell(com.facebook.buck.rules.Cell) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) AppleBundleBuilder(com.facebook.buck.apple.AppleBundleBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Collection(java.util.Collection) Platform(com.facebook.buck.util.environment.Platform) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) XcodePrebuildScriptBuilder(com.facebook.buck.apple.XcodePrebuildScriptBuilder) List(java.util.List) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeAppleRuleDescriptions(com.facebook.buck.apple.FakeAppleRuleDescriptions) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) PathSourcePath(com.facebook.buck.rules.PathSourcePath) ExportFileDescription(com.facebook.buck.shell.ExportFileDescription) Optional(java.util.Optional) Assume.assumeTrue(org.junit.Assume.assumeTrue) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) CoreMatchers.not(org.hamcrest.CoreMatchers.not) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) AbstractBottomUpTraversal(com.facebook.buck.graph.AbstractBottomUpTraversal) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ImmutableList(com.google.common.collect.ImmutableList) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) NSString(com.dd.plist.NSString) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) ExpectedException(org.junit.rules.ExpectedException) MoreCollectors(com.facebook.buck.util.MoreCollectors) Assert.assertNotNull(org.junit.Assert.assertNotNull) TargetNode(com.facebook.buck.rules.TargetNode) ExportFileBuilder(com.facebook.buck.shell.ExportFileBuilder) Matchers(org.hamcrest.Matchers) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TimeUnit(java.util.concurrent.TimeUnit) PBXCopyFilesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXCopyFilesBuildPhase) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) AppleTestBuilder(com.facebook.buck.apple.AppleTestBuilder) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) CoreDataModelBuilder(com.facebook.buck.apple.CoreDataModelBuilder) CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) Flavor(com.facebook.buck.model.Flavor) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) InputStream(java.io.InputStream) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 49 with TargetNode

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

the class ProjectGeneratorTest method testAggregateTargetForBinaryForBuildWithBuck.

@Test
public void testAggregateTargetForBinaryForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(binaryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + binaryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.dSYM") + " " + binaryTarget.getShortName()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 50 with TargetNode

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

the class ProjectGeneratorTest method usingBuildTargetSourcePathInResourceDirsOrFilesDoesNotThrow.

@Test
public void usingBuildTargetSourcePathInResourceDirsOrFilesDoesNotThrow() throws IOException {
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:rule");
    SourcePath sourcePath = new DefaultBuildTargetSourcePath(buildTarget);
    TargetNode<?, ?> generatingTarget = ExportFileBuilder.newExportFileBuilder(buildTarget).build();
    ImmutableSet<TargetNode<?, ?>> nodes = FluentIterable.from(setupSimpleLibraryWithResources(ImmutableSet.of(sourcePath), ImmutableSet.of(sourcePath))).append(generatingTarget).toSet();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(nodes);
    projectGenerator.createXcodeProjects();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Aggregations

TargetNode (com.facebook.buck.rules.TargetNode)88 BuildTarget (com.facebook.buck.model.BuildTarget)73 TargetGraph (com.facebook.buck.rules.TargetGraph)43 Test (org.junit.Test)40 Path (java.nio.file.Path)36 ImmutableSet (com.google.common.collect.ImmutableSet)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 Map (java.util.Map)18 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 ImmutableList (com.google.common.collect.ImmutableList)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)13 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)13 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 Cell (com.facebook.buck.rules.Cell)13 IOException (java.io.IOException)13 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)12