use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AuditRulesCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ProjectFilesystem projectFilesystem = params.getCell().getFilesystem();
try (ProjectBuildFileParser parser = params.getCell().createBuildFileParser(new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(params.getObjectMapper())), params.getConsole(), params.getBuckEventBus(), /* ignoreBuckAutodepsFiles */
false)) {
PrintStream out = params.getConsole().getStdOut();
for (String pathToBuildFile : getArguments()) {
if (!json) {
// Print a comment with the path to the build file.
out.printf("# %s\n\n", pathToBuildFile);
}
// Resolve the path specified by the user.
Path path = Paths.get(pathToBuildFile);
if (!path.isAbsolute()) {
Path root = projectFilesystem.getRootPath();
path = root.resolve(path);
}
// Parse the rules from the build file.
List<Map<String, Object>> rawRules;
try {
rawRules = parser.getAll(path);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Format and print the rules from the raw data, filtered by type.
final ImmutableSet<String> types = getTypes();
Predicate<String> includeType = type -> types.isEmpty() || types.contains(type);
printRulesToStdout(params, rawRules, includeType);
}
} catch (BuildFileParseException e) {
throw new HumanReadableException("Unable to create parser");
}
return 0;
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class BuildCommand method showOutputs.
private void showOutputs(CommandRunnerParams params, ActionGraphAndResolver actionGraphAndResolver) {
Optional<DefaultRuleKeyFactory> ruleKeyFactory = Optional.empty();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(actionGraphAndResolver.getResolver());
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
if (showRuleKey) {
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(params.getBuckConfig().getKeySeed());
ruleKeyFactory = Optional.of(new DefaultRuleKeyFactory(fieldLoader, params.getFileHashCache(), pathResolver, ruleFinder));
}
params.getConsole().getStdOut().println("The outputs are:");
for (BuildTarget buildTarget : buildTargets) {
try {
BuildRule rule = actionGraphAndResolver.getResolver().requireRule(buildTarget);
Optional<Path> outputPath = TargetsCommand.getUserFacingOutputPath(pathResolver, rule, showFullOutput, params.getBuckConfig().getBuckOutCompatLink());
params.getConsole().getStdOut().printf("%s%s%s\n", rule.getFullyQualifiedName(), showRuleKey ? " " + ruleKeyFactory.get().build(rule).toString() : "", showOutput || showFullOutput ? " " + outputPath.map(Object::toString).orElse("") : "");
} catch (NoSuchBuildTargetException e) {
throw new HumanReadableException(MoreExceptions.getHumanReadableOrLocalizedMessage(e));
}
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class AbstractCommand method getConfigOverrides.
@Override
public CellConfig getConfigOverrides() {
CellConfig.Builder builder = CellConfig.builder();
// Parse command-line config overrides.
for (Map.Entry<String, String> entry : configOverrides.entrySet()) {
List<String> key = Splitter.on("//").limit(2).splitToList(entry.getKey());
RelativeCellName cellName = CellConfig.ALL_CELLS_OVERRIDE;
String configKey = key.get(0);
if (key.size() == 2) {
// path overrides for cells.
if (key.get(0).length() == 0) {
cellName = RelativeCellName.ROOT_CELL_NAME;
} else {
cellName = RelativeCellName.of(ImmutableSet.of(key.get(0)));
}
configKey = key.get(1);
}
int separatorIndex = configKey.lastIndexOf('.');
if (separatorIndex < 0 || separatorIndex == configKey.length() - 1) {
throw new HumanReadableException("Invalid config override \"%s=%s\" Expected <section>.<field>=<value>.", configKey, entry.getValue());
}
String value = entry.getValue();
// If the value is empty, un-set the config
if (value == null) {
value = "";
}
// Overrides for locations of transitive children of cells are weird as the order of overrides
// can affect the result (for example `-c a/b/c.k=v -c a/b//repositories.c=foo` causes an
// interesting problem as the a/b/c cell gets created as a side-effect of the first override,
// but the second override wants to change its identity).
// It's generally a better idea to use the .buckconfig.local mechanism when overriding
// repositories anyway, so here we simply disallow them.
String section = configKey.substring(0, separatorIndex);
if (section.equals("repositories")) {
throw new HumanReadableException("Overriding repository locations from the command line " + "is not supported. Please place a .buckconfig.local in the appropriate location and " + "use that instead.");
}
String field = configKey.substring(separatorIndex + 1);
builder.put(cellName, section, field, value);
}
if (numThreads != null) {
builder.put(CellConfig.ALL_CELLS_OVERRIDE, "build", "threads", String.valueOf(numThreads));
}
if (noCache) {
builder.put(CellConfig.ALL_CELLS_OVERRIDE, "cache", "mode", "");
}
return builder.build();
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class UnixArchive method getIntFromStringAtRange.
private int getIntFromStringAtRange(int len, CharsetDecoder decoder) {
String filenameLengthString;
int offset = buffer.position();
try {
filenameLengthString = readStringWithLength(buffer, len, decoder);
} catch (CharacterCodingException e) {
throw new HumanReadableException(e, "Unable to read int from buffer (range %d..%d)", offset, offset + len);
}
return Integer.parseInt(filenameLengthString.trim());
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class CxxLibraryDescription method createSharedLibraryInterface.
private static <A extends Arg> BuildRule createSharedLibraryInterface(BuildRuleParams baseParams, BuildRuleResolver resolver, CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
BuildTarget baseTarget = baseParams.getBuildTarget();
Optional<SharedLibraryInterfaceFactory> factory = cxxPlatform.getSharedLibraryInterfaceFactory();
if (!factory.isPresent()) {
throw new HumanReadableException("%s: C/C++ platform %s does not support shared library interfaces", baseTarget, cxxPlatform.getFlavor());
}
CxxLink sharedLibrary = (CxxLink) resolver.requireRule(baseTarget.withAppendedFlavors(cxxPlatform.getFlavor(), Type.SHARED.getFlavor()));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
return factory.get().createSharedInterfaceLibrary(baseTarget.withAppendedFlavors(Type.SHARED_INTERFACE.getFlavor(), cxxPlatform.getFlavor()), baseParams, resolver, pathResolver, ruleFinder, sharedLibrary.getSourcePathToOutput());
}
Aggregations