Search in sources :

Example 1 with Tool

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();
}
Also used : WriteFile(com.facebook.buck.file.WriteFile) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) Tool(com.facebook.buck.rules.Tool)

Example 2 with Tool

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();
}
Also used : WriteFile(com.facebook.buck.file.WriteFile) BuildTarget(com.facebook.buck.model.BuildTarget) WriteStringTemplateRule(com.facebook.buck.rules.WriteStringTemplateRule) Tool(com.facebook.buck.rules.Tool)

Example 3 with Tool

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);
}
Also used : Optional(java.util.Optional) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTestDescription(com.facebook.buck.jvm.java.JavaTestDescription) JavaTest(com.facebook.buck.jvm.java.JavaTest) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool)

Example 4 with Tool

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();
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool)

Example 5 with Tool

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

Tool (com.facebook.buck.rules.Tool)30 BuildTarget (com.facebook.buck.model.BuildTarget)14 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)12 Test (org.junit.Test)12 CommandTool (com.facebook.buck.rules.CommandTool)11 BuildRule (com.facebook.buck.rules.BuildRule)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 SourcePath (com.facebook.buck.rules.SourcePath)8 Path (java.nio.file.Path)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 VersionedTool (com.facebook.buck.rules.VersionedTool)5 ImmutableList (com.google.common.collect.ImmutableList)5 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)4 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)4 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 HashedFileTool (com.facebook.buck.rules.HashedFileTool)4 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)3