Search in sources :

Example 26 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class ScalaLibraryDescription 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 libraryTarget = CalculateAbi.getLibraryTarget(rawParams.getBuildTarget());
        BuildRule libraryRule = resolver.requireRule(libraryTarget);
        return CalculateAbi.of(rawParams.getBuildTarget(), ruleFinder, rawParams, Preconditions.checkNotNull(libraryRule.getSourcePathToOutput()));
    }
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Tool scalac = scalaBuckConfig.getScalac(resolver);
    final BuildRule scalaLibrary = resolver.getRule(scalaBuckConfig.getScalaLibraryTarget());
    BuildRuleParams params = rawParams.copyReplacingDeclaredAndExtraDeps(() -> ImmutableSortedSet.<BuildRule>naturalOrder().addAll(rawParams.getDeclaredDeps().get()).add(scalaLibrary).build(), rawParams.getExtraDeps());
    BuildRuleParams javaLibraryParams = params.copyAppendingExtraDeps(Iterables.concat(BuildRules.getExportedRules(Iterables.concat(params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps))), scalac.getDeps(ruleFinder)));
    return new DefaultJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, args.srcs, validateResources(pathResolver, params.getProjectFilesystem(), args.resources), /* generatedSourceFolder */
    Optional.empty(), /* proguardConfig */
    Optional.empty(), /* postprocessClassesCommands */
    ImmutableList.of(), params.getDeclaredDeps().get(), resolver.getAllRules(args.providedDeps), JavaLibraryRules.getAbiInputs(resolver, javaLibraryParams.getDeps()), /* trackClassUsage */
    false, /* additionalClasspathEntries */
    ImmutableSet.of(), new ScalacToJarStepFactory(scalac, scalaBuckConfig.getCompilerFlags(), args.extraArguments, resolver.getAllRules(scalaBuckConfig.getCompilerPlugins())), args.resourcesRoot, args.manifestFile, args.mavenCoords, args.tests, /* classesToRemoveFromJar */
    ImmutableSet.of());
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) Tool(com.facebook.buck.rules.Tool)

Example 27 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class PythonBinaryDescriptionTest method executableCommandWithPathToPexExecutor.

@Test
public void executableCommandWithPathToPexExecutor() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bin");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    final Path executor = Paths.get("executor");
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public Optional<Tool> getPexExecutor(BuildRuleResolver resolver) {
            return Optional.of(new HashedFileTool(executor));
        }
    };
    PythonBinaryBuilder builder = new PythonBinaryBuilder(target, config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    PythonPackagedBinary binary = (PythonPackagedBinary) builder.setMainModule("main").build(resolver);
    assertThat(binary.getExecutableCommand().getCommandPrefix(pathResolver), Matchers.contains(executor.toString(), pathResolver.getAbsolutePath(binary.getSourcePathToOutput()).toString()));
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 28 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class PythonBinaryDescriptionTest method pexToolBuilderAddedToRuntimeDeps.

@Test
public void pexToolBuilderAddedToRuntimeDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(), new DefaultTargetNodeToBuildRuleTransformer());
    ShBinary pyTool = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:py_tool")).setMain(new FakeSourcePath("run.sh")).build(resolver);
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public Optional<Tool> getPexExecutor(BuildRuleResolver resolver) {
            return Optional.of(pyTool.getExecutableCommand());
        }
    };
    PythonBinary standaloneBinary = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS).setMainModule("hello").setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE).build(resolver);
    assertThat(standaloneBinary.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(pyTool.getBuildTarget()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ShBinary(com.facebook.buck.shell.ShBinary) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 29 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class RustTestDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
    BuildTarget exeTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("unittest"));
    BinaryWrapperRule testExeBuild = resolver.addToIndex(RustCompileUtils.createBinaryBuildRule(params.withBuildTarget(exeTarget), resolver, rustBuckConfig, cxxPlatforms, defaultCxxPlatform, args.crate, args.features, Stream.of(args.framework ? Stream.of("--test") : Stream.<String>empty(), rustBuckConfig.getRustTestFlags().stream(), args.rustcFlags.stream()).flatMap(x -> x).iterator(), args.linkerFlags.iterator(), RustCompileUtils.getLinkStyle(params.getBuildTarget(), args.linkStyle), args.rpath, args.srcs, args.crateRoot, ImmutableSet.of("lib.rs", "main.rs")));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Tool testExe = testExeBuild.getExecutableCommand();
    BuildRuleParams testParams = params.copyAppendingExtraDeps(testExe.getDeps(ruleFinder));
    return new RustTest(testParams, ruleFinder, testExeBuild, args.labels, args.contacts);
}
Also used : Linker(com.facebook.buck.cxx.Linker) BinaryWrapperRule(com.facebook.buck.rules.BinaryWrapperRule) CellPathResolver(com.facebook.buck.rules.CellPathResolver) ToolProvider(com.facebook.buck.rules.ToolProvider) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePath(com.facebook.buck.rules.SourcePath) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavored(com.facebook.buck.model.Flavored) BuildRule(com.facebook.buck.rules.BuildRule) FlavorDomain(com.facebook.buck.model.FlavorDomain) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) CxxPlatforms(com.facebook.buck.cxx.CxxPlatforms) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) Stream(java.util.stream.Stream) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) VersionRoot(com.facebook.buck.versions.VersionRoot) Optional(java.util.Optional) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BinaryWrapperRule(com.facebook.buck.rules.BinaryWrapperRule) Tool(com.facebook.buck.rules.Tool)

Example 30 with Tool

use of com.facebook.buck.rules.Tool in project buck by facebook.

the class AppleCxxPlatformsTest method appleCxxPlatformShouldUsePreferredSwiftVersion.

@Test
public void appleCxxPlatformShouldUsePreferredSwiftVersion() throws IOException {
    AppleCxxPlatform platformWithConfiguredSwift = buildAppleCxxPlatformWithSwiftToolchain(false);
    Optional<SwiftPlatform> swiftPlatformOptional = platformWithConfiguredSwift.getSwiftPlatform();
    assertThat(swiftPlatformOptional.isPresent(), is(true));
    Tool swiftTool = swiftPlatformOptional.get().getSwift();
    assertThat(((VersionedTool) swiftTool).getPath(), not(equalTo(Paths.get("Toolchains/Swift_2.3.xctoolchain/usr/bin/swift"))));
    assertThat(swiftPlatformOptional.get().getSwiftRuntimePaths(), equalTo(ImmutableSet.of(temp.getRoot().resolve("usr/lib/swift/iphoneos"))));
}
Also used : SwiftPlatform(com.facebook.buck.swift.SwiftPlatform) VersionedTool(com.facebook.buck.rules.VersionedTool) Tool(com.facebook.buck.rules.Tool) Test(org.junit.Test)

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