Search in sources :

Example 6 with ImmutableSortedSet

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());
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Flavor(com.facebook.buck.model.Flavor)

Example 7 with ImmutableSortedSet

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BuildRule(com.facebook.buck.rules.BuildRule)

Example 8 with ImmutableSortedSet

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());
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule)

Example 9 with ImmutableSortedSet

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;
}
Also used : Iterables(com.google.common.collect.Iterables) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) BuildRule(com.facebook.buck.rules.BuildRule) Compiler(com.facebook.buck.cxx.Compiler) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) StringArg(com.facebook.buck.rules.args.StringArg) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableMap(com.google.common.collect.ImmutableMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) Arg(com.facebook.buck.rules.args.Arg) Stream(java.util.stream.Stream) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Joiner(com.google.common.base.Joiner) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ImmutableList(com.google.common.collect.ImmutableList) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg)

Example 10 with ImmutableSortedSet

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());
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) StringArg(com.facebook.buck.rules.args.StringArg) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule)

Aggregations

ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)51 BuildTarget (com.facebook.buck.model.BuildTarget)26 BuildRule (com.facebook.buck.rules.BuildRule)26 Path (java.nio.file.Path)25 SourcePath (com.facebook.buck.rules.SourcePath)22 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 ImmutableList (com.google.common.collect.ImmutableList)21 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)19 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 Optional (java.util.Optional)17 ImmutableSet (com.google.common.collect.ImmutableSet)16 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)15 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)14 Map (java.util.Map)13 Flavor (com.facebook.buck.model.Flavor)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 IOException (java.io.IOException)12 Preconditions (com.google.common.base.Preconditions)11 Suppliers (com.google.common.base.Suppliers)10 TargetGraph (com.facebook.buck.rules.TargetGraph)9