use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class CxxCollectAndLogInferDependenciesStepTest method testStepWritesNoCellTokenInFileWhenCellIsAbsent.
@Test
public void testStepWritesNoCellTokenInFileWhenCellIsAbsent() throws IOException, InterruptedException {
assumeThat(Platform.detect(), is(not(WINDOWS)));
ProjectFilesystem filesystem = createFakeFilesystem("/Users/user/src");
BuildTarget testBuildTarget = BuildTarget.builder().setUnflavoredBuildTarget(UnflavoredBuildTarget.of(filesystem.getRootPath(), Optional.empty(), "//target", "short")).addFlavors(CxxInferEnhancer.InferFlavors.INFER.get()).build();
BuildRuleParams testBuildRuleParams = new FakeBuildRuleParamsBuilder(testBuildTarget).setProjectFilesystem(filesystem).build();
InferBuckConfig inferBuckConfig = new InferBuckConfig(FakeBuckConfig.builder().build());
CxxInferCaptureAndAggregatingRules<CxxInferAnalyze> captureAndAggregatingRules = new CxxInferCaptureAndAggregatingRules<>(ImmutableSet.of(), ImmutableSet.<CxxInferAnalyze>of());
CxxInferAnalyze analyzeRule = new CxxInferAnalyze(testBuildRuleParams, inferBuckConfig, captureAndAggregatingRules);
Path outputFile = Paths.get("infer-deps.txt");
CxxCollectAndLogInferDependenciesStep step = CxxCollectAndLogInferDependenciesStep.fromAnalyzeRule(analyzeRule, filesystem, outputFile);
ExecutionContext executionContext = TestExecutionContext.newInstance();
int exitCode = step.execute(executionContext).getExitCode();
assertThat(exitCode, is(StepExecutionResult.SUCCESS.getExitCode()));
String expectedOutput = InferLogLine.fromBuildTarget(testBuildTarget, analyzeRule.getAbsolutePathToResultsDir()).toString();
assertEquals(expectedOutput + "\n", filesystem.readFileIfItExists(outputFile).get());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class ArchiveTest method testThatBuildTargetSourcePathDepsAndPathsArePropagated.
@Test
public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
// Create a couple of genrules to generate inputs for an archive rule.
Genrule genrule1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut("foo/bar.o").build(resolver);
Genrule genrule2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")).setOut("foo/test.o").build(resolver);
// Build the archive using a normal input the outputs of the genrules above.
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o"), genrule1.getSourcePathToOutput(), genrule2.getSourcePathToOutput()));
// Verify that the archive dependencies include the genrules providing the
// SourcePath inputs.
assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps());
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class ArchiveTest method testThatInputChangesCauseRuleKeyChanges.
@Test
public void testThatInputChangesCauseRuleKeyChanges() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put(AR.toString(), Strings.repeat("0", 40)).put(RANLIB.toString(), Strings.repeat("1", 40)).put("a.o", Strings.repeat("a", 40)).put("b.o", Strings.repeat("b", 40)).put("c.o", Strings.repeat("c", 40)).put(Paths.get("different").toString(), Strings.repeat("d", 40)).build());
// Generate a rule key for the defaults.
RuleKey defaultRuleKey = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
// Verify that changing the archiver causes a rulekey change.
RuleKey archiverChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, new GnuArchiver(new HashedFileTool(Paths.get("different"))), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
assertNotEquals(defaultRuleKey, archiverChange);
// Verify that changing the output path causes a rulekey change.
RuleKey outputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, Paths.get("different"), DEFAULT_INPUTS));
assertNotEquals(defaultRuleKey, outputChange);
// Verify that changing the inputs causes a rulekey change.
RuleKey inputChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("different"))));
assertNotEquals(defaultRuleKey, inputChange);
// Verify that changing the type of archiver causes a rulekey change.
RuleKey archiverTypeChange = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(Archive.from(target, params, ruleFinder, new BsdArchiver(new HashedFileTool(AR)), ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, DEFAULT_INPUTS));
assertNotEquals(defaultRuleKey, archiverTypeChange);
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class ArchiveTest method flagsArePropagated.
@Test
public void flagsArePropagated() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of("-foo"), DEFAULT_RANLIB, ImmutableList.of("-bar"), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o")));
BuildContext buildContext = BuildContext.builder().from(FakeBuildContext.NOOP_CONTEXT).setSourcePathResolver(pathResolver).build();
ImmutableList<Step> steps = archive.getBuildSteps(buildContext, new FakeBuildableContext());
Step archiveStep = FluentIterable.from(steps).filter(ArchiveStep.class).first().get();
assertThat(archiveStep.getDescription(TestExecutionContext.newInstance()), containsString("-foo"));
Step ranlibStep = FluentIterable.from(steps).filter(RanlibStep.class).first().get();
assertThat(ranlibStep.getDescription(TestExecutionContext.newInstance()), containsString("-bar"));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder 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));
}
Aggregations