use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class MultiarchFileInfos method create.
/**
* Inspect the given build target and return information about it if its a fat binary.
*
* @return non-empty when the target represents a fat binary.
* @throws com.facebook.buck.util.HumanReadableException
* when the target is a fat binary but has incompatible flavors.
*/
public static Optional<MultiarchFileInfo> create(final FlavorDomain<AppleCxxPlatform> appleCxxPlatforms, BuildTarget target) {
ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors(appleCxxPlatforms.getFlavors(), target.getFlavors());
if (thinFlavorSets.size() <= 1) {
// Actually a thin binary
return Optional.empty();
}
if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) {
throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target);
}
AppleCxxPlatform representativePlatform = null;
AppleSdk sdk = null;
for (SortedSet<Flavor> flavorSet : thinFlavorSets) {
AppleCxxPlatform platform = Preconditions.checkNotNull(appleCxxPlatforms.getValue(flavorSet).orElse(null));
if (sdk == null) {
sdk = platform.getAppleSdk();
representativePlatform = platform;
} else if (sdk != platform.getAppleSdk()) {
throw new HumanReadableException("%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target);
}
}
MultiarchFileInfo.Builder builder = MultiarchFileInfo.builder().setFatTarget(target).setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform));
BuildTarget platformFreeTarget = target.withoutFlavors(appleCxxPlatforms.getFlavors());
for (SortedSet<Flavor> flavorSet : thinFlavorSets) {
builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet));
}
return Optional.of(builder.build());
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class AbstractJavacOptions method getInputs.
public ImmutableSortedSet<SourcePath> getInputs(SourcePathRuleFinder ruleFinder) {
ImmutableSortedSet.Builder<SourcePath> builder = ImmutableSortedSet.<SourcePath>naturalOrder().addAll(getAnnotationProcessingParams().getInputs());
Optional<SourcePath> javacJarPath = getJavacJarPath();
if (javacJarPath.isPresent()) {
SourcePath sourcePath = javacJarPath.get();
// Add the original rule regardless of what happens next.
builder.add(sourcePath);
Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath);
if (possibleRule.isPresent()) {
BuildRule rule = possibleRule.get();
// And now include any transitive deps that contribute to the classpath.
if (rule instanceof JavaLibrary) {
builder.addAll(((JavaLibrary) rule).getDepsForTransitiveClasspathEntries().stream().map(BuildRule::getSourcePathToOutput).collect(MoreCollectors.toImmutableList()));
} else {
builder.add(sourcePath);
}
}
}
return builder.build();
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class OcamlBuildRulesGenerator method generateSingleMLBytecodeCompilation.
/**
* Compiles a single .ml file to a .cmo
*/
private void generateSingleMLBytecodeCompilation(Map<Path, ImmutableSortedSet<BuildRule>> sourceToRule, ImmutableList.Builder<SourcePath> cmoFiles, Path mlSource, ImmutableMap<Path, ImmutableList<Path>> sources, ImmutableList<Path> cycleDetector) {
ImmutableList<Path> newCycleDetector = ImmutableList.<Path>builder().addAll(cycleDetector).add(mlSource).build();
if (cycleDetector.contains(mlSource)) {
throw new HumanReadableException("Dependency cycle detected: %s", Joiner.on(" -> ").join(newCycleDetector));
}
if (sourceToRule.containsKey(mlSource)) {
return;
}
ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
if (sources.containsKey(mlSource)) {
for (Path dep : checkNotNull(sources.get(mlSource))) {
generateSingleMLBytecodeCompilation(sourceToRule, cmoFiles, dep, sources, newCycleDetector);
depsBuilder.addAll(checkNotNull(sourceToRule.get(dep)));
}
}
ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
String name = mlSource.toFile().getName();
BuildTarget buildTarget = createMLBytecodeCompileBuildTarget(params.getBuildTarget(), name);
BuildRuleParams compileParams = params.withBuildTarget(buildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().add(this.cleanRule).addAll(params.getDeclaredDeps().get()).addAll(deps).addAll(ocamlContext.getBytecodeCompileDeps()).addAll(cCompiler.getDeps(ruleFinder)).build()), params.getExtraDeps());
String outputFileName = getMLBytecodeOutputName(name);
Path outputPath = ocamlContext.getCompileBytecodeOutputDir().resolve(outputFileName);
final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
true, /* excludeDeps */
false);
BuildRule compileBytecode = new OcamlMLCompile(compileParams, new OcamlMLCompileStep.Args(params.getProjectFilesystem()::resolve, cCompiler.getEnvironment(pathResolver), cCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlBytecodeCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, mlSource, compileFlags));
resolver.addToIndex(compileBytecode);
sourceToRule.put(mlSource, ImmutableSortedSet.<BuildRule>naturalOrder().add(compileBytecode).addAll(deps).build());
if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
cmoFiles.add(compileBytecode.getSourcePathToOutput());
}
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class OcamlBuildRulesGenerator method generateNativeLinking.
/**
* Links the .cmx files generated by the native compilation
*/
private BuildRule generateNativeLinking(ImmutableList<SourcePath> allInputs) {
BuildRuleParams linkParams = params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(allInputs)).addAll(ocamlContext.getNativeLinkableInput().getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(ocamlContext.getCLinkableInput().getArgs().stream().flatMap(arg -> arg.getDeps(ruleFinder).stream()).iterator()).addAll(cxxCompiler.getDeps(ruleFinder)).build()), Suppliers.ofInstance(ImmutableSortedSet.of()));
ImmutableList.Builder<Arg> flags = ImmutableList.builder();
flags.addAll(ocamlContext.getFlags());
flags.addAll(StringArg.from(ocamlContext.getCommonCLinkerFlags()));
OcamlLink link = new OcamlLink(linkParams, allInputs, cxxCompiler.getEnvironment(pathResolver), cxxCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlCompiler().get(), flags.build(), ocamlContext.getOcamlInteropIncludesDir(), ocamlContext.getNativeOutput(), ocamlContext.getNativePluginOutput(), ocamlContext.getNativeLinkableInput().getArgs(), ocamlContext.getCLinkableInput().getArgs(), ocamlContext.isLibrary(), /* isBytecode */
false, buildNativePlugin);
resolver.addToIndex(link);
return link;
}
use of com.google.common.collect.ImmutableSortedSet in project buck by facebook.
the class OcamlBuildRulesGenerator method generateSingleMLNativeCompilation.
/**
* Compiles a single .ml file to a .cmx
*/
private void generateSingleMLNativeCompilation(Map<Path, ImmutableSortedSet<BuildRule>> sourceToRule, ImmutableList.Builder<SourcePath> cmxFiles, Path mlSource, ImmutableMap<Path, ImmutableList<Path>> sources, ImmutableList<Path> cycleDetector) {
ImmutableList<Path> newCycleDetector = ImmutableList.<Path>builder().addAll(cycleDetector).add(mlSource).build();
if (cycleDetector.contains(mlSource)) {
throw new HumanReadableException("Dependency cycle detected: %s", Joiner.on(" -> ").join(newCycleDetector));
}
if (sourceToRule.containsKey(mlSource)) {
return;
}
ImmutableSortedSet.Builder<BuildRule> depsBuilder = ImmutableSortedSet.naturalOrder();
if (sources.containsKey(mlSource)) {
for (Path dep : checkNotNull(sources.get(mlSource))) {
generateSingleMLNativeCompilation(sourceToRule, cmxFiles, dep, sources, newCycleDetector);
depsBuilder.addAll(checkNotNull(sourceToRule.get(dep)));
}
}
ImmutableSortedSet<BuildRule> deps = depsBuilder.build();
String name = mlSource.toFile().getName();
BuildTarget buildTarget = createMLNativeCompileBuildTarget(params.getBuildTarget(), name);
BuildRuleParams compileParams = params.withBuildTarget(buildTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(params.getDeclaredDeps().get()).add(this.cleanRule).addAll(deps).addAll(ocamlContext.getNativeCompileDeps()).addAll(cCompiler.getDeps(ruleFinder)).build()), params.getExtraDeps());
String outputFileName = getMLNativeOutputName(name);
Path outputPath = ocamlContext.getCompileNativeOutputDir().resolve(outputFileName);
final ImmutableList<Arg> compileFlags = getCompileFlags(/* isBytecode */
false, /* excludeDeps */
false);
OcamlMLCompile compile = new OcamlMLCompile(compileParams, new OcamlMLCompileStep.Args(params.getProjectFilesystem()::resolve, cCompiler.getEnvironment(pathResolver), cCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, mlSource, compileFlags));
resolver.addToIndex(compile);
sourceToRule.put(mlSource, ImmutableSortedSet.<BuildRule>naturalOrder().add(compile).addAll(deps).build());
if (!outputFileName.endsWith(OcamlCompilables.OCAML_CMI)) {
cmxFiles.add(compile.getSourcePathToOutput());
}
}
Aggregations