use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class GenruleTest method testGenruleWithWorkerMacroUsesSpecialShellStep.
@Test
public void testGenruleWithWorkerMacroUsesSpecialShellStep() throws Exception {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
BuildRule genrule = createGenruleBuilderThatUsesWorkerMacro(ruleResolver).build(ruleResolver);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
List<Step> steps = genrule.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext());
ExecutionContext executionContext = newEmptyExecutionContext(Platform.LINUX);
assertEquals(4, steps.size());
Step step = steps.get(3);
assertTrue(step instanceof WorkerShellStep);
WorkerShellStep workerShellStep = (WorkerShellStep) step;
assertThat(workerShellStep.getShortName(), Matchers.equalTo("worker"));
assertThat(workerShellStep.getEnvironmentVariables(executionContext), Matchers.hasEntry("OUT", filesystem.resolve(filesystem.getBuckPaths().getGenDir()).resolve("genrule_with_worker/output.txt").toString()));
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class GenruleTest method testShouldIncludeAndroidSpecificEnvInEnvironmentIfPresent.
@Test
public void testShouldIncludeAndroidSpecificEnvInEnvironmentIfPresent() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
AndroidPlatformTarget android = EasyMock.createNiceMock(AndroidPlatformTarget.class);
Path sdkDir = Paths.get("/opt/users/android_sdk");
Path ndkDir = Paths.get("/opt/users/android_ndk");
EasyMock.expect(android.getSdkDirectory()).andStubReturn(Optional.of(sdkDir));
EasyMock.expect(android.getNdkDirectory()).andStubReturn(Optional.of(ndkDir));
EasyMock.expect(android.getDxExecutable()).andStubReturn(Paths.get("."));
EasyMock.expect(android.getZipalignExecutable()).andStubReturn(Paths.get("zipalign"));
EasyMock.replay(android);
BuildTarget target = BuildTargetFactory.newInstance("//example:genrule");
Genrule genrule = GenruleBuilder.newGenruleBuilder(target).setBash("echo something > $OUT").setOut("file").build(resolver);
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(android)).build();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
genrule.addEnvironmentVariables(pathResolver, context, builder);
ImmutableMap<String, String> env = builder.build();
assertEquals(Paths.get(".").toString(), env.get("DX"));
assertEquals(Paths.get("zipalign").toString(), env.get("ZIPALIGN"));
assertEquals(sdkDir.toString(), env.get("ANDROID_HOME"));
assertEquals(ndkDir.toString(), env.get("NDK_HOME"));
EasyMock.verify(android);
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class ShellStepTest method testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr.
@Test
public void testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr() throws Exception {
ShellStep command = createCommand(/*shouldPrintStdErr*/
false, /*shouldPrintStdOut*/
false);
ProcessExecutorParams params = createParams();
FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
TestConsole console = new TestConsole(Verbosity.STANDARD_INFORMATION);
ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
command.launchAndInteractWithProcess(context, params);
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class ShellStepTest method createContext.
private static ExecutionContext createContext(ImmutableMap<ProcessExecutorParams, FakeProcess> processes, final Console console) throws IOException {
ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).setProcessExecutor(new FakeProcessExecutor(processes, console)).build();
context.getBuckEventBus().register(new Object() {
@Subscribe
public void logEvent(ConsoleEvent event) throws IOException {
if (event.getLevel().equals(Level.WARNING)) {
console.getStdErr().write(event.getMessage().getBytes(Charsets.UTF_8));
}
}
});
return context;
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class WorkerShellStepTest method testPersistentJobIsExecutedAndResultIsReceived.
@Test
public void testPersistentJobIsExecutedAndResultIsReceived() throws IOException, InterruptedException {
ExecutionContext context = createExecutionContextWith(0, "", "");
WorkerShellStep step = createWorkerShellStep(createJobParams(ImmutableList.of(startupCommand), persistentStartupArgs, ImmutableMap.of(), "myJobArgs", 1, persistentWorkerKey, Hashing.sha1().hashString(fakePersistentWorkerStartupCommand, Charsets.UTF_8)), null, null);
int exitCode = step.execute(context).getExitCode();
assertThat(exitCode, Matchers.equalTo(0));
}
Aggregations