Search in sources :

Example 41 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException 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 42 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException 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)

Example 43 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class SegmentCommandUtils method createFromBuffer.

@SuppressWarnings("PMD.PrematureDeclaration")
public static SegmentCommand createFromBuffer(ByteBuffer buffer, NulTerminatedCharsetDecoder decoder) {
    LoadCommandCommonFields fields = LoadCommandCommonFieldsUtils.createFromBuffer(buffer);
    Preconditions.checkArgument(SegmentCommand.VALID_CMD_VALUES.contains(fields.getCmd()));
    boolean is64Bit = fields.getCmd().equals(SegmentCommand.LC_SEGMENT_64);
    String segname;
    try {
        segname = decoder.decodeString(buffer);
    } catch (CharacterCodingException e) {
        throw new HumanReadableException(e, "Cannot read segname for SegmentCommand at %d", fields.getOffsetInBinary());
    }
    buffer.position(fields.getOffsetInBinary() + LoadCommandCommonFields.CMD_AND_CMDSIZE_SIZE + SegmentCommand.SEGNAME_SIZE_IN_BYTES);
    return SegmentCommand.of(fields, segname, UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL), UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL), UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL), UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL), buffer.getInt(), buffer.getInt(), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()));
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 44 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class KotlinBuckConfig method getKotlinCompiler.

/**
   * Get the Tool instance for the Kotlin compiler.
   * @return the Kotlin compiler Tool
   */
public Supplier<Tool> getKotlinCompiler() {
    Path compilerPath = getKotlinHome().resolve("kotlinc");
    if (!Files.isExecutable(compilerPath)) {
        compilerPath = getKotlinHome().resolve(Paths.get("bin", "kotlinc"));
        if (!Files.isExecutable(compilerPath)) {
            throw new HumanReadableException("Could not resolve kotlinc location.");
        }
    }
    Path compiler = new ExecutableFinder().getExecutable(compilerPath, delegate.getEnvironment());
    return Suppliers.ofInstance(new HashedFileTool(compiler));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) HashedFileTool(com.facebook.buck.rules.HashedFileTool) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 45 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class ScalaBuckConfig method findScalac.

private Tool findScalac(BuildRuleResolver resolver) {
    Optional<Tool> configScalac = delegate.getTool(SECTION, "compiler", resolver);
    if (configScalac.isPresent()) {
        return configScalac.get();
    }
    Optional<Path> externalScalac = new ExecutableFinder().getOptionalExecutable(Paths.get("scalac"), delegate.getEnvironment());
    if (externalScalac.isPresent()) {
        return new HashedFileTool(externalScalac.get());
    }
    String scalaHome = delegate.getEnvironment().get("SCALA_HOME");
    if (scalaHome != null) {
        Path scalacInHomePath = Paths.get(scalaHome, "bin", "scalac");
        if (scalacInHomePath.toFile().exists()) {
            return new HashedFileTool(scalacInHomePath);
        }
        throw new HumanReadableException("Could not find scalac at $SCALA_HOME/bin/scalac.");
    }
    throw new HumanReadableException("Could not find scalac. Consider setting scala.compiler or $SCALA_HOME.");
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) HashedFileTool(com.facebook.buck.rules.HashedFileTool) HumanReadableException(com.facebook.buck.util.HumanReadableException) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15