use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.
the class JavaLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
BuildTarget target = params.getBuildTarget();
// We know that the flavour we're being asked to create is valid, since the check is done when
// creating the action graph from the target graph.
ImmutableSortedSet<Flavor> flavors = target.getFlavors();
if (flavors.contains(Javadoc.DOC_JAR)) {
BuildTarget unflavored = BuildTarget.of(target.getUnflavoredBuildTarget());
BuildRule baseLibrary = resolver.requireRule(unflavored);
JarShape shape = params.getBuildTarget().getFlavors().contains(JavaLibrary.MAVEN_JAR) ? JarShape.MAVEN : JarShape.SINGLE;
JarShape.Summary summary = shape.gatherDeps(baseLibrary);
ImmutableSet<SourcePath> sources = summary.getPackagedRules().stream().filter(HasSources.class::isInstance).map(rule -> ((HasSources) rule).getSources()).flatMap(Collection::stream).collect(MoreCollectors.toImmutableSet());
// In theory, the only deps we need are the ones that contribute to the sourcepaths. However,
// javadoc wants to have classes being documented have all their deps be available somewhere.
// Ideally, we'd not build everything, but then we're not able to document any classes that
// rely on auto-generated classes, such as those created by the Immutables library. Oh well.
// Might as well add them as deps. *sigh*
ImmutableSortedSet.Builder<BuildRule> deps = ImmutableSortedSet.naturalOrder();
// Sourcepath deps
deps.addAll(ruleFinder.filterBuildRuleInputs(sources));
// Classpath deps
deps.add(baseLibrary);
deps.addAll(summary.getClasspath().stream().filter(rule -> HasClasspathEntries.class.isAssignableFrom(rule.getClass())).flatMap(rule -> rule.getTransitiveClasspathDeps().stream()).iterator());
BuildRuleParams emptyParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(deps.build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
return new Javadoc(emptyParams, args.mavenCoords, args.mavenPomTemplate, summary.getMavenDeps(), sources);
}
if (CalculateAbi.isAbiTarget(target)) {
BuildTarget libraryTarget = CalculateAbi.getLibraryTarget(target);
BuildRule libraryRule = resolver.requireRule(libraryTarget);
return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
}
BuildRuleParams paramsWithMavenFlavor = null;
if (flavors.contains(JavaLibrary.MAVEN_JAR)) {
paramsWithMavenFlavor = params;
// Maven rules will depend upon their vanilla versions, so the latter have to be constructed
// without the maven flavor to prevent output-path conflict
params = params.withoutFlavor(JavaLibrary.MAVEN_JAR);
}
if (flavors.contains(JavaLibrary.SRC_JAR)) {
args.mavenCoords = args.mavenCoords.map(input -> AetherUtil.addClassifier(input, AetherUtil.CLASSIFIER_SOURCES));
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return new JavaSourceJar(params, args.srcs, args.mavenCoords);
} else {
return MavenUberJar.SourceJar.create(Preconditions.checkNotNull(paramsWithMavenFlavor), args.srcs, args.mavenCoords, args.mavenPomTemplate);
}
}
JavacOptions javacOptions = JavacOptionsFactory.create(defaultOptions, params, resolver, ruleFinder, args);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableSortedSet<BuildRule> exportedDeps = resolver.getAllRules(args.exportedDeps);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), exportedDeps, resolver.getAllRules(args.providedDeps))), ruleFinder.filterBuildRuleInputs(javacOptions.getInputs(ruleFinder))));
DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), javacOptions.getGeneratedSourceFolderName(), args.proguardConfig, args.postprocessClassesCommands, exportedDeps, resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, javacOptions.getClassesToRemoveFromJar());
if (!flavors.contains(JavaLibrary.MAVEN_JAR)) {
return defaultJavaLibrary;
} else {
resolver.addToIndex(defaultJavaLibrary);
return MavenUberJar.create(defaultJavaLibrary, Preconditions.checkNotNull(paramsWithMavenFlavor), args.mavenCoords, args.mavenPomTemplate);
}
}
use of com.facebook.buck.parser.NoSuchBuildTargetException 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.parser.NoSuchBuildTargetException in project buck by facebook.
the class HaskellDescriptionUtils method createLinkRule.
/**
* Create a Haskell link rule that links the given inputs to a executable or shared library and
* pulls in transitive native linkable deps from the given dep roots.
*/
public static HaskellLinkRule createLinkRule(BuildTarget target, BuildRuleParams baseParams, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, HaskellConfig haskellConfig, Linker.LinkType linkType, ImmutableList<String> extraFlags, Iterable<Arg> linkerInputs, Iterable<? extends NativeLinkable> deps, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
Tool linker = haskellConfig.getLinker().resolve(resolver);
String name = target.getShortName();
ImmutableList.Builder<Arg> linkerArgsBuilder = ImmutableList.builder();
ImmutableList.Builder<Arg> argsBuilder = ImmutableList.builder();
// Add the base flags from the `.buckconfig` first.
argsBuilder.addAll(StringArg.from(haskellConfig.getLinkerFlags()));
// Pass in the appropriate flags to link a shared library.
if (linkType.equals(Linker.LinkType.SHARED)) {
name = CxxDescriptionEnhancer.getSharedLibrarySoname(Optional.empty(), target.withFlavors(), cxxPlatform);
argsBuilder.addAll(StringArg.from("-shared", "-dynamic"));
argsBuilder.addAll(StringArg.from(MoreIterables.zipAndConcat(Iterables.cycle("-optl"), cxxPlatform.getLd().resolve(resolver).soname(name))));
}
// Add in extra flags passed into this function.
argsBuilder.addAll(StringArg.from(extraFlags));
// We pass in the linker inputs and all native linkable deps by prefixing with `-optl` so that
// the args go straight to the linker, and preserve their order.
linkerArgsBuilder.addAll(linkerInputs);
for (NativeLinkable nativeLinkable : NativeLinkables.getNativeLinkables(cxxPlatform, deps, depType).values()) {
linkerArgsBuilder.addAll(NativeLinkables.getNativeLinkableInput(cxxPlatform, depType, nativeLinkable).getArgs());
}
// Since we use `-optl` to pass all linker inputs directly to the linker, the haskell linker
// will complain about not having any input files. So, create a dummy archive with an empty
// module and pass that in normally to work around this.
BuildTarget emptyModuleTarget = target.withAppendedFlavors(InternalFlavor.of("empty-module"));
WriteFile emptyModule = resolver.addToIndex(new WriteFile(baseParams.withBuildTarget(emptyModuleTarget), "module Unused where", BuildTargets.getGenPath(baseParams.getProjectFilesystem(), emptyModuleTarget, "%s/Unused.hs"), /* executable */
false));
HaskellCompileRule emptyCompiledModule = resolver.addToIndex(createCompileRule(target.withAppendedFlavors(InternalFlavor.of("empty-compiled-module")), baseParams, resolver, ruleFinder, // Buck dependency.
baseParams.getDeps(), cxxPlatform, haskellConfig, depType, Optional.empty(), Optional.empty(), ImmutableList.of(), HaskellSources.builder().putModuleMap("Unused", emptyModule.getSourcePathToOutput()).build()));
BuildTarget emptyArchiveTarget = target.withAppendedFlavors(InternalFlavor.of("empty-archive"));
Archive emptyArchive = resolver.addToIndex(Archive.from(emptyArchiveTarget, baseParams, ruleFinder, cxxPlatform, Archive.Contents.NORMAL, BuildTargets.getGenPath(baseParams.getProjectFilesystem(), emptyArchiveTarget, "%s/libempty.a"), emptyCompiledModule.getObjects()));
argsBuilder.add(SourcePathArg.of(emptyArchive.getSourcePathToOutput()));
ImmutableList<Arg> args = argsBuilder.build();
ImmutableList<Arg> linkerArgs = linkerArgsBuilder.build();
return resolver.addToIndex(new HaskellLinkRule(baseParams.withBuildTarget(target).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(linker.getDeps(ruleFinder)).addAll(Stream.of(args, linkerArgs).flatMap(Collection::stream).flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), linker, name, args, linkerArgs, haskellConfig.shouldCacheLinks()));
}
use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.
the class GoDescriptors method createGoBinaryRule.
static GoBinary createGoBinaryRule(BuildRuleParams params, final BuildRuleResolver resolver, GoBuckConfig goBuckConfig, ImmutableSet<SourcePath> srcs, List<String> compilerFlags, List<String> assemblerFlags, List<String> linkerFlags, GoPlatform platform) throws NoSuchBuildTargetException {
BuildTarget libraryTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("compile"), platform.getFlavor());
GoCompile library = GoDescriptors.createGoCompileRule(params.withBuildTarget(libraryTarget), resolver, goBuckConfig, Paths.get("main"), srcs, compilerFlags, assemblerFlags, platform, FluentIterable.from(params.getDeclaredDeps().get()).transform(BuildRule::getBuildTarget));
resolver.addToIndex(library);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = createTransitiveSymlinkTreeTarget(params.getBuildTarget());
SymlinkTree symlinkTree = makeSymlinkTree(params.withBuildTarget(target), pathResolver, ruleFinder, requireTransitiveGoLinkables(params.getBuildTarget(), resolver, platform, FluentIterable.from(params.getDeclaredDeps().get()).transform(BuildRule::getBuildTarget), /* includeSelf */
false));
resolver.addToIndex(symlinkTree);
LOG.verbose("Symlink tree for linking of %s: %s", params.getBuildTarget(), symlinkTree);
return new GoBinary(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(symlinkTree.getLinks().values())).add(symlinkTree).add(library).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), platform.getCxxPlatform().map(input -> input.getLd().resolve(resolver)), symlinkTree, library, goBuckConfig.getLinker(), ImmutableList.copyOf(linkerFlags), platform);
}
use of com.facebook.buck.parser.NoSuchBuildTargetException in project buck by facebook.
the class ActionGraphCache method createActionGraph.
private static ActionGraphAndResolver createActionGraph(final BuckEventBus eventBus, TargetNodeToBuildRuleTransformer transformer, TargetGraph targetGraph) {
final BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, transformer, eventBus);
AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException> bottomUpTraversal = new AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException>(targetGraph) {
@Override
public void visit(TargetNode<?, ?> node) {
try {
resolver.requireRule(node.getBuildTarget());
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(e);
}
}
};
bottomUpTraversal.traverse();
return ActionGraphAndResolver.builder().setActionGraph(new ActionGraph(resolver.getBuildRules())).setResolver(resolver).build();
}
Aggregations