use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class AbstractCxxSourceRuleFactory method getPreprocessDeps.
private ImmutableSortedSet<BuildRule> getPreprocessDeps() {
ImmutableSortedSet.Builder<BuildRule> builder = ImmutableSortedSet.naturalOrder();
for (CxxPreprocessorInput input : getCxxPreprocessorInput()) {
builder.addAll(input.getDeps(getResolver(), getRuleFinder()));
}
if (getPrefixHeader().isPresent()) {
builder.addAll(getRuleFinder().filterBuildRuleInputs(getPrefixHeader().get()));
}
if (getPrecompiledHeader().isPresent()) {
builder.addAll(getRuleFinder().filterBuildRuleInputs(getPrecompiledHeader().get()));
}
if (getSandboxTree().isPresent()) {
SymlinkTree tree = getSandboxTree().get();
builder.add(tree);
builder.addAll(getRuleFinder().filterBuildRuleInputs(tree.getLinks().values()));
}
return builder.build();
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class CxxDescriptionEnhancer method createBuildRulesForCxxBinaryDescriptionArg.
public static CxxLinkAndCompileRules createBuildRulesForCxxBinaryDescriptionArg(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, CxxBinaryDescription.Arg args, Optional<StripStyle> stripStyle, Optional<LinkerMapMode> flavoredLinkerMapMode) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ImmutableMap<String, CxxSource> srcs = parseCxxSources(params.getBuildTarget(), resolver, ruleFinder, pathResolver, cxxPlatform, args);
ImmutableMap<Path, SourcePath> headers = parseHeaders(params.getBuildTarget(), resolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args);
// Build the binary deps.
ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
// Add original declared and extra deps.
depsBuilder.addAll(params.getDeps());
// Add in deps found via deps query.
args.depsQuery.ifPresent(depsQuery -> QueryUtils.resolveDepQuery(params, depsQuery, resolver, targetGraph).forEach(depsBuilder::add));
ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
return createBuildRulesForCxxBinary(params, resolver, cxxBuckConfig, cxxPlatform, srcs, headers, deps, stripStyle, flavoredLinkerMapMode, args.linkStyle.orElse(Linker.LinkableDepType.STATIC), args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, args.frameworks, args.libraries, args.compilerFlags, args.langCompilerFlags, args.platformCompilerFlags, args.prefixHeader, args.precompiledHeader, args.linkerFlags, args.platformLinkerFlags, args.cxxRuntimeType, args.includeDirs, Optional.empty());
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class JavaSymbolFinder method getCandidatePaths.
/**
* Guessing file names from fully-qualified Java symbols is ambiguous, because we don't know ahead
* of time exactly what part of the symbol is the package, and what part is class names or static
* members. This returns the set of all possible Java files for a given symbol, given different
* possibilities for the package name and resolving against all the available source roots.
* Returns only those candidates that actually exist.
*/
private ImmutableSortedSet<Path> getCandidatePaths(String symbol, Collection<Path> srcRoots) {
ImmutableSortedSet.Builder<Path> candidatePaths = ImmutableSortedSet.naturalOrder();
List<String> symbolParts = Lists.newArrayList(symbol.split("\\."));
for (int symbolIndex = 0; symbolIndex < symbolParts.size(); symbolIndex++) {
List<String> pathPartsList = symbolParts.subList(0, symbolIndex);
String[] pathParts = pathPartsList.toArray(new String[pathPartsList.size()]);
String candidateFileName = symbolParts.get(symbolIndex) + ".java";
for (Path srcRoot : srcRoots) {
Path candidatePath = srcRoot.resolve(Paths.get("", pathParts)).resolve(candidateFileName);
if (projectFilesystem.exists(candidatePath)) {
candidatePaths.add(candidatePath);
}
}
}
return candidatePaths.build();
}
use of com.google.common.collect.ImmutableSortedSet 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.google.common.collect.ImmutableSortedSet 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()));
}
Aggregations