Search in sources :

Example 26 with ExecutionContext

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();
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) InputStreamReader(java.io.InputStreamReader) ImmutableList(com.google.common.collect.ImmutableList) FileInputStream(java.io.FileInputStream) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BufferedReader(java.io.BufferedReader) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File) Test(org.junit.Test)

Example 27 with ExecutionContext

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);
    }
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step)

Example 28 with ExecutionContext

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();
    }
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 29 with ExecutionContext

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();
    }
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 30 with ExecutionContext

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"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

ExecutionContext (com.facebook.buck.step.ExecutionContext)176 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)140 Test (org.junit.Test)128 Path (java.nio.file.Path)79 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)67 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)66 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)55 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)50 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)45 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)44 Step (com.facebook.buck.step.Step)34 ImmutableList (com.google.common.collect.ImmutableList)32 BuildTarget (com.facebook.buck.model.BuildTarget)31 SourcePath (com.facebook.buck.rules.SourcePath)26 TestConsole (com.facebook.buck.testutil.TestConsole)25 FakeProcess (com.facebook.buck.util.FakeProcess)21 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)19 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)19