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());
}
}
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());
}
}
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()));
}
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));
}
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.");
}
Aggregations