use of com.facebook.buck.rules.Tool in project buck by facebook.
the class GoDescriptors method getTestMainGenerator.
static Tool getTestMainGenerator(GoBuckConfig goBuckConfig, BuildRuleParams sourceParams, BuildRuleResolver resolver) throws NoSuchBuildTargetException {
Optional<Tool> configTool = goBuckConfig.getGoTestMainGenerator(resolver);
if (configTool.isPresent()) {
return configTool.get();
}
// TODO(mikekap): Make a single test main gen, rather than one per test. The generator itself
// doesn't vary per test.
BuildTarget generatorTarget = sourceParams.getBuildTarget().withFlavors(InternalFlavor.of("make-test-main-gen"));
Optional<BuildRule> generator = resolver.getRuleOptional(generatorTarget);
if (generator.isPresent()) {
return ((BinaryBuildRule) generator.get()).getExecutableCommand();
}
BuildTarget generatorSourceTarget = sourceParams.getBuildTarget().withAppendedFlavors(InternalFlavor.of("test-main-gen-source"));
WriteFile writeFile = resolver.addToIndex(new WriteFile(sourceParams.withBuildTarget(generatorSourceTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), extractTestMainGenerator(), BuildTargets.getGenPath(sourceParams.getProjectFilesystem(), generatorSourceTarget, "%s/main.go"), /* executable */
false));
GoBinary binary = resolver.addToIndex(createGoBinaryRule(sourceParams.withBuildTarget(generatorTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of(writeFile))), resolver, goBuckConfig, ImmutableSet.of(writeFile.getSourcePathToOutput()), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), goBuckConfig.getDefaultPlatform()));
return binary.getExecutableCommand();
}
use of com.facebook.buck.rules.Tool in project buck by facebook.
the class AbstractLuaScriptStarter method build.
@Override
public SourcePath build() {
BuildTarget templateTarget = BuildTarget.builder(getBaseParams().getBuildTarget()).addFlavors(InternalFlavor.of("starter-template")).build();
WriteFile templateRule = getRuleResolver().addToIndex(new WriteFile(getBaseParams().withBuildTarget(templateTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), getPureStarterTemplate(), BuildTargets.getGenPath(getBaseParams().getProjectFilesystem(), templateTarget, "%s/starter.lua.in"), /* executable */
false));
final Tool lua = getLuaConfig().getLua(getRuleResolver());
WriteStringTemplateRule writeStringTemplateRule = getRuleResolver().addToIndex(WriteStringTemplateRule.from(getBaseParams(), getRuleFinder(), getTarget(), getOutput(), templateRule.getSourcePathToOutput(), ImmutableMap.of("SHEBANG", lua.getCommandPrefix(getPathResolver()).get(0), "MAIN_MODULE", Escaper.escapeAsPythonString(getMainModule()), "MODULES_DIR", getRelativeModulesDir().isPresent() ? Escaper.escapeAsPythonString(getRelativeModulesDir().get().toString()) : "nil", "PY_MODULES_DIR", getRelativePythonModulesDir().isPresent() ? Escaper.escapeAsPythonString(getRelativePythonModulesDir().get().toString()) : "nil", "EXT_SUFFIX", Escaper.escapeAsPythonString(getCxxPlatform().getSharedLibraryExtension())), /* executable */
true));
return writeStringTemplateRule.getSourcePathToOutput();
}
use of com.facebook.buck.rules.Tool in project buck by facebook.
the class ScalaTestDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams rawParams, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
if (CalculateAbi.isAbiTarget(rawParams.getBuildTarget())) {
BuildTarget testTarget = CalculateAbi.getLibraryTarget(rawParams.getBuildTarget());
BuildRule testRule = resolver.requireRule(testTarget);
return CalculateAbi.of(rawParams.getBuildTarget(), ruleFinder, rawParams, Preconditions.checkNotNull(testRule.getSourcePathToOutput()));
}
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final BuildRule scalaLibrary = resolver.getRule(config.getScalaLibraryTarget());
BuildRuleParams params = rawParams.copyReplacingDeclaredAndExtraDeps(() -> ImmutableSortedSet.<BuildRule>naturalOrder().addAll(rawParams.getDeclaredDeps().get()).add(scalaLibrary).build(), rawParams.getExtraDeps());
JavaTestDescription.CxxLibraryEnhancement cxxLibraryEnhancement = new JavaTestDescription.CxxLibraryEnhancement(params, args.useCxxLibraries, args.cxxLibraryWhitelist, resolver, ruleFinder, cxxPlatform);
params = cxxLibraryEnhancement.updatedParams;
Tool scalac = config.getScalac(resolver);
BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), scalac.getDeps(ruleFinder))).withAppendedFlavor(JavaTest.COMPILED_TESTS_LIBRARY_FLAVOR);
JavaLibrary testsLibrary = resolver.addToIndex(new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, ResourceValidator.validateResources(pathResolver, params.getProjectFilesystem(), args.resources), /* generatedSourceFolderName */
Optional.empty(), /* proguardConfig */
Optional.empty(), /* postprocessClassesCommands */
ImmutableList.of(), /* exportDeps */
ImmutableSortedSet.of(), /* providedDeps */
ImmutableSortedSet.of(), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), /* trackClassUsage */
false, /* additionalClasspathEntries */
ImmutableSet.of(), new ScalacToJarStepFactory(scalac, config.getCompilerFlags(), args.extraArguments, ImmutableSet.of()), args.resourcesRoot, args.manifestFile, args.mavenCoords, /* tests */
ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of()));
return new JavaTest(params.copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(testsLibrary)), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, testsLibrary, /* additionalClasspathEntries */
ImmutableSet.of(), args.labels, args.contacts, args.testType.orElse(TestType.JUNIT), javaOptions.getJavaRuntimeLauncher(), args.vmArgs, cxxLibraryEnhancement.nativeLibsEnvironment, args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.testCaseTimeoutMs, args.env, args.runTestSeparately.orElse(false), args.forkMode.orElse(ForkMode.NONE), args.stdOutLogLevel, args.stdErrLogLevel);
}
use of com.facebook.buck.rules.Tool 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.Tool 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