use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class ConcatStepTest method testConcatFiles.
@Test
public void testConcatFiles() throws IOException {
// Create three files containing "foo", "bar", and "baz"
// and see if they are correctly concatenated.
File dest = temp.newFile();
ImmutableList.Builder<Path> inputsBuilder = ImmutableList.builder();
String[] fileContents = { "foo", "bar", "baz" };
for (int i = 0; i < fileContents.length; i++) {
File src = temp.newFile();
PrintStream out = new PrintStream(src);
out.print(fileContents[i]);
inputsBuilder.add(src.toPath());
out.close();
}
ProjectFilesystem filesystem = new ProjectFilesystem(temp.getRoot().toPath());
ExecutionContext context = TestExecutionContext.newInstance();
ConcatStep step = new ConcatStep(filesystem, inputsBuilder.build(), dest.toPath());
step.execute(context);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(dest)));
assertEquals(reader.readLine(), "foobarbaz");
reader.close();
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class CopyNativeLibrariesTest method createAndroidBinaryRuleAndTestCopyNativeLibraryCommand.
private void createAndroidBinaryRuleAndTestCopyNativeLibraryCommand(ImmutableSet<TargetCpuType> cpuFilters, Path sourceDir, Path destinationDir, ImmutableList<String> expectedCommandDescriptions) {
// Invoke copyNativeLibrary to populate the steps.
ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
CopyNativeLibraries.copyNativeLibrary(new FakeProjectFilesystem(), sourceDir, destinationDir, cpuFilters, stepsBuilder);
ImmutableList<Step> steps = stepsBuilder.build();
assertEquals(steps.size(), expectedCommandDescriptions.size());
ExecutionContext context = TestExecutionContext.newInstance();
for (int i = 0; i < steps.size(); ++i) {
String description = steps.get(i).getDescription(context);
assertEquals(expectedCommandDescriptions.get(i), description);
}
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class DxStepTest method testDxCommandOptimizeNoJumbo.
@Test
public void testDxCommandOptimizeNoJumbo() throws IOException {
// Context with --verbose 2.
try (ExecutionContext context = createExecutionContext(2)) {
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
DxStep dx = new DxStep(filesystem, SAMPLE_OUTPUT_PATH, SAMPLE_FILES_TO_DEX);
String expected = String.format("%s --output %s %s", EXPECTED_DX_PREFIX, SAMPLE_OUTPUT_PATH, Joiner.on(' ').join(Iterables.transform(SAMPLE_FILES_TO_DEX, filesystem::resolve)));
MoreAsserts.assertShellCommands("Neither --no-optimize nor --force-jumbo should be present.", ImmutableList.of(expected), ImmutableList.of(dx), context);
verifyAll();
}
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class DxStepTest method testDxCommandNoOptimizeNoJumbo.
@Test
public void testDxCommandNoOptimizeNoJumbo() throws IOException {
// Context with --verbose 2.
try (ExecutionContext context = createExecutionContext(2)) {
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
DxStep dx = new DxStep(filesystem, SAMPLE_OUTPUT_PATH, SAMPLE_FILES_TO_DEX, EnumSet.of(Option.NO_OPTIMIZE));
String expected = String.format("%s --no-optimize --output %s %s", EXPECTED_DX_PREFIX, SAMPLE_OUTPUT_PATH, Joiner.on(' ').join(Iterables.transform(SAMPLE_FILES_TO_DEX, filesystem::resolve)));
MoreAsserts.assertShellCommands("--no-optimize should be present, but --force-jumbo should not.", ImmutableList.of(expected), ImmutableList.of(dx), context);
verifyAll();
}
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class MergeAndroidResourcesStepTest method testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage.
@Test
public void testGenerateRDotJavaWithPreviouslyEmptyResourceUnionPackage() throws IOException {
BuildTarget res1Target = BuildTargetFactory.newInstance("//:res1");
RDotTxtEntryBuilder entriesBuilder = new RDotTxtEntryBuilder();
entriesBuilder.add(new RDotTxtFile("com.res1", BuildTargets.getGenPath(entriesBuilder.getProjectFilesystem(), res1Target, "__%s_text_symbols__/R.txt").toString(), ImmutableList.of("int id id1 0x7f020000")));
FakeProjectFilesystem filesystem = entriesBuilder.getProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
HasAndroidResourceDeps res1 = AndroidResourceRuleBuilder.newBuilder().setRuleFinder(ruleFinder).setBuildTarget(res1Target).setRes(new FakeSourcePath("res1")).setRDotJavaPackage("res1").build();
MergeAndroidResourcesStep mergeStep = MergeAndroidResourcesStep.createStepForDummyRDotJava(filesystem, resolver, ImmutableList.of(res1), Paths.get("output"), /* forceFinalResourceIds */
false, Optional.of("resM"), /* rName */
Optional.empty(), /* useOldStyleableFormat */
false);
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertEquals(0, mergeStep.execute(executionContext).getExitCode());
String res1java = filesystem.readFileIfItExists(Paths.get("output/res1/R.java")).get();
String resMjava = filesystem.readFileIfItExists(Paths.get("output/resM/R.java")).get();
assertThat(res1java, StringContains.containsString("id1"));
assertThat(resMjava, StringContains.containsString("id1"));
}
Aggregations