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#")));
}
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));
}
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());
}
}
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());
}
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();
}
Aggregations