Search in sources :

Example 6 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class MultiarchFileTest method descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile.

@SuppressWarnings({ "unchecked" })
@Test
public void descriptionWithMultiplePlatformArgsShouldGenerateMultiarchFile() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64");
    BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//foo:thing#iphoneos-i386,iphoneos-x86_64,sandbox");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleLibraryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRule multiarchRule = nodeBuilderFactory.getNodeBuilder(target).build(resolver, filesystem);
    assertThat(multiarchRule, instanceOf(MultiarchFile.class));
    ImmutableList<Step> steps = multiarchRule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
    ShellStep step = Iterables.getLast(Iterables.filter(steps, ShellStep.class));
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    ImmutableList<String> command = step.getShellCommand(executionContext);
    assertThat(command, Matchers.contains(endsWith("lipo"), equalTo("-create"), equalTo("-output"), containsString("foo/thing#"), containsString("/thing#"), containsString("/thing#")));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep) Matchers.containsString(org.hamcrest.Matchers.containsString) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTarget(com.facebook.buck.model.BuildTarget) ShellStep(com.facebook.buck.shell.ShellStep) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 7 with ShellStep

use of com.facebook.buck.shell.ShellStep 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 8 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class MoreAsserts method assertShellCommands.

/**
   * Asserts that every {@link com.facebook.buck.step.Step} in the observed list is a
   * {@link com.facebook.buck.shell.ShellStep} whose shell
   * command arguments match those of the corresponding entry in the expected list.
   */
public static void assertShellCommands(String userMessage, List<String> expected, List<Step> observed, ExecutionContext context) {
    Iterator<String> expectedIter = expected.iterator();
    Iterator<Step> observedIter = observed.iterator();
    Joiner joiner = Joiner.on(" ");
    while (expectedIter.hasNext() && observedIter.hasNext()) {
        String expectedShellCommand = expectedIter.next();
        Step observedStep = observedIter.next();
        if (!(observedStep instanceof ShellStep)) {
            failWith(userMessage, "Observed command must be a shell command: " + observedStep);
        }
        ShellStep shellCommand = (ShellStep) observedStep;
        String observedShellCommand = joiner.join(shellCommand.getShellCommand(context));
        assertEquals(userMessage, expectedShellCommand, observedShellCommand);
    }
    if (expectedIter.hasNext()) {
        failWith(userMessage, "Extra expected command: " + expectedIter.next());
    }
    if (observedIter.hasNext()) {
        failWith(userMessage, "Extra observed command: " + observedIter.next());
    }
}
Also used : Joiner(com.google.common.base.Joiner) ShellStep(com.facebook.buck.shell.ShellStep) Step(com.facebook.buck.step.Step) ShellStep(com.facebook.buck.shell.ShellStep)

Example 9 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class Project method processJsonConfig.

private ExitCodeAndOutput processJsonConfig(File jsonTempFile, boolean generateMinimalProject) throws IOException, InterruptedException {
    ImmutableList.Builder<String> argsBuilder = ImmutableList.<String>builder().add(pythonInterpreter).add(PATH_TO_INTELLIJ_PY).add(jsonTempFile.getAbsolutePath());
    if (generateMinimalProject) {
        argsBuilder.add("--generate_minimum_project");
    }
    if (turnOffAutoSourceGeneration) {
        argsBuilder.add("--disable_android_auto_generation_setting");
    }
    final ImmutableList<String> args = argsBuilder.build();
    ShellStep command = new ShellStep(projectFilesystem.getRootPath()) {

        @Override
        public String getShortName() {
            return "python";
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
            return args;
        }
    };
    Console console = executionContext.getConsole();
    Console childConsole = new Console(Verbosity.SILENT, console.getStdOut(), console.getStdErr(), Ansi.withoutTty());
    int exitCode;
    try (ExecutionContext childContext = ExecutionContext.builder().from(executionContext).setConsole(childConsole).setExecutors(executionContext.getExecutors()).build()) {
        exitCode = command.execute(childContext).getExitCode();
    }
    return new ExitCodeAndOutput(exitCode, command.getStdout(), command.getStderr());
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) Console(com.facebook.buck.util.Console)

Example 10 with ShellStep

use of com.facebook.buck.shell.ShellStep in project buck by facebook.

the class Javadoc method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), output.getParent()));
    steps.add(new RmStep(getProjectFilesystem(), output));
    // Fast path: nothing to do so just create an empty zip and return.
    if (sources.isEmpty()) {
        steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.<Path>of(), /* junk paths */
        false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, output));
        return steps.build();
    }
    Path sourcesListFilePath = scratchDir.resolve("all-sources.txt");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
    // Write an @-file with all the source files in
    steps.add(new WriteFileStep(getProjectFilesystem(), Joiner.on("\n").join(sources.stream().map(context.getSourcePathResolver()::getAbsolutePath).map(Path::toString).iterator()), sourcesListFilePath, /* can execute */
    false));
    Path atArgs = scratchDir.resolve("options");
    // Write an @-file with the classpath
    StringBuilder argsBuilder = new StringBuilder("-classpath ");
    Joiner.on(File.pathSeparator).appendTo(argsBuilder, getDeps().stream().filter(HasClasspathEntries.class::isInstance).flatMap(rule -> ((HasClasspathEntries) rule).getTransitiveClasspaths().stream()).map(context.getSourcePathResolver()::getAbsolutePath).map(Object::toString).iterator());
    steps.add(new WriteFileStep(getProjectFilesystem(), argsBuilder.toString(), atArgs, /* can execute */
    false));
    Path uncompressedOutputDir = scratchDir.resolve("docs");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), uncompressedOutputDir));
    steps.add(new ShellStep(getProjectFilesystem().resolve(scratchDir)) {

        @Override
        protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
            return ImmutableList.of("javadoc", "-Xdoclint:none", "-notimestamp", "-d", uncompressedOutputDir.getFileName().toString(), "@" + getProjectFilesystem().resolve(atArgs), "@" + getProjectFilesystem().resolve(sourcesListFilePath));
        }

        @Override
        public String getShortName() {
            return "javadoc";
        }
    });
    steps.add(new ZipStep(getProjectFilesystem(), output, ImmutableSet.of(), /* junk paths */
    false, DEFAULT_COMPRESSION_LEVEL, uncompressedOutputDir));
    return steps.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ZipStep(com.facebook.buck.zip.ZipStep) ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) ZipStep(com.facebook.buck.zip.ZipStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) ShellStep(com.facebook.buck.shell.ShellStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) RmStep(com.facebook.buck.step.fs.RmStep) ExecutionContext(com.facebook.buck.step.ExecutionContext) ShellStep(com.facebook.buck.shell.ShellStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Aggregations

ShellStep (com.facebook.buck.shell.ShellStep)13 ExecutionContext (com.facebook.buck.step.ExecutionContext)11 Step (com.facebook.buck.step.Step)9 ImmutableList (com.google.common.collect.ImmutableList)9 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 Path (java.nio.file.Path)6 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)5 SourcePath (com.facebook.buck.rules.SourcePath)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Test (org.junit.Test)4 FakeBuildableContext (com.facebook.buck.rules.FakeBuildableContext)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 MkdirStep (com.facebook.buck.step.fs.MkdirStep)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2