use of com.facebook.buck.model.BuildTarget 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.model.BuildTarget in project buck by facebook.
the class AppleTestDescription method getXctool.
private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver) {
// can use that directly.
if (appleConfig.getXctoolZipTarget().isPresent()) {
final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget()).addFlavors(UNZIP_XCTOOL_FLAVOR).build();
final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget, "%s/unzipped");
if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
BuildRuleParams unzipXctoolParams = params.withBuildTarget(unzipXctoolTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)), Suppliers.ofInstance(ImmutableSortedSet.of()));
resolver.addToIndex(new AbstractBuildRule(unzipXctoolParams) {
@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
buildableContext.recordArtifact(outputDirectory);
return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory), new UnzipStep(getProjectFilesystem(), context.getSourcePathResolver().getAbsolutePath(Preconditions.checkNotNull(xctoolZipBuildRule.getSourcePathToOutput())), outputDirectory));
}
@Override
public SourcePath getSourcePathToOutput() {
return new ExplicitBuildTargetSourcePath(getBuildTarget(), outputDirectory);
}
});
}
return Optional.of(new ExplicitBuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
} else if (appleConfig.getXctoolPath().isPresent()) {
return Optional.of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
} else {
return Optional.empty();
}
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AppleTestDescription method createTestHostInfo.
private TestHostInfo createTestHostInfo(BuildRuleParams params, BuildRuleResolver resolver, BuildTarget testHostAppBuildTarget, AppleDebugFormat debugFormat, Iterable<Flavor> additionalFlavors, ImmutableList<CxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
BuildRule rule = resolver.requireRule(BuildTarget.builder(testHostAppBuildTarget).addAllFlavors(additionalFlavors).addFlavors(debugFormat.getFlavor()).addFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor()).build());
if (!(rule instanceof AppleBundle)) {
throw new HumanReadableException("Apple test rule '%s' has test_host_app '%s' not of type '%s'.", params.getBuildTarget(), testHostAppBuildTarget, Description.getBuildRuleType(AppleBundleDescription.class));
}
AppleBundle testHostApp = (AppleBundle) rule;
SourcePath testHostAppBinarySourcePath = testHostApp.getBinaryBuildRule().getSourcePathToOutput();
ImmutableMap<BuildTarget, NativeLinkable> roots = NativeLinkables.getNativeLinkableRoots(testHostApp.getBinary().get().getDeps(), x -> true);
// Union the blacklist of all the platforms. This should give a superset for each particular
// platform, which should be acceptable as items in the blacklist thare are unmatched are simply
// ignored.
ImmutableSet.Builder<BuildTarget> blacklistBuilder = ImmutableSet.builder();
for (CxxPlatform platform : cxxPlatforms) {
blacklistBuilder.addAll(NativeLinkables.getTransitiveNativeLinkables(platform, roots.values()).keySet());
}
return TestHostInfo.of(testHostApp, testHostAppBinarySourcePath, blacklistBuilder.build());
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class AppleTestDescription method createTestLibraryRule.
private <A extends Arg> BuildRule createTestLibraryRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args, Optional<SourcePath> testHostAppBinarySourcePath, ImmutableSet<BuildTarget> blacklist, BuildTarget libraryTarget) throws NoSuchBuildTargetException {
BuildTarget existingLibraryTarget = libraryTarget.withAppendedFlavors(AppleDebuggableBinary.RULE_FLAVOR, CxxStrip.RULE_FLAVOR).withAppendedFlavors(StripStyle.NON_GLOBAL_SYMBOLS.getFlavor());
Optional<BuildRule> existingLibrary = resolver.getRuleOptional(existingLibraryTarget);
BuildRule library;
if (existingLibrary.isPresent()) {
library = existingLibrary.get();
} else {
library = appleLibraryDescription.createLibraryBuildRule(targetGraph, params.withBuildTarget(libraryTarget), resolver, args, // we'll just link them statically.
Optional.of(Linker.LinkableDepType.STATIC), testHostAppBinarySourcePath, blacklist);
resolver.addToIndex(library);
}
return library;
}
use of com.facebook.buck.model.BuildTarget 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());
}
Aggregations