use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class DistBuildState method dump.
public static BuildJobState dump(DistBuildCellIndexer distributedBuildCellIndexer, DistBuildFileHashes fileHashes, DistBuildTargetGraphCodec targetGraphCodec, TargetGraph targetGraph, ImmutableSet<BuildTarget> topLevelTargets) throws IOException, InterruptedException {
Preconditions.checkArgument(topLevelTargets.size() > 0);
BuildJobState jobState = new BuildJobState();
jobState.setFileHashes(fileHashes.getFileHashes());
jobState.setTargetGraph(targetGraphCodec.dump(targetGraph.getNodes(), distributedBuildCellIndexer));
jobState.setCells(distributedBuildCellIndexer.getState());
for (BuildTarget target : topLevelTargets) {
jobState.addToTopLevelTargets(target.getFullyQualifiedName());
}
return jobState;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class HaskellPrebuiltLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
return new PrebuiltHaskellLibrary(params) {
private final LoadingCache<CxxPreprocessables.CxxPreprocessorInputCacheKey, ImmutableMap<BuildTarget, CxxPreprocessorInput>> transitiveCxxPreprocessorInputCache = CxxPreprocessables.getTransitiveCxxPreprocessorInputCache(this);
@Override
public HaskellCompileInput getCompileInput(CxxPlatform cxxPlatform, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
return HaskellCompileInput.builder().addAllFlags(args.exportedCompilerFlags).addPackages(HaskellPackage.builder().setInfo(HaskellPackageInfo.of(getBuildTarget().getShortName(), args.version, args.id.orElse(String.format("%s-%s", getBuildTarget().getShortName(), args.version)))).setPackageDb(args.db).addAllInterfaces(args.importDirs).addAllLibraries(depType == Linker.LinkableDepType.SHARED ? args.sharedLibs.values() : args.staticLibs).build()).build();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableDeps() {
return ImmutableList.of();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableExportedDeps() {
return FluentIterable.from(getDeclaredDeps()).filter(NativeLinkable.class);
}
@Override
public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) {
NativeLinkableInput.Builder builder = NativeLinkableInput.builder();
builder.addAllArgs(StringArg.from(args.exportedLinkerFlags));
if (type == Linker.LinkableDepType.SHARED) {
builder.addAllArgs(SourcePathArg.from(args.sharedLibs.values()));
} else {
builder.addAllArgs(SourcePathArg.from(args.staticLibs));
}
return builder.build();
}
@Override
public Linkage getPreferredLinkage(CxxPlatform cxxPlatform) {
return Linkage.ANY;
}
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) {
return args.sharedLibs;
}
@Override
public Iterable<? extends CxxPreprocessorDep> getCxxPreprocessorDeps(CxxPlatform cxxPlatform) {
return FluentIterable.from(getDeps()).filter(CxxPreprocessorDep.class);
}
@Override
public Optional<HeaderSymlinkTree> getExportedHeaderSymlinkTree(CxxPlatform cxxPlatform) {
return Optional.empty();
}
@Override
public CxxPreprocessorInput getCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
CxxPreprocessorInput.Builder builder = CxxPreprocessorInput.builder();
for (SourcePath headerDir : args.cxxHeaderDirs) {
builder.addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, headerDir));
}
return builder.build();
}
@Override
public ImmutableMap<BuildTarget, CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
return transitiveCxxPreprocessorInputCache.getUnchecked(ImmutableCxxPreprocessorInputCacheKey.of(cxxPlatform, headerVisibility));
}
};
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class JavaDepsFinder method findDependencyInfoForGraph.
public DependencyInfo findDependencyInfoForGraph(final TargetGraph graph) {
final DependencyInfo dependencyInfo = new DependencyInfo();
// were thread-safe.
for (TargetNode<?, ?> node : graph.getNodes()) {
if (!RULES_TO_VISIT.contains(Description.getBuildRuleType(node.getDescription()))) {
continue;
}
// Set up the appropriate fields for java_library() vs. prebuilt_jar().
boolean autodeps;
ImmutableSortedSet<BuildTarget> providedDeps;
ImmutableSortedSet<BuildTarget> exportedDeps;
if (node.getConstructorArg() instanceof JavaLibraryDescription.Arg) {
JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) node.getConstructorArg();
autodeps = arg.autodeps.orElse(false);
providedDeps = arg.providedDeps;
exportedDeps = arg.exportedDeps;
} else if (node.getConstructorArg() instanceof PrebuiltJarDescription.Arg) {
autodeps = false;
providedDeps = ImmutableSortedSet.of();
exportedDeps = ImmutableSortedSet.of();
} else {
throw new IllegalStateException("This rule is not supported by autodeps: " + node);
}
if (autodeps) {
dependencyInfo.rulesWithAutodeps.add(node);
dependencyInfo.rulesWithAutodepsToProvidedDeps.putAll(node, providedDeps);
}
for (BuildTarget exportedDep : exportedDeps) {
dependencyInfo.ruleToRulesThatExportIt.put(graph.get(exportedDep), node);
}
Symbols symbols = getJavaFileFeatures(node, autodeps);
if (autodeps) {
dependencyInfo.ruleToRequiredSymbols.putAll(node, symbols.required);
dependencyInfo.ruleToExportedSymbols.putAll(node, symbols.exported);
}
for (String providedEntity : symbols.provided) {
dependencyInfo.symbolToProviders.put(providedEntity, node);
}
}
return dependencyInfo;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class JavaDepsFinder method getJavaFileFeatures.
private Symbols getJavaFileFeatures(TargetNode<?, ?> node, boolean shouldRecordRequiredSymbols) {
// Build a JavaLibrarySymbolsFinder to create the JavaFileFeatures. By making use of Buck's
// build cache, we can often avoid running a Java parser.
BuildTarget buildTarget = node.getBuildTarget();
Object argForNode = node.getConstructorArg();
JavaSymbolsRule.SymbolsFinder symbolsFinder;
ImmutableSortedSet<String> generatedSymbols;
if (argForNode instanceof JavaLibraryDescription.Arg) {
JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) argForNode;
// The build target should be recorded as a provider for every symbol in its
// generated_symbols set (if it exists). It is common to use this for symbols that are
// generated via annotation processors.
generatedSymbols = arg.generatedSymbols;
symbolsFinder = new JavaLibrarySymbolsFinder(arg.srcs, javaFileParser, shouldRecordRequiredSymbols);
} else {
PrebuiltJarDescription.Arg arg = (PrebuiltJarDescription.Arg) argForNode;
generatedSymbols = ImmutableSortedSet.of();
symbolsFinder = new PrebuiltJarSymbolsFinder(arg.binaryJar);
}
// Build the rule, leveraging Buck's build cache.
JavaSymbolsRule buildRule = new JavaSymbolsRule(buildTarget, symbolsFinder, generatedSymbols, objectMapper, node.getFilesystem());
ListenableFuture<BuildResult> future = buildEngine.build(buildContext, executionContext, buildRule);
BuildResult result = Futures.getUnchecked(future);
Symbols features;
if (result.getSuccess() != null) {
features = buildRule.getFeatures();
} else {
Throwable failure = result.getFailure();
Preconditions.checkNotNull(failure);
throw new RuntimeException("Failed to extract Java symbols for " + buildTarget, failure);
}
return features;
}
use of com.facebook.buck.model.BuildTarget in project buck by facebook.
the class JavaDepsFinder method findDepsForBuildFiles.
private DepsForBuildFiles findDepsForBuildFiles(final TargetGraph graph, final DependencyInfo dependencyInfo, final Console console) {
// For the rules that expect to have their deps generated, look through all of their required
// symbols and try to find the build rule that provides each symbols. Store these build rules in
// the depsForBuildFiles data structure.
//
// Currently, we process each rule with autodeps=True on a single thread. See the class overview
// for DepsForBuildFiles about what it would take to do this work in a multi-threaded way.
DepsForBuildFiles depsForBuildFiles = new DepsForBuildFiles();
for (final TargetNode<?, ?> rule : dependencyInfo.rulesWithAutodeps) {
final Set<BuildTarget> providedDeps = dependencyInfo.rulesWithAutodepsToProvidedDeps.get(rule);
final Predicate<TargetNode<?, ?>> isVisibleDepNotAlreadyInProvidedDeps = provider -> provider.isVisibleTo(graph, rule) && !providedDeps.contains(provider.getBuildTarget());
final boolean isJavaTestRule = rule.getDescription() instanceof JavaTestDescription;
for (DependencyType type : DependencyType.values()) {
HashMultimap<TargetNode<?, ?>, String> ruleToSymbolsMap;
switch(type) {
case DEPS:
ruleToSymbolsMap = dependencyInfo.ruleToRequiredSymbols;
break;
case EXPORTED_DEPS:
ruleToSymbolsMap = dependencyInfo.ruleToExportedSymbols;
break;
default:
throw new IllegalStateException("Unrecognized type: " + type);
}
final DependencyType typeOfDepToAdd;
if (isJavaTestRule) {
// java_test rules do not honor exported_deps: add all dependencies to the ordinary deps.
typeOfDepToAdd = DependencyType.DEPS;
} else {
typeOfDepToAdd = type;
}
for (String requiredSymbol : ruleToSymbolsMap.get(rule)) {
BuildTarget provider = findProviderForSymbolFromBuckConfig(requiredSymbol);
if (provider != null) {
depsForBuildFiles.addDep(rule.getBuildTarget(), provider, typeOfDepToAdd);
continue;
}
Set<TargetNode<?, ?>> providers = dependencyInfo.symbolToProviders.get(requiredSymbol);
SortedSet<TargetNode<?, ?>> candidateProviders = providers.stream().filter(isVisibleDepNotAlreadyInProvidedDeps).collect(MoreCollectors.toImmutableSortedSet(Comparator.<TargetNode<?, ?>>naturalOrder()));
int numCandidates = candidateProviders.size();
if (numCandidates == 1) {
depsForBuildFiles.addDep(rule.getBuildTarget(), Iterables.getOnlyElement(candidateProviders).getBuildTarget(), typeOfDepToAdd);
} else if (numCandidates > 1) {
// Warn the user that there is an ambiguity. This could be very common with macros that
// generate multiple versions of a java_library() with the same sources.
// If numProviders is 0, then hopefully the dep is provided by something the user
// hardcoded in the BUCK file.
console.printErrorText(String.format("WARNING: Multiple providers for %s: %s. " + "Consider adding entry to .buckconfig to eliminate ambiguity:\n" + "[autodeps]\n" + "java-package-mappings = %s => %s", requiredSymbol, Joiner.on(", ").join(candidateProviders), requiredSymbol, Iterables.getFirst(candidateProviders, null)));
} else {
// If there aren't any candidates, then see if there is a visible rule that can provide
// the symbol via its exported_deps. We make this a secondary check because we prefer to
// depend on the rule that defines the symbol directly rather than one of possibly many
// rules that provides it via its exported_deps.
ImmutableSortedSet<TargetNode<?, ?>> newCandidates = providers.stream().flatMap(candidate -> dependencyInfo.ruleToRulesThatExportIt.get(candidate).stream()).filter(ruleThatExportsCandidate -> ruleThatExportsCandidate.isVisibleTo(graph, rule)).collect(MoreCollectors.toImmutableSortedSet(Comparator.<TargetNode<?, ?>>naturalOrder()));
int numNewCandidates = newCandidates.size();
if (numNewCandidates == 1) {
depsForBuildFiles.addDep(rule.getBuildTarget(), Iterables.getOnlyElement(newCandidates).getBuildTarget(), typeOfDepToAdd);
} else if (numNewCandidates > 1) {
console.printErrorText(String.format("WARNING: No providers found for '%s' for build rule %s, " + "but there are multiple rules that export a rule to provide %s: %s", requiredSymbol, rule.getBuildTarget(), requiredSymbol, Joiner.on(", ").join(newCandidates)));
}
// In the case that numNewCandidates is 0, we assume that the user is taking
// responsibility for declaring a provider for the symbol by hardcoding it in the deps.
}
}
}
}
return depsForBuildFiles;
}
Aggregations