use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.
the class WorkerMacroArgTest method testWorkerMacroArgWithNoMacros.
@Test
public void testWorkerMacroArgWithNoMacros() throws MacroException, NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
ProjectFilesystem filesystem = new FakeProjectFilesystem();
try {
new WorkerMacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "no macros here");
} catch (MacroException e) {
assertThat(e.getMessage(), Matchers.containsString("Unable to extract any build targets"));
}
}
use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.
the class WorkerMacroArgTest method testWorkerMacroArgWithBadReference.
@Test
public void testWorkerMacroArgWithBadReference() throws MacroException, NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule nonWorkerBuildRule = new FakeBuildRule(BuildTargetFactory.newInstance("//:not_worker_rule"), new SourcePathResolver(new SourcePathRuleFinder(resolver)));
resolver.addToIndex(nonWorkerBuildRule);
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
ProjectFilesystem filesystem = new FakeProjectFilesystem();
try {
new WorkerMacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "$(worker //:not_worker_rule)");
} catch (MacroException e) {
assertThat(e.getMessage(), Matchers.containsString("does not correspond to a worker_tool"));
}
}
use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.
the class WorkerMacroArgTest method testWorkerMacroArgWithMacroInWrongLocation.
@Test
public void testWorkerMacroArgWithMacroInWrongLocation() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
ProjectFilesystem filesystem = new FakeProjectFilesystem();
try {
new WorkerMacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "mkdir && $(worker :worker)");
} catch (MacroException e) {
assertThat(e.getMessage(), Matchers.containsString("must be at the beginning"));
}
}
use of com.facebook.buck.rules.macros.WorkerMacroExpander in project buck by facebook.
the class WorkerMacroArgTest method testWorkerMacroArgConstruction.
@Test
public void testWorkerMacroArgConstruction() throws MacroException, NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
BuildRule shBinaryRule = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe")).setMain(new FakeSourcePath("bin/exe")).build(resolver);
String startupArgs = "startupargs";
Integer maxWorkers = 5;
WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule")).setExe(shBinaryRule.getBuildTarget()).setArgs(startupArgs).setMaxWorkers(maxWorkers).build(resolver);
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
String jobArgs = "jobargs";
WorkerMacroArg arg = new WorkerMacroArg(macroHandler, target, TestCellBuilder.createCellRoots(filesystem), resolver, "$(worker //:worker_rule) " + jobArgs);
assertThat(arg.getJobArgs(), Matchers.equalTo(jobArgs));
assertThat(arg.getStartupArgs(pathResolver), Matchers.equalTo(startupArgs));
assertThat(arg.getMaxWorkers(), Matchers.equalTo(maxWorkers));
}
Aggregations