use of com.facebook.buck.model.MacroException in project buck by facebook.
the class MavenCoordinatesMacroExpanderTest method testMissingBuildRule.
@Test
public void testMissingBuildRule() throws NoSuchBuildTargetException {
BuildTarget target = BuildTargetFactory.newInstance("//:java");
ProjectFilesystem filesystem = new FakeProjectFilesystem();
MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("maven_coords", expander));
try {
macroHandler.expand(target, createCellRoots(filesystem), resolver, "$(maven_coords //:foo)");
fail("Expected MacroException; Rule does not exist");
} catch (MacroException e) {
assertTrue("Expected MacroException that indicates target does not exist", e.getMessage().contains("no rule //:foo"));
}
}
use of com.facebook.buck.model.MacroException in project buck by facebook.
the class MavenCoordinatesMacroExpanderTest method testHasMavenCoordinatesBuildRuleMissingCoordinates.
@Test
public void testHasMavenCoordinatesBuildRuleMissingCoordinates() throws Exception {
BuildRule rule = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//test:no-mvn")).build(resolver);
try {
expander.getMavenCoordinates(rule);
fail("Expected MacroException; Rule does not contain maven coordinates");
} catch (MacroException e) {
assertTrue("Expected MacroException that indicates target does not have maven coordinates", e.getMessage().contains("does not have maven coordinates"));
}
}
use of com.facebook.buck.model.MacroException in project buck by facebook.
the class PrebuiltCxxLibraryDescription method getBuildRules.
private ImmutableList<BuildRule> getBuildRules(BuildTarget target, CellPathResolver cellNames, BuildRuleResolver ruleResolver, Iterable<String> paramValues) {
ImmutableList.Builder<BuildRule> builder = ImmutableList.builder();
MacroHandler macroHandler = getMacroHandler(Optional.empty());
for (String p : paramValues) {
try {
builder.addAll(macroHandler.extractBuildTimeDeps(target, cellNames, ruleResolver, p));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s : %s in \"%s\"", target, e.getMessage(), p);
}
}
return builder.build();
}
use of com.facebook.buck.model.MacroException in project buck by facebook.
the class WorkerToolDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
BuildRule rule = resolver.requireRule(args.exe);
if (!(rule instanceof BinaryBuildRule)) {
throw new HumanReadableException("The 'exe' argument of %s, %s, needs to correspond to a " + "binary rule, such as sh_binary().", params.getBuildTarget(), args.exe.getFullyQualifiedName());
}
Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver);
final ImmutableList<com.facebook.buck.rules.args.Arg> workerToolArgs = args.getStartupArgs().stream().map(toArg::apply).collect(MoreCollectors.toImmutableList());
ImmutableMap<String, String> expandedEnv = ImmutableMap.copyOf(FluentIterable.from(args.env.entrySet()).transform(input -> {
try {
return Maps.immutableEntry(input.getKey(), MACRO_HANDLER.expand(params.getBuildTarget(), params.getCellRoots(), resolver, input.getValue()));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
}
}));
int maxWorkers;
if (args.maxWorkers.isPresent()) {
// negative or zero: unlimited number of worker processes
maxWorkers = args.maxWorkers.get() < 1 ? Integer.MAX_VALUE : args.maxWorkers.get();
} else {
// default is 1 worker process (for backwards compatibility)
maxWorkers = 1;
}
return new DefaultWorkerTool(params, (BinaryBuildRule) rule, workerToolArgs, expandedEnv, maxWorkers, args.persistent.orElse(buckConfig.getBooleanValue(CONFIG_SECTION, CONFIG_PERSISTENT_KEY, false)));
}
use of com.facebook.buck.model.MacroException in project buck by facebook.
the class OutputToFileExpander method expand.
@Override
public String expand(BuildTarget target, CellPathResolver cellNames, BuildRuleResolver resolver, ImmutableList<String> input) throws MacroException {
try {
String expanded;
if (delegate instanceof MacroExpanderWithCustomFileOutput) {
expanded = ((MacroExpanderWithCustomFileOutput) delegate).expandForFile(target, cellNames, resolver, input);
} else {
expanded = delegate.expand(target, cellNames, resolver, input);
}
Optional<BuildRule> rule = resolver.getRuleOptional(target);
if (!rule.isPresent()) {
throw new MacroException(String.format("no rule %s", target));
}
ProjectFilesystem filesystem = rule.get().getProjectFilesystem();
Path tempFile = createTempFile(filesystem, target, input.get(0));
filesystem.writeContentsToPath(expanded, tempFile);
return "@" + filesystem.resolve(tempFile);
} catch (IOException e) {
throw new MacroException("Unable to create file to hold expanded results", e);
}
}
Aggregations