use of com.facebook.buck.rules.SourcePath 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.rules.SourcePath in project buck by facebook.
the class OcamlBuildRulesGenerator method generateBytecodeLinking.
/**
* Links the .cmo files generated by the bytecode compilation
*/
private BuildRule generateBytecodeLinking(ImmutableList<SourcePath> allInputs) {
BuildRuleParams linkParams = params.withBuildTarget(addBytecodeFlavor(params.getBuildTarget())).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(allInputs)).addAll(ocamlContext.getBytecodeLinkDeps()).addAll(Stream.concat(ocamlContext.getBytecodeLinkableInput().getArgs().stream(), ocamlContext.getCLinkableInput().getArgs().stream()).flatMap(arg -> arg.getDeps(ruleFinder).stream()).filter(rule -> !(rule instanceof OcamlBuild)).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.getOcamlBytecodeCompiler().get(), flags.build(), ocamlContext.getOcamlInteropIncludesDir(), ocamlContext.getBytecodeOutput(), ocamlContext.getNativePluginOutput(), ocamlContext.getBytecodeLinkableInput().getArgs(), ocamlContext.getCLinkableInput().getArgs(), ocamlContext.isLibrary(), /* isBytecode */
true, /* buildNativePlugin */
false);
resolver.addToIndex(link);
return link;
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class OcamlBuildStep method executeCCompilation.
private StepExecutionResult executeCCompilation(ExecutionContext context, ImmutableList.Builder<Path> linkerInputs) throws IOException, InterruptedException {
ImmutableList.Builder<String> cCompileFlags = ImmutableList.builder();
cCompileFlags.addAll(ocamlContext.getCCompileFlags());
cCompileFlags.addAll(ocamlContext.getCommonCFlags());
CxxPreprocessorInput cxxPreprocessorInput = ocamlContext.getCxxPreprocessorInput();
for (SourcePath cSrc : ocamlContext.getCInput()) {
Path outputPath = ocamlContext.getCOutput(resolver.getAbsolutePath(cSrc));
linkerInputs.add(outputPath);
Step compileStep = new OcamlCCompileStep(resolver, filesystem.getRootPath(), new OcamlCCompileStep.Args(cCompilerEnvironment, cCompiler, ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, cSrc, cCompileFlags.build(), cxxPreprocessorInput.getIncludes()));
StepExecutionResult compileExecutionResult = compileStep.execute(context);
if (!compileExecutionResult.isSuccess()) {
return compileExecutionResult;
}
}
return StepExecutionResult.SUCCESS;
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class LuaBinaryDescription method getStandaloneBinary.
private Tool getStandaloneBinary(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, SourcePath starter, String mainModule, final LuaPackageComponents components) {
Path output = getOutputPath(params.getBuildTarget(), params.getProjectFilesystem());
Tool lua = luaConfig.getLua(resolver);
Tool packager = luaConfig.getPackager().resolve(resolver);
LuaStandaloneBinary binary = resolver.addToIndex(new LuaStandaloneBinary(params.withAppendedFlavor(BINARY_FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(starter)).addAll(components.getDeps(ruleFinder)).addAll(lua.getDeps(ruleFinder)).addAll(packager.getDeps(ruleFinder)).build()), Suppliers.ofInstance(ImmutableSortedSet.of())), packager, ImmutableList.of(), output, Optional.of(starter), components, mainModule, lua, luaConfig.shouldCacheBinaries()));
return new CommandTool.Builder().addArg(SourcePathArg.of(binary.getSourcePathToOutput())).build();
}
use of com.facebook.buck.rules.SourcePath in project buck by facebook.
the class AbstractOcamlBuildContext method getLexOutput.
protected FluentIterable<SourcePath> getLexOutput(Iterable<SourcePath> lexInputs) {
return FluentIterable.from(lexInputs).transform(lexInput -> {
Path fileName = getSourcePathResolver().getAbsolutePath(lexInput).getFileName();
Path out = getGeneratedSourceDir().resolve(fileName.toString().replaceFirst(OcamlCompilables.OCAML_MLL_REGEX, OcamlCompilables.OCAML_ML));
return new PathSourcePath(getProjectFilesystem(), out);
});
}
Aggregations