use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class CalculateAbiStepTest method shouldCalculateAbiFromAStubJar.
@Test
public void shouldCalculateAbiFromAStubJar() throws IOException {
Path outDir = temp.newFolder().toAbsolutePath();
ProjectFilesystem filesystem = new ProjectFilesystem(outDir);
Path directory = TestDataHelper.getTestDataDirectory(this);
Path source = directory.resolve("prebuilt/junit.jar");
Path binJar = Paths.get("source.jar");
Files.copy(source, outDir.resolve(binJar));
Path abiJar = outDir.resolve("abi.jar");
ExecutionContext executionContext = TestExecutionContext.newInstance();
FakeBuildableContext context = new FakeBuildableContext();
new CalculateAbiStep(context, filesystem, binJar, abiJar).execute(executionContext);
String seenHash = filesystem.computeSha1(Paths.get("abi.jar")).getHash();
// Hi there! This is hardcoded here because we want to make sure buck always produces the same
// jar files across timezones and versions. If the test is failing because of an intentional
// modification to how we produce abi .jar files, then just update the hash, otherwise please
// investigate why the value is different.
// NOTE: If this starts failing on CI for no obvious reason it's possible that the offset
// calculation in ZipConstants.getFakeTime() does not account for DST correctly.
assertEquals("2f8dd47439697c6d633f7baef3d0f71cbac9d4a4", seenHash);
// Assert that the abiJar contains non-class resources (like txt files).
ZipInspector inspector = new ZipInspector(abiJar);
inspector.assertFileExists("LICENSE.txt");
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class JavaSourceJarTest method shouldOnlyIncludePathBasedSources.
@Test
public void shouldOnlyIncludePathBasedSources() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
SourcePath fileBased = new FakeSourcePath("some/path/File.java");
SourcePath ruleBased = new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//cheese:cake"));
JavaPackageFinder finderStub = createNiceMock(JavaPackageFinder.class);
expect(finderStub.findJavaPackageFolder((Path) anyObject())).andStubReturn(Paths.get("cheese"));
expect(finderStub.findJavaPackage((Path) anyObject())).andStubReturn("cheese");
// No need to verify. It's a stub. I don't care about the interactions.
EasyMock.replay(finderStub);
JavaSourceJar rule = new JavaSourceJar(new FakeBuildRuleParamsBuilder("//example:target").build(), ImmutableSortedSet.of(fileBased, ruleBased), Optional.empty());
BuildContext buildContext = BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(finderStub).setEventBus(BuckEventBusFactory.newInstance()).build();
ImmutableList<Step> steps = rule.getBuildSteps(buildContext, new FakeBuildableContext());
// There should be a CopyStep per file being copied. Count 'em.
int copyStepsCount = FluentIterable.from(steps).filter(CopyStep.class::isInstance).size();
assertEquals(1, copyStepsCount);
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class ExportFileTest method shouldSetSrcAndOutToNameParameterIfNeitherAreSet.
@Test
public void shouldSetSrcAndOutToNameParameterIfNeitherAreSet() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
ExportFile exportFile = ExportFileBuilder.newExportFileBuilder(target).build(resolver, projectFilesystem);
List<Step> steps = exportFile.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
MoreAsserts.assertSteps("The output directory should be created and then the file should be copied there.", ImmutableList.of("mkdir -p " + projectFilesystem.resolve("buck-out/gen"), "rm -f -r " + projectFilesystem.resolve("buck-out/gen/example.html"), "cp " + projectFilesystem.resolve("example.html") + " " + Paths.get("buck-out/gen/example.html")), steps, TestExecutionContext.newInstance());
assertEquals(projectFilesystem.getBuckPaths().getGenDir().resolve("example.html"), pathResolver.getRelativePath(exportFile.getSourcePathToOutput()));
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class GenruleTest method testGenruleWithWorkerMacroUsesSpecialShellStep.
@Test
public void testGenruleWithWorkerMacroUsesSpecialShellStep() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildRule genrule = createGenruleBuilderThatUsesWorkerMacro(ruleResolver).build(ruleResolver);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
List<Step> steps = genrule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
ExecutionContext executionContext = newEmptyExecutionContext(Platform.LINUX);
assertEquals(4, steps.size());
Step step = steps.get(3);
assertTrue(step instanceof WorkerShellStep);
WorkerShellStep workerShellStep = (WorkerShellStep) step;
assertThat(workerShellStep.getShortName(), Matchers.equalTo("worker"));
assertThat(workerShellStep.getEnvironmentVariables(executionContext), Matchers.hasEntry("OUT", filesystem.resolve(filesystem.getBuckPaths().getGenDir()).resolve("genrule_with_worker/output.txt").toString()));
}
use of com.facebook.buck.rules.FakeBuildableContext in project buck by facebook.
the class DefaultJavaLibraryTest method testStepsPresenceForForDirectJarSpooling.
@Test
public void testStepsPresenceForForDirectJarSpooling() {
BuildTarget buildTarget = BuildTargetFactory.newInstance("//:lib");
BuildRule javaLibraryBuildRule = createDefaultJavaLibraryRuleWithAbiKey(buildTarget, /* srcs */
ImmutableSortedSet.of("foo/Bar.java"), /* deps */
ImmutableSortedSet.of(), /* exportedDeps */
ImmutableSortedSet.of(), Optional.of(AbstractJavacOptions.SpoolMode.DIRECT_TO_JAR), /* postprocessClassesCommands */
ImmutableList.of());
BuildContext buildContext = createBuildContext(javaLibraryBuildRule, /* bootclasspath */
null);
ImmutableList<Step> steps = javaLibraryBuildRule.getBuildSteps(buildContext, new FakeBuildableContext());
assertThat(steps, Matchers.hasItem(Matchers.instanceOf(JavacDirectToJarStep.class)));
assertThat(steps, Matchers.not(Matchers.hasItem(Matchers.instanceOf(JavacStep.class))));
assertThat(steps, Matchers.not(Matchers.hasItem(Matchers.instanceOf(JarDirectoryStep.class))));
}
Aggregations