use of com.facebook.buck.rules.macros.MacroHandler in project buck by facebook.
the class MacroArgTest method getDeps.
@Test
public void getDeps() throws Exception {
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("loc", new LocationMacroExpander()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
Genrule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("output").build(resolver);
MacroArg arg = new MacroArg(macroHandler, rule.getBuildTarget(), TestCellBuilder.createCellRoots(filesystem), resolver, "$(loc //:rule)");
assertThat(arg.getDeps(ruleFinder), Matchers.contains(rule));
}
use of com.facebook.buck.rules.macros.MacroHandler in project buck by facebook.
the class MacroArgTest method stringify.
@Test
public void stringify() {
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("macro", new StringExpander("expanded")));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
ProjectFilesystem filesystem = new FakeProjectFilesystem();
MacroArg arg = new MacroArg(macroHandler, BuildTargetFactory.newInstance("//:rule"), TestCellBuilder.createCellRoots(filesystem), resolver, "$(macro)");
assertThat(Arg.stringifyList(arg, pathResolver), Matchers.contains("expanded"));
}
use of com.facebook.buck.rules.macros.MacroHandler 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.MacroHandler 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.MacroHandler 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