use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath 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.ExplicitBuildTargetSourcePath 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.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class HalideLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = params.getBuildTarget();
ImmutableSet<Flavor> flavors = ImmutableSet.copyOf(target.getFlavors());
CxxPlatform cxxPlatform = cxxPlatforms.getValue(flavors).orElse(defaultCxxPlatform);
if (flavors.contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR)) {
ImmutableMap.Builder<Path, SourcePath> headersBuilder = ImmutableMap.builder();
BuildTarget compileTarget = resolver.requireRule(target.withFlavors(HALIDE_COMPILE_FLAVOR, cxxPlatform.getFlavor())).getBuildTarget();
Path outputPath = HalideCompile.headerOutputPath(compileTarget, params.getProjectFilesystem(), args.functionName);
headersBuilder.put(outputPath.getFileName(), new ExplicitBuildTargetSourcePath(compileTarget, outputPath));
return CxxDescriptionEnhancer.createHeaderSymlinkTree(params, resolver, cxxPlatform, headersBuilder.build(), HeaderVisibility.PUBLIC, true);
} else if (flavors.contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR)) {
CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
return CxxDescriptionEnhancer.createSandboxTreeBuildRule(resolver, args, hostCxxPlatform, params);
} else if (flavors.contains(HALIDE_COMPILER_FLAVOR)) {
// We always want to build the halide "compiler" for the host platform, so
// we use the host flavor here, regardless of the flavors on the build
// target.
CxxPlatform hostCxxPlatform = cxxPlatforms.getValue(CxxPlatforms.getHostFlavor());
final ImmutableSortedSet<BuildTarget> compilerDeps = args.compilerDeps;
return createHalideCompiler(params.withAppendedFlavor(HALIDE_COMPILER_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(resolver.getAllRules(compilerDeps)), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, pathResolver, ruleFinder, hostCxxPlatform, args.srcs, args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, args.linkerFlags, args.platformLinkerFlags, args.includeDirs);
} else if (flavors.contains(CxxDescriptionEnhancer.STATIC_FLAVOR) || flavors.contains(CxxDescriptionEnhancer.STATIC_PIC_FLAVOR)) {
// See: https://github.com/halide/Halide/blob/e3c301f3/src/LLVM_Output.cpp#L152
return createHalideStaticLibrary(params, resolver, ruleFinder, cxxPlatform, args);
} else if (flavors.contains(CxxDescriptionEnhancer.SHARED_FLAVOR)) {
throw new HumanReadableException("halide_library '%s' does not support shared libraries as output", params.getBuildTarget());
} else if (flavors.contains(HALIDE_COMPILE_FLAVOR)) {
return createHalideCompile(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), resolver, cxxPlatform, Optional.of(args.compilerInvocationFlags), args.functionName);
}
return new HalideLibrary(params, resolver, args.supportedPlatformsRegex);
}
use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class HalideLibraryDescription method createHalideStaticLibrary.
private BuildRule createHalideStaticLibrary(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathRuleFinder ruleFinder, CxxPlatform platform, Arg args) throws NoSuchBuildTargetException {
if (!isPlatformSupported(args, platform)) {
return new NoopBuildRule(params);
}
BuildRule halideCompile = ruleResolver.requireRule(params.getBuildTarget().withFlavors(HALIDE_COMPILE_FLAVOR, platform.getFlavor()));
BuildTarget buildTarget = halideCompile.getBuildTarget();
return Archive.from(params.getBuildTarget(), params, ruleFinder, platform, cxxBuckConfig.getArchiveContents(), CxxDescriptionEnhancer.getStaticLibraryPath(params.getProjectFilesystem(), params.getBuildTarget(), platform.getFlavor(), CxxSourceRuleFactory.PicType.PIC, platform.getStaticLibraryExtension()), ImmutableList.of(new ExplicitBuildTargetSourcePath(buildTarget, HalideCompile.objectOutputPath(buildTarget, params.getProjectFilesystem(), args.functionName))));
}
use of com.facebook.buck.rules.ExplicitBuildTargetSourcePath in project buck by facebook.
the class PrebuiltCxxLibraryDescription method getApplicableSourcePath.
private static SourcePath getApplicableSourcePath(final BuildTarget target, final CellPathResolver cellRoots, final ProjectFilesystem filesystem, final BuildRuleResolver ruleResolver, final CxxPlatform cxxPlatform, Optional<String> versionSubDir, final String basePathString, final Optional<String> addedPathString) {
ImmutableList<BuildRule> deps;
MacroHandler handler = getMacroHandler(Optional.of(cxxPlatform));
try {
deps = handler.extractBuildTimeDeps(target, cellRoots, ruleResolver, basePathString);
} catch (MacroException e) {
deps = ImmutableList.of();
}
Path libDirPath = filesystem.getPath(expandMacros(handler, target, cellRoots, ruleResolver, basePathString));
if (versionSubDir.isPresent()) {
libDirPath = filesystem.getPath(versionSubDir.get()).resolve(libDirPath);
}
// So just expand the macros and return a PathSourcePath
if (deps.isEmpty()) {
Path resultPath = libDirPath;
if (addedPathString.isPresent()) {
resultPath = libDirPath.resolve(expandMacros(handler, target, cellRoots, ruleResolver, addedPathString.get()));
}
resultPath = target.getBasePath().resolve(resultPath);
return new PathSourcePath(filesystem, resultPath);
}
// If we get here then this is referencing the output from a build rule.
// This always return a ExplicitBuildTargetSourcePath
Path p = filesystem.resolve(libDirPath);
if (addedPathString.isPresent()) {
p = p.resolve(addedPathString.get());
}
p = filesystem.relativize(p);
return new ExplicitBuildTargetSourcePath(deps.iterator().next().getBuildTarget(), p);
}
Aggregations