Search in sources :

Example 11 with Tool

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

the class AppleCxxPlatformsTest method buckTargetIsUsedWhenBuildTargetIsSpecified.

@Test
public void buckTargetIsUsedWhenBuildTargetIsSpecified() {
    AppleCxxPlatform appleCxxPlatform = buildAppleCxxPlatform(temp.getRoot(), FakeBuckConfig.builder().setSections("[apple]", "codesign = //foo:bar").build());
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
    BinaryBuildRule buildRule = EasyMock.createMock(BinaryBuildRule.class);
    Tool codesign = EasyMock.createMock(Tool.class);
    EasyMock.expect(buildRule.getExecutableCommand()).andReturn(codesign);
    BuildRuleResolver buildRuleResolver = EasyMock.createMock(BuildRuleResolver.class);
    EasyMock.expect(buildRuleResolver.getRuleOptional(buildTarget)).andReturn(Optional.of(buildRule));
    EasyMock.replay(buildRule, buildRuleResolver);
    assertThat(appleCxxPlatform.getCodesignProvider().resolve(buildRuleResolver), is(codesign));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VersionedTool(com.facebook.buck.rules.VersionedTool) Tool(com.facebook.buck.rules.Tool) Test(org.junit.Test)

Example 12 with Tool

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

the class CxxCollectAndLogInferDependenciesStepTest method createCaptureRule.

private CxxInferCapture createCaptureRule(BuildRuleParams buildRuleParams, SourcePathResolver sourcePathResolver, ProjectFilesystem filesystem, InferBuckConfig inferBuckConfig) throws Exception {
    RuleKeyAppendableFunction<FrameworkPath, Path> defaultFrameworkPathSearchPathFunction = new RuleKeyAppendableFunction<FrameworkPath, Path>() {

        @Override
        public void appendToRuleKey(RuleKeyObjectSink sink) {
        // Do nothing.
        }

        @Override
        public Path apply(FrameworkPath input) {
            return Paths.get("test", "framework", "path", input.toString());
        }
    };
    SourcePath preprocessor = new PathSourcePath(filesystem, Paths.get("preprocessor"));
    Tool preprocessorTool = new CommandTool.Builder().addInput(preprocessor).build();
    PreprocessorDelegate preprocessorDelegate = new PreprocessorDelegate(sourcePathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), Paths.get("whatever"), new GccPreprocessor(preprocessorTool), PreprocessorFlags.builder().build(), defaultFrameworkPathSearchPathFunction, Optional.empty(), /* leadingIncludePaths */
    Optional.empty());
    return new CxxInferCapture(buildRuleParams, CxxToolFlags.of(), CxxToolFlags.of(), new FakeSourcePath("src.c"), AbstractCxxSource.Type.C, Paths.get("src.o"), preprocessorDelegate, inferBuckConfig, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER);
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) RuleKeyAppendableFunction(com.facebook.buck.rules.args.RuleKeyAppendableFunction) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) RuleKeyObjectSink(com.facebook.buck.rules.RuleKeyObjectSink) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool)

Example 13 with Tool

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

the class CxxPreprocessAndCompileTest method compilerAndPreprocessorAreAlwaysReturnedFromGetInputsAfterBuildingLocally.

@Test
public void compilerAndPreprocessorAreAlwaysReturnedFromGetInputsAfterBuildingLocally() throws Exception {
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    SourcePath preprocessor = new PathSourcePath(filesystem, Paths.get("preprocessor"));
    Tool preprocessorTool = new CommandTool.Builder().addInput(preprocessor).build();
    SourcePath compiler = new PathSourcePath(filesystem, Paths.get("compiler"));
    Tool compilerTool = new CommandTool.Builder().addInput(compiler).build();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(filesystem).build();
    BuildContext context = FakeBuildContext.withSourcePathResolver(pathResolver);
    filesystem.writeContentsToPath("test.o: " + pathResolver.getRelativePath(DEFAULT_INPUT) + " ", filesystem.getPath("test.o.dep"));
    CxxPreprocessAndCompile cxxPreprocess = CxxPreprocessAndCompile.preprocessAndCompile(params, new PreprocessorDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_PLATFORM.getHeaderVerification(), DEFAULT_WORKING_DIR, new GccPreprocessor(preprocessorTool), PreprocessorFlags.builder().build(), DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION, Optional.empty(), /* leadingIncludePaths */
    Optional.empty()), new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, DEFAULT_COMPILER, CxxToolFlags.of()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, Optional.empty(), CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty());
    assertThat(cxxPreprocess.getInputsAfterBuildingLocally(context), hasItem(preprocessor));
    CxxPreprocessAndCompile cxxCompile = CxxPreprocessAndCompile.compile(params, new CompilerDelegate(pathResolver, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, new GccCompiler(compilerTool), CxxToolFlags.of()), DEFAULT_OUTPUT, DEFAULT_INPUT, DEFAULT_INPUT_TYPE, CxxPlatformUtils.DEFAULT_COMPILER_DEBUG_PATH_SANITIZER, CxxPlatformUtils.DEFAULT_ASSEMBLER_DEBUG_PATH_SANITIZER, Optional.empty());
    assertThat(cxxCompile.getInputsAfterBuildingLocally(context), hasItem(compiler));
}
Also used : FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 14 with Tool

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

the class RemoteFileDescriptionTest method remoteFileBinaryRuleIsCreatedForExecutableType.

@Test
public void remoteFileBinaryRuleIsCreatedForExecutableType() throws NoSuchBuildTargetException {
    BuildTarget target = BuildTargetFactory.newInstance("//mmmm:kale");
    RemoteFileDescription.Arg arg = description.createUnpopulatedConstructorArg();
    arg.type = Optional.of(RemoteFile.Type.EXECUTABLE);
    arg.sha1 = "cf23df2207d99a74fbe169e3eba035e633b65d94";
    arg.out = Optional.of("kale");
    BuildRule buildRule = description.createBuildRule(TargetGraph.EMPTY, RemoteFileBuilder.createBuilder(downloader, target).createBuildRuleParams(ruleResolver, filesystem), ruleResolver, arg);
    ruleResolver.addToIndex(buildRule);
    assertThat(buildRule, CoreMatchers.instanceOf(RemoteFileBinary.class));
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    Tool executableCommand = ((RemoteFileBinary) buildRule).getExecutableCommand();
    assertThat(executableCommand.getInputs(), Matchers.hasSize(1));
    SourcePath input = Iterables.getOnlyElement(executableCommand.getInputs());
    Path absolutePath = pathResolver.getAbsolutePath(input);
    assertEquals("kale", absolutePath.getFileName().toString());
    assertEquals(ImmutableList.of(absolutePath.toString()), executableCommand.getCommandPrefix(pathResolver));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Tool(com.facebook.buck.rules.Tool) Test(org.junit.Test)

Example 15 with Tool

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

the class LuaBinaryDescriptionTest method toolOverride.

@Test
public void toolOverride() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    Tool override = new CommandTool.Builder().addArg("override").build();
    LuaBinary binary = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:rule"), FakeLuaConfig.DEFAULT.withLua(override).withExtension(".override")).setMainModule("main").build(resolver);
    assertThat(binary.getLua(), Matchers.is(override));
}
Also used : PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxPythonExtensionBuilder(com.facebook.buck.python.CxxPythonExtensionBuilder) CxxTestBuilder(com.facebook.buck.cxx.CxxTestBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) PythonLibraryBuilder(com.facebook.buck.python.PythonLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) 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