use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class ResolveAliasHelper method validateBuildTargetForFullyQualifiedTarget.
/**
* Verify that the given target is a valid full-qualified (non-alias) target.
*/
@Nullable
static String validateBuildTargetForFullyQualifiedTarget(CommandRunnerParams params, ListeningExecutorService executor, boolean enableProfiling, String target, Parser parser) {
BuildTarget buildTarget = getBuildTargetForFullyQualifiedTarget(params.getBuckConfig(), target);
Cell owningCell = params.getCell().getCell(buildTarget);
Path buildFile;
try {
buildFile = owningCell.getAbsolutePathToBuildFile(buildTarget);
} catch (Cell.MissingBuildFileException e) {
throw new HumanReadableException(e);
}
// Get all valid targets in our target directory by reading the build file.
ImmutableSet<TargetNode<?, ?>> targetNodes;
try {
targetNodes = parser.getAllTargetNodes(params.getBuckEventBus(), owningCell, enableProfiling, executor, buildFile);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Check that the given target is a valid target.
for (TargetNode<?, ?> candidate : targetNodes) {
if (candidate.getBuildTarget().equals(buildTarget)) {
return buildTarget.getFullyQualifiedName();
}
}
return null;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class TestRunning method getRulesUnderTest.
/**
* Generates the set of Java library rules under test.
*/
private static ImmutableSet<JavaLibrary> getRulesUnderTest(Iterable<TestRule> tests) {
ImmutableSet.Builder<JavaLibrary> rulesUnderTest = ImmutableSet.builder();
// Gathering all rules whose source will be under test.
for (TestRule test : tests) {
if (test instanceof JavaTest) {
// Look at the transitive dependencies for `tests` attribute that refers to this test.
JavaTest javaTest = (JavaTest) test;
ImmutableSet<JavaLibrary> transitiveDeps = javaTest.getCompiledTestsLibrary().getTransitiveClasspathDeps();
for (JavaLibrary dep : transitiveDeps) {
if (dep instanceof JavaLibraryWithTests) {
ImmutableSortedSet<BuildTarget> depTests = ((JavaLibraryWithTests) dep).getTests();
if (depTests.contains(test.getBuildTarget())) {
rulesUnderTest.add(dep);
}
}
}
}
}
return rulesUnderTest.build();
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class CxxDescriptionEnhancer method parseOnlyPlatformHeaders.
static ImmutableMap<String, SourcePath> parseOnlyPlatformHeaders(BuildTarget buildTarget, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, SourcePathResolver sourcePathResolver, CxxPlatform cxxPlatform, String headersParameterName, SourceList headers, String platformHeadersParameterName, PatternMatchedCollection<SourceList> platformHeaders) throws NoSuchBuildTargetException {
ImmutableMap.Builder<String, SourcePath> parsed = ImmutableMap.builder();
java.util.function.Function<SourcePath, SourcePath> fixup = path -> {
try {
return CxxGenruleDescription.fixupSourcePath(resolver, ruleFinder, cxxPlatform, path);
} catch (NoSuchBuildTargetException e) {
throw new RuntimeException(e);
}
};
// Include all normal exported headers that are generated by `cxx_genrule`.
parsed.putAll(headers.toNameMap(buildTarget, sourcePathResolver, headersParameterName, path -> CxxGenruleDescription.wrapsCxxGenrule(ruleFinder, path), fixup));
// Include all platform specific headers.
for (SourceList sourceList : platformHeaders.getMatchingValues(cxxPlatform.getFlavor().toString())) {
parsed.putAll(sourceList.toNameMap(buildTarget, sourcePathResolver, platformHeadersParameterName, path -> true, fixup));
}
return parsed.build();
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class CxxDescriptionEnhancer method requireSharedLibrarySymlinkTree.
public static SymlinkTree requireSharedLibrarySymlinkTree(BuildTarget buildTarget, ProjectFilesystem filesystem, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Iterable<? extends BuildRule> deps, Predicate<Object> traverse) throws NoSuchBuildTargetException {
BuildTarget target = createSharedLibrarySymlinkTreeTarget(buildTarget, cxxPlatform.getFlavor());
SymlinkTree tree = resolver.getRuleOptionalWithType(target, SymlinkTree.class).orElse(null);
if (tree == null) {
tree = resolver.addToIndex(createSharedLibrarySymlinkTree(ruleFinder, buildTarget, filesystem, cxxPlatform, deps, traverse));
}
return tree;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class CxxDescriptionEnhancer method createCompilationDatabaseDependencies.
public static Optional<CxxCompilationDatabaseDependencies> createCompilationDatabaseDependencies(BuildTarget buildTarget, FlavorDomain<CxxPlatform> platforms, BuildRuleResolver resolver, CxxConstructorArg args) throws NoSuchBuildTargetException {
Preconditions.checkState(buildTarget.getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE));
Optional<Flavor> cxxPlatformFlavor = platforms.getFlavor(buildTarget);
Preconditions.checkState(cxxPlatformFlavor.isPresent(), "Could not find cxx platform in:\n%s", Joiner.on(", ").join(buildTarget.getFlavors()));
ImmutableSet.Builder<SourcePath> sourcePaths = ImmutableSet.builder();
for (BuildTarget dep : args.deps) {
Optional<CxxCompilationDatabaseDependencies> compilationDatabases = resolver.requireMetadata(BuildTarget.builder(dep).addFlavors(CxxCompilationDatabase.COMPILATION_DATABASE).addFlavors(cxxPlatformFlavor.get()).build(), CxxCompilationDatabaseDependencies.class);
if (compilationDatabases.isPresent()) {
sourcePaths.addAll(compilationDatabases.get().getSourcePaths());
}
}
// Not all parts of Buck use require yet, so require the rule here so it's available in the
// resolver for the parts that don't.
BuildRule buildRule = resolver.requireRule(buildTarget);
sourcePaths.add(buildRule.getSourcePathToOutput());
return Optional.of(CxxCompilationDatabaseDependencies.of(sourcePaths.build()));
}
Aggregations