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));
}
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);
}
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));
}
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));
}
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));
}
Aggregations