use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AppleResources method collectResourceDirsAndFiles.
public static <T> AppleBundleResources collectResourceDirsAndFiles(final TargetGraph targetGraph, final Optional<AppleDependenciesCache> cache, TargetNode<T, ?> targetNode) {
AppleBundleResources.Builder builder = AppleBundleResources.builder();
Iterable<TargetNode<?, ?>> resourceNodes = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.COPYING, targetNode, Optional.of(APPLE_RESOURCE_DESCRIPTION_CLASSES));
ProjectFilesystem filesystem = targetNode.getFilesystem();
for (TargetNode<?, ?> resourceNode : resourceNodes) {
Object constructorArg = resourceNode.getConstructorArg();
if (constructorArg instanceof AppleResourceDescription.Arg) {
AppleResourceDescription.Arg appleResource = (AppleResourceDescription.Arg) constructorArg;
builder.addAllResourceDirs(appleResource.dirs);
builder.addAllResourceFiles(appleResource.files);
builder.addAllResourceVariantFiles(appleResource.variants);
} else {
Preconditions.checkState(constructorArg instanceof ReactNativeLibraryArgs);
BuildTarget buildTarget = resourceNode.getBuildTarget();
builder.addDirsContainingResourceDirs(new ExplicitBuildTargetSourcePath(buildTarget, ReactNativeBundle.getPathToJSBundleDir(buildTarget, filesystem)), new ExplicitBuildTargetSourcePath(buildTarget, ReactNativeBundle.getPathToResources(buildTarget, filesystem)));
}
}
return builder.build();
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGenerator method resolveSourcePath.
private Path resolveSourcePath(SourcePath sourcePath) {
if (sourcePath instanceof PathSourcePath) {
return ((PathSourcePath) sourcePath).getRelativePath();
}
Preconditions.checkArgument(sourcePath instanceof BuildTargetSourcePath);
BuildTargetSourcePath<?> buildTargetSourcePath = (BuildTargetSourcePath<?>) sourcePath;
BuildTarget buildTarget = buildTargetSourcePath.getTarget();
TargetNode<?, ?> node = targetGraph.get(buildTarget);
Optional<TargetNode<ExportFileDescription.Arg, ?>> exportFileNode = node.castArg(ExportFileDescription.Arg.class);
if (!exportFileNode.isPresent()) {
BuildRuleResolver resolver = buildRuleResolverForNode.apply(node);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Path output = pathResolver.getRelativePath(sourcePath);
if (output == null) {
throw new HumanReadableException("The target '%s' does not have an output.", node.getBuildTarget());
}
requiredBuildTargetsBuilder.add(buildTarget);
return output;
}
Optional<SourcePath> src = exportFileNode.get().getConstructorArg().src;
if (!src.isPresent()) {
return buildTarget.getBasePath().resolve(buildTarget.getShortNameAndFlavorPostfix());
}
return resolveSourcePath(src.get());
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class WorkspaceAndProjectGenerator method addExtraWorkspaceSchemes.
private static void addExtraWorkspaceSchemes(TargetGraph projectGraph, AppleDependenciesCache dependenciesCache, ImmutableSortedMap<String, BuildTarget> extraSchemes, ImmutableMap.Builder<String, XcodeWorkspaceConfigDescription.Arg> schemeConfigsBuilder, ImmutableSetMultimap.Builder<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNodeBuilder, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg, ?>> extraTestNodesBuilder) {
for (Map.Entry<String, BuildTarget> extraSchemeEntry : extraSchemes.entrySet()) {
BuildTarget extraSchemeTarget = extraSchemeEntry.getValue();
Optional<TargetNode<?, ?>> extraSchemeNode = projectGraph.getOptional(extraSchemeTarget);
if (!extraSchemeNode.isPresent() || !(extraSchemeNode.get().getDescription() instanceof XcodeWorkspaceConfigDescription)) {
throw new HumanReadableException("Extra scheme target '%s' should be of type 'xcode_workspace_config'", extraSchemeTarget);
}
XcodeWorkspaceConfigDescription.Arg extraSchemeArg = (XcodeWorkspaceConfigDescription.Arg) extraSchemeNode.get().getConstructorArg();
String schemeName = extraSchemeEntry.getKey();
addWorkspaceScheme(projectGraph, dependenciesCache, schemeName, extraSchemeArg, schemeConfigsBuilder, schemeNameToSrcTargetNodeBuilder, extraTestNodesBuilder);
}
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGenerator method generateAppleTestTarget.
@SuppressWarnings("unchecked")
private PBXTarget generateAppleTestTarget(TargetNode<AppleTestDescription.Arg, ?> testTargetNode) throws IOException {
Optional<TargetNode<AppleBundleDescription.Arg, ?>> testHostBundle;
if (testTargetNode.getConstructorArg().testHostApp.isPresent()) {
BuildTarget testHostBundleTarget = testTargetNode.getConstructorArg().testHostApp.get();
TargetNode<?, ?> testHostBundleNode = targetGraph.get(testHostBundleTarget);
if (!(testHostBundleNode.getDescription() instanceof AppleBundleDescription)) {
throw new HumanReadableException("The test host target '%s' has the wrong type (%s), must be apple_bundle", testHostBundleTarget, testHostBundleNode.getDescription().getClass());
}
testHostBundle = Optional.of((TargetNode<AppleBundleDescription.Arg, ?>) testHostBundleNode);
} else {
testHostBundle = Optional.empty();
}
return generateAppleBundleTarget(project, testTargetNode, testTargetNode, testHostBundle);
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGenerator method generateAppleBundleTarget.
private PBXNativeTarget generateAppleBundleTarget(PBXProject project, TargetNode<? extends HasAppleBundleFields, ?> targetNode, TargetNode<? extends AppleNativeTargetDescriptionArg, ?> binaryNode, Optional<TargetNode<AppleBundleDescription.Arg, ?>> bundleLoaderNode) throws IOException {
Path infoPlistPath = Preconditions.checkNotNull(resolveSourcePath(targetNode.getConstructorArg().getInfoPlist()));
// -- copy any binary and bundle targets into this bundle
Iterable<TargetNode<?, ?>> copiedRules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, Optional.of(dependenciesCache), AppleBuildRules.RecursiveDependenciesMode.COPYING, targetNode, Optional.of(AppleBuildRules.XCODE_TARGET_DESCRIPTION_CLASSES));
if (bundleRequiresRemovalOfAllTransitiveFrameworks(targetNode)) {
copiedRules = rulesWithoutFrameworkBundles(copiedRules);
} else if (bundleRequiresAllTransitiveFrameworks(binaryNode)) {
copiedRules = ImmutableSet.<TargetNode<?, ?>>builder().addAll(copiedRules).addAll(getTransitiveFrameworkNodes(targetNode)).build();
}
if (bundleLoaderNode.isPresent()) {
copiedRules = rulesWithoutBundleLoader(copiedRules, bundleLoaderNode.get());
}
ImmutableList<PBXBuildPhase> copyFilesBuildPhases = getCopyFilesBuildPhases(copiedRules);
PBXNativeTarget target = generateBinaryTarget(project, Optional.of(targetNode), binaryNode, bundleToTargetProductType(targetNode, binaryNode), "%s." + getExtensionString(targetNode.getConstructorArg().getExtension()), Optional.of(infoPlistPath), /* includeFrameworks */
true, AppleResources.collectRecursiveResources(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), AppleResources.collectDirectResources(targetGraph, targetNode), AppleBuildRules.collectRecursiveAssetCatalogs(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), AppleBuildRules.collectDirectAssetCatalogs(targetGraph, targetNode), AppleBuildRules.collectRecursiveWrapperResources(targetGraph, Optional.of(dependenciesCache), ImmutableList.of(targetNode)), Optional.of(copyFilesBuildPhases), bundleLoaderNode);
LOG.debug("Generated iOS bundle target %s", target);
return target;
}
Aggregations