Search in sources :

Example 61 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeBuildSteps.

@Test
public void testSymlinkTreeBuildSteps() throws IOException {
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(resolver);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ImmutableList<Step> expectedBuildSteps = ImmutableList.of(new MakeCleanDirectoryStep(filesystem, symlinkTreeRoot), new SymlinkTreeStep(filesystem, symlinkTreeRoot, resolver.getMappedPaths(links)), new HeaderMapStep(filesystem, HeaderSymlinkTreeWithHeaderMap.getPath(filesystem, buildTarget), ImmutableMap.of(Paths.get("file"), filesystem.getBuckPaths().getBuckOut().relativize(symlinkTreeRoot).resolve("file"), Paths.get("directory/then/file"), filesystem.getBuckPaths().getBuckOut().relativize(symlinkTreeRoot).resolve("directory/then/file"))));
    ImmutableList<Step> actualBuildSteps = symlinkTreeBuildRule.getBuildSteps(buildContext, buildableContext);
    assertEquals(expectedBuildSteps, actualBuildSteps.subList(1, actualBuildSteps.size()));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Test(org.junit.Test)

Example 62 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class BaseCompileToJarStepFactoryTest method testAddPostprocessClassesCommands.

@Test
public void testAddPostprocessClassesCommands() {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    String androidBootClassPath = filesystem.resolve("android.jar").toString();
    ImmutableList<String> postprocessClassesCommands = ImmutableList.of("tool arg1", "tool2");
    Path outputDirectory = filesystem.getBuckPaths().getScratchDir().resolve("android/java/lib__java__classes");
    ImmutableSortedSet<Path> classpathEntries = ImmutableSortedSet.<Path>naturalOrder().add(filesystem.resolve("rt.jar")).add(filesystem.resolve("dep.jar")).build();
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList.Builder<Step> commands = ImmutableList.builder();
    commands.addAll(BaseCompileToJarStepFactory.addPostprocessClassesCommands(new FakeProjectFilesystem(), postprocessClassesCommands, outputDirectory, classpathEntries, Optional.of(androidBootClassPath)));
    ImmutableList<Step> steps = commands.build();
    assertEquals(2, steps.size());
    assertTrue(steps.get(0) instanceof ShellStep);
    ShellStep step0 = (ShellStep) steps.get(0);
    assertEquals(ImmutableList.of("bash", "-c", "tool arg1 " + outputDirectory), step0.getShellCommand(executionContext));
    assertEquals(ImmutableMap.of("COMPILATION_BOOTCLASSPATH", androidBootClassPath, "COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(classpathEntries, filesystem::resolve))), step0.getEnvironmentVariables(executionContext));
    assertTrue(steps.get(1) instanceof ShellStep);
    ShellStep step1 = (ShellStep) steps.get(1);
    assertEquals(ImmutableList.of("bash", "-c", "tool2 " + outputDirectory), step1.getShellCommand(executionContext));
    assertEquals(ImmutableMap.of("COMPILATION_BOOTCLASSPATH", androidBootClassPath, "COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(classpathEntries, filesystem::resolve))), step1.getEnvironmentVariables(executionContext));
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Test(org.junit.Test)

Example 63 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class DefaultJavaLibraryTest method testBuildInternalWithAndroidBootclasspath.

/** Make sure that when isAndroidLibrary is true, that the Android bootclasspath is used. */
@Test
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public void testBuildInternalWithAndroidBootclasspath() throws Exception {
    String folder = "android/java/src/com/facebook";
    tmp.newFolder(folder.split("/"));
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//" + folder + ":fb");
    Path src = Paths.get(folder, "Main.java");
    tmp.newFile(src.toString());
    BuildRule libraryRule = AndroidLibraryBuilder.createBuilder(buildTarget).addSrc(src).build(ruleResolver);
    DefaultJavaLibrary javaLibrary = (DefaultJavaLibrary) libraryRule;
    String bootclasspath = "effects.jar" + File.pathSeparator + "maps.jar" + File.pathSeparator + "usb.jar" + File.pathSeparator;
    BuildContext context = createBuildContext(libraryRule, bootclasspath);
    List<Step> steps = javaLibrary.getBuildSteps(context, new FakeBuildableContext());
    // Find the JavacStep and verify its bootclasspath.
    Step step = Iterables.find(steps, command -> command instanceof JavacStep);
    assertNotNull("Expected a JavacStep in the steplist.", step);
    JavacStep javac = (JavacStep) step;
    assertEquals("Should compile Main.java rather than generated R.java.", ImmutableSet.of(src), javac.getSrcs());
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) Step(com.facebook.buck.step.Step) Test(org.junit.Test)

Example 64 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class DefaultJavaLibraryTest method testClasspathForJavacCommand.

@Test
public void testClasspathForJavacCommand() throws Exception {
    // libraryOne responds like an ordinary prebuilt_jar with no dependencies. We have to use a
    // FakeJavaLibraryRule so that we can override the behavior of getAbiKey().
    BuildTarget libraryOneTarget = BuildTargetFactory.newInstance("//:libone");
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    FakeJavaLibrary libraryOne = new FakeJavaLibrary(libraryOneTarget, resolver) {

        @Override
        public Optional<BuildTarget> getAbiJar() {
            return Optional.empty();
        }

        @Override
        public ImmutableSet<SourcePath> getOutputClasspaths() {
            return ImmutableSet.of(new FakeSourcePath("java/src/com/libone/bar.jar"));
        }

        @Override
        public ImmutableSet<SourcePath> getTransitiveClasspaths() {
            return ImmutableSet.of();
        }

        @Override
        public ImmutableSet<JavaLibrary> getTransitiveClasspathDeps() {
            return ImmutableSet.of();
        }
    };
    ruleResolver.addToIndex(libraryOne);
    BuildTarget libraryTwoTarget = BuildTargetFactory.newInstance("//:libtwo");
    BuildRule libraryTwo = JavaLibraryBuilder.createBuilder(libraryTwoTarget).addSrc(Paths.get("java/src/com/libtwo/Foo.java")).addDep(libraryOne.getBuildTarget()).build(ruleResolver);
    List<Step> steps = libraryTwo.getBuildSteps(FakeBuildContext.withSourcePathResolver(resolver), new FakeBuildableContext());
    ImmutableList<JavacStep> javacSteps = FluentIterable.from(steps).filter(JavacStep.class).toList();
    assertEquals("There should be only one javac step.", 1, javacSteps.size());
    JavacStep javacStep = javacSteps.get(0);
    assertEquals("The classpath for the javac step to compile //:libtwo should contain only bar.jar.", ImmutableSet.of(libraryOne.getProjectFilesystem().resolve("java/src/com/libone/bar.jar")), javacStep.getClasspathEntries());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) Test(org.junit.Test)

Example 65 with Step

use of com.facebook.buck.step.Step in project buck by facebook.

the class DefaultJavaLibraryTest method testJavacDirectToJarStepIsNotPresentWhenPostprocessClassesCommandsPresent.

@Test
public void testJavacDirectToJarStepIsNotPresentWhenPostprocessClassesCommandsPresent() {
    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("process_class_files.py"));
    BuildContext buildContext = createBuildContext(javaLibraryBuildRule, /* bootclasspath */
    null);
    ImmutableList<Step> steps = javaLibraryBuildRule.getBuildSteps(buildContext, new FakeBuildableContext());
    assertThat(steps, Matchers.not(Matchers.hasItem(Matchers.instanceOf(JavacDirectToJarStep.class))));
    assertThat(steps, Matchers.hasItem(Matchers.instanceOf(JavacStep.class)));
    assertThat(steps, Matchers.hasItem(Matchers.instanceOf(JarDirectoryStep.class)));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) Step(com.facebook.buck.step.Step) Test(org.junit.Test)

Aggregations

Step (com.facebook.buck.step.Step)143 ImmutableList (com.google.common.collect.ImmutableList)82 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)65 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)62 Test (org.junit.Test)54 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)49 MkdirStep (com.facebook.buck.step.fs.MkdirStep)44 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)42 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)41 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)40 BuildTarget (com.facebook.buck.model.BuildTarget)39 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)36 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)35 ExecutionContext (com.facebook.buck.step.ExecutionContext)34 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)31 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)30 BuildContext (com.facebook.buck.rules.BuildContext)25 RmStep (com.facebook.buck.step.fs.RmStep)24 CopyStep (com.facebook.buck.step.fs.CopyStep)23