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;
}
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();
}
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;
}
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()));
}
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();
}
Aggregations