use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class CxxGenruleDescription method translateConstructorArg.
@Override
public Optional<Arg> translateConstructorArg(BuildTarget target, CellPathResolver cellNames, TargetNodeTranslator translator, Arg constructorArg) {
Arg newConstructorArg = createUnpopulatedConstructorArg();
translator.translateConstructorArg(cellNames, BuildTargetPatternParser.forBaseName(target.getBaseName()), constructorArg, newConstructorArg);
newConstructorArg.cmd = newConstructorArg.cmd.map(c -> translateCmd(target, cellNames, translator, "cmd", c));
newConstructorArg.bash = newConstructorArg.bash.map(c -> translateCmd(target, cellNames, translator, "bash", c));
newConstructorArg.cmdExe = newConstructorArg.cmdExe.map(c -> translateCmd(target, cellNames, translator, "cmd_exe", c));
return Optional.of(newConstructorArg);
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class QueryMacroExpander method extractTargets.
private Stream<BuildTarget> extractTargets(BuildTarget target, CellPathResolver cellNames, Optional<BuildRuleResolver> resolver, T input) {
String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.getQuery().getQuery());
final GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(resolver, targetGraph, cellNames, BuildTargetPatternParser.forBaseName(target.getBaseName()), ImmutableSet.of());
try {
QueryExpression parsedExp = QueryExpression.parse(queryExpression, env);
HashSet<String> targetLiterals = new HashSet<>();
parsedExp.collectTargetPatterns(targetLiterals);
return targetLiterals.stream().flatMap(pattern -> {
try {
return env.getTargetsMatchingPattern(pattern, executorService).stream();
} catch (Exception e) {
throw new HumanReadableException(e, "Error parsing target expression %s for target %s", pattern, target);
}
}).map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
return ((QueryBuildTarget) queryTarget).getBuildTarget();
});
} catch (QueryException e) {
throw new HumanReadableException("Error executing query in macro for target %s", target, e);
}
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class TargetNodeTranslator method translateNode.
/**
* @return a copy of the given {@link TargetNode} with all found {@link BuildTarget}s translated,
* or {@link Optional#empty()} if the node requires no translation.
*/
public <A> Optional<TargetNode<A, ?>> translateNode(TargetNode<A, ?> node) {
CellPathResolver cellPathResolver = node.getCellNames();
BuildTargetPatternParser<BuildTargetPattern> pattern = BuildTargetPatternParser.forBaseName(node.getBuildTarget().getBaseName());
Optional<BuildTarget> target = translateBuildTarget(node.getBuildTarget());
Optional<A> constructorArg = translateConstructorArg(cellPathResolver, pattern, node);
Optional<ImmutableSet<BuildTarget>> declaredDeps = translateSet(cellPathResolver, pattern, node.getDeclaredDeps());
Optional<ImmutableSet<BuildTarget>> extraDeps = translateSet(cellPathResolver, pattern, node.getExtraDeps());
Optional<ImmutableMap<BuildTarget, Version>> newSelectedVersions = getSelectedVersions(node.getBuildTarget());
Optional<ImmutableMap<BuildTarget, Version>> oldSelectedVersions = node.getSelectedVersions();
Optional<Optional<ImmutableMap<BuildTarget, Version>>> selectedVersions = oldSelectedVersions.equals(newSelectedVersions) ? Optional.empty() : Optional.of(newSelectedVersions);
// If nothing has changed, don't generate a new node.
if (!target.isPresent() && !constructorArg.isPresent() && !declaredDeps.isPresent() && !extraDeps.isPresent() && !selectedVersions.isPresent()) {
return Optional.empty();
}
return Optional.of(node.withTargetConstructorArgDepsAndSelectedVerisons(target.orElse(node.getBuildTarget()), constructorArg.orElse(node.getConstructorArg()), declaredDeps.orElse(node.getDeclaredDeps()), extraDeps.orElse(node.getExtraDeps()), selectedVersions.orElse(oldSelectedVersions)));
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class PrebuiltCxxLibraryDescriptionTest method platformMacro.
@Test
public void platformMacro() {
Optional<String> libDir = Optional.of("libs/$(platform)");
Optional<String> libName = Optional.of("test-$(platform)");
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
CellPathResolver cellRoots = TestCellBuilder.createCellRoots(filesystem);
CxxPlatform platform1 = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
CxxPlatform platform2 = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM2"));
assertEquals(filesystem.resolve(TARGET.getBasePath().resolve(String.format("libs/PLATFORM1/libtest-PLATFORM1.%s", platform1.getSharedLibraryExtension()))), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getSharedLibraryPath(TARGET, cellRoots, filesystem, resolver, platform1, Optional.empty(), libDir, libName)));
assertEquals(filesystem.resolve(TARGET.getBasePath().resolve("libs/PLATFORM1/libtest-PLATFORM1.a")), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform1, Optional.empty(), libDir, libName)));
assertEquals(filesystem.resolve(TARGET.getBasePath().resolve(String.format("libs/PLATFORM2/libtest-PLATFORM2.%s", platform2.getSharedLibraryExtension()))), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getSharedLibraryPath(TARGET, cellRoots, filesystem, resolver, platform2, Optional.empty(), libDir, libName)));
assertEquals(filesystem.resolve(TARGET.getBasePath().resolve("libs/PLATFORM2/libtest-PLATFORM2.a")), pathResolver.getAbsolutePath(PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform2, Optional.empty(), libDir, libName)));
}
use of com.facebook.buck.rules.CellPathResolver in project buck by facebook.
the class BuildTargetParserTest method testParseWithRepoName.
@Test
public void testParseWithRepoName() {
final Path localRepoRoot = Paths.get("/opt/local/repo");
CellPathResolver cellRoots = new FakeCellPathResolver(ImmutableMap.of("localreponame", localRepoRoot));
String targetStr = "localreponame//foo/bar:baz";
BuildTarget buildTarget = parser.parse(targetStr, fullyQualifiedParser, cellRoots);
assertEquals("localreponame//foo/bar:baz", buildTarget.getFullyQualifiedName());
assertTrue(buildTarget.getCell().isPresent());
assertEquals(localRepoRoot, buildTarget.getCellPath());
}
Aggregations