use of com.facebook.buck.model.Pair in project buck by facebook.
the class JsLibraryDescription method createDevFileRule.
private static <A extends Arg> BuildRule createDevFileRule(BuildRuleParams params, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, A args, Either<SourcePath, Pair<SourcePath, String>> source, WorkerTool worker) {
final SourcePath sourcePath = source.transform(x -> x, Pair::getFirst);
final Optional<String> subPath = Optional.ofNullable(source.transform(x -> null, Pair::getSecond));
final Optional<Path> virtualPath = args.basePath.map(basePath -> changePathPrefix(sourcePath, basePath, params, sourcePathResolver, params.getBuildTarget().getUnflavoredBuildTarget()).resolve(subPath.orElse("")));
return new JsFile.JsFileDev(ruleFinder.getRule(sourcePath).map(params::copyAppendingExtraDeps).orElse(params), sourcePath, subPath, virtualPath, args.extraArgs, worker);
}
use of com.facebook.buck.model.Pair in project buck by facebook.
the class JsLibraryDescription method mapSourcesToFlavors.
private static ImmutableBiMap<Either<SourcePath, Pair<SourcePath, String>>, Flavor> mapSourcesToFlavors(SourcePathResolver sourcePathResolver, ImmutableSet<Either<SourcePath, Pair<SourcePath, String>>> sources) {
final ImmutableBiMap.Builder<Either<SourcePath, Pair<SourcePath, String>>, Flavor> builder = ImmutableBiMap.builder();
for (Either<SourcePath, Pair<SourcePath, String>> source : sources) {
final Path relativePath = source.isLeft() ? sourcePathResolver.getRelativePath(source.getLeft()) : Paths.get(source.getRight().getSecond());
builder.put(source, JsFlavors.fileFlavorForSourcePath(relativePath));
}
return builder.build();
}
use of com.facebook.buck.model.Pair in project buck by facebook.
the class TypeCoercerTest method traverseWithPair.
@Test
public void traverseWithPair() throws NoSuchFieldException {
Type type = TestFields.class.getField("pairOfPathsAndStrings").getGenericType();
@SuppressWarnings("unchecked") TypeCoercer<Pair<Path, String>> coercer = (TypeCoercer<Pair<Path, String>>) typeCoercerFactory.typeCoercerForType(type);
TestTraversal traversal = new TestTraversal();
Pair<Path, String> input = new Pair<>(Paths.get("foo"), "bar");
coercer.traverse(input, traversal);
assertThat(traversal.getObjects(), Matchers.contains(ImmutableList.of(sameInstance((Object) input.getFirst()), sameInstance((Object) input.getSecond()))));
}
use of com.facebook.buck.model.Pair in project buck by facebook.
the class AndroidResourceDescription method collectInputSourcePaths.
private static Pair<Optional<SymlinkTree>, Optional<SourcePath>> collectInputSourcePaths(BuildRuleResolver ruleResolver, BuildTarget resourceRuleTarget, Flavor symlinkTreeFlavor, Optional<Either<SourcePath, ImmutableSortedMap<String, SourcePath>>> attribute) {
if (!attribute.isPresent()) {
return new Pair<>(Optional.empty(), Optional.empty());
}
if (attribute.get().isLeft()) {
SourcePath inputSourcePath = attribute.get().getLeft();
if (!(inputSourcePath instanceof PathSourcePath)) {
// in advance to create a symlink tree. Instead, we have to pass the source path as is.
return new Pair<>(Optional.empty(), Optional.of(inputSourcePath));
}
}
BuildTarget symlinkTreeTarget = resourceRuleTarget.withAppendedFlavors(symlinkTreeFlavor);
SymlinkTree symlinkTree;
try {
symlinkTree = (SymlinkTree) ruleResolver.requireRule(symlinkTreeTarget);
} catch (NoSuchBuildTargetException e) {
throw new RuntimeException(e);
}
return new Pair<>(Optional.of(symlinkTree), Optional.of(symlinkTree.getSourcePathToOutput()));
}
use of com.facebook.buck.model.Pair in project buck by facebook.
the class AndroidResourceDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, final BuildRuleResolver resolver, A args) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (params.getBuildTarget().getFlavors().contains(RESOURCES_SYMLINK_TREE_FLAVOR)) {
return createSymlinkTree(ruleFinder, params, args.res, "res");
} else if (params.getBuildTarget().getFlavors().contains(ASSETS_SYMLINK_TREE_FLAVOR)) {
return createSymlinkTree(ruleFinder, params, args.assets, "assets");
}
// Only allow android resource and library rules as dependencies.
Optional<BuildRule> invalidDep = params.getDeclaredDeps().get().stream().filter(rule -> !(rule instanceof AndroidResource || rule instanceof AndroidLibrary)).findFirst();
if (invalidDep.isPresent()) {
throw new HumanReadableException(params.getBuildTarget() + " (android_resource): dependency " + invalidDep.get().getBuildTarget() + " (" + invalidDep.get().getType() + ") is not of type android_resource or android_library.");
}
// We don't handle the resources parameter well in `AndroidResource` rules, as instead of
// hashing the contents of the entire resources directory, we try to filter out anything that
// doesn't look like a resource. This means when our resources are supplied from another rule,
// we have to resort to some hackery to make sure things work correctly.
Pair<Optional<SymlinkTree>, Optional<SourcePath>> resInputs = collectInputSourcePaths(resolver, params.getBuildTarget(), RESOURCES_SYMLINK_TREE_FLAVOR, args.res);
Pair<Optional<SymlinkTree>, Optional<SourcePath>> assetsInputs = collectInputSourcePaths(resolver, params.getBuildTarget(), ASSETS_SYMLINK_TREE_FLAVOR, args.assets);
params = params.copyAppendingExtraDeps(Iterables.concat(resInputs.getSecond().map(ruleFinder::filterBuildRuleInputs).orElse(ImmutableSet.of()), assetsInputs.getSecond().map(ruleFinder::filterBuildRuleInputs).orElse(ImmutableSet.of())));
return new AndroidResource(// step.
params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(AndroidResourceHelper.androidResOnly(params.getDeclaredDeps().get())), params.getExtraDeps()), ruleFinder, resolver.getAllRules(args.deps), resInputs.getSecond().orElse(null), resInputs.getFirst().map(SymlinkTree::getLinks).orElse(ImmutableSortedMap.of()), args.rDotJavaPackage.orElse(null), assetsInputs.getSecond().orElse(null), assetsInputs.getFirst().map(SymlinkTree::getLinks).orElse(ImmutableSortedMap.of()), args.manifest.orElse(null), args.hasWhitelistedStrings.orElse(false), args.resourceUnion.orElse(false), isGrayscaleImageProcessingEnabled);
}
Aggregations