use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class CxxPlatforms method getHostFlavor.
public static Flavor getHostFlavor() {
String platformName = Platform.detect().getAutoconfName();
Flavor hostFlavor = getHostFlavorMap().get(platformName);
if (hostFlavor == null) {
throw new HumanReadableException("Unable to determine the host platform.");
}
return hostFlavor;
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class CxxTestDescription method findDepsForTargetFromConstructorArgs.
@Override
public Iterable<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, Arg constructorArg) {
ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
// Get any parse time deps from the C/C++ platforms.
deps.addAll(CxxPlatforms.getParseTimeDeps(cxxPlatforms.getValue(buildTarget.getFlavors()).orElse(defaultCxxPlatform)));
// Extract parse time deps from flags, args, and environment parameters.
Iterable<Iterable<String>> macroStrings = ImmutableList.<Iterable<String>>builder().add(constructorArg.args).add(constructorArg.env.values()).build();
for (String macroString : Iterables.concat(macroStrings)) {
try {
deps.addAll(CxxDescriptionEnhancer.MACRO_HANDLER.extractParseTimeDeps(buildTarget, cellRoots, macroString));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s: %s", buildTarget, e.getMessage());
}
}
CxxTestType type = constructorArg.framework.orElse(getDefaultTestType());
switch(type) {
case GTEST:
{
cxxBuckConfig.getGtestDep().ifPresent(deps::add);
if (constructorArg.useDefaultTestMain.orElse(true)) {
cxxBuckConfig.getGtestDefaultTestMainDep().ifPresent(deps::add);
}
break;
}
case BOOST:
{
cxxBuckConfig.getBoostTestDep().ifPresent(deps::add);
break;
}
default:
{
break;
}
}
constructorArg.depsQuery.ifPresent(depsQuery -> QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery).forEach(deps::add));
return deps.build();
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class PrebuiltCxxLibraryDescription method createSharedLibraryInterface.
private <A extends Arg> BuildRule createSharedLibraryInterface(BuildTarget baseTarget, BuildRuleParams baseParams, BuildRuleResolver resolver, CxxPlatform cxxPlatform, Optional<String> versionSubdir, A args) throws NoSuchBuildTargetException {
if (!args.supportsSharedLibraryInterface) {
throw new HumanReadableException("%s: rule does not support shared library interfaces", baseTarget, cxxPlatform.getFlavor());
}
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());
}
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
SourcePath sharedLibrary = requireSharedLibrary(baseTarget, resolver, pathResolver, baseParams.getCellRoots(), baseParams.getProjectFilesystem(), cxxPlatform, versionSubdir, args);
return factory.get().createSharedInterfaceLibrary(baseTarget.withAppendedFlavors(Type.SHARED_INTERFACE.getFlavor(), cxxPlatform.getFlavor()), baseParams, resolver, pathResolver, ruleFinder, sharedLibrary);
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class PrebuiltCxxLibraryDescription method addDepsFromParam.
private void addDepsFromParam(BuildTarget target, CellPathResolver cellNames, String paramValue, ImmutableSet.Builder<BuildTarget> targets) {
try {
// doesn't matter that the platform expander doesn't do anything.
MacroHandler macroHandler = getMacroHandler(Optional.empty());
// Then get the parse time deps.
targets.addAll(macroHandler.extractParseTimeDeps(target, cellNames, paramValue));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s : %s in \"%s\"", target, e.getMessage(), paramValue);
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class JavacOptionsFactory method create.
public static JavacOptions create(JavacOptions defaultOptions, BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, JvmLibraryArg jvmLibraryArg) {
if ((jvmLibraryArg.source.isPresent() || jvmLibraryArg.target.isPresent()) && jvmLibraryArg.javaVersion.isPresent()) {
throw new HumanReadableException("Please set either source and target or java_version.");
}
JavacOptions.Builder builder = JavacOptions.builder(defaultOptions);
if (jvmLibraryArg.javaVersion.isPresent()) {
builder.setSourceLevel(jvmLibraryArg.javaVersion.get());
builder.setTargetLevel(jvmLibraryArg.javaVersion.get());
}
if (jvmLibraryArg.source.isPresent()) {
builder.setSourceLevel(jvmLibraryArg.source.get());
}
if (jvmLibraryArg.target.isPresent()) {
builder.setTargetLevel(jvmLibraryArg.target.get());
}
if (jvmLibraryArg.generateAbiFromSource.isPresent() && !jvmLibraryArg.generateAbiFromSource.get()) {
// This parameter can only be used to turn off ABI generation from source where it would
// otherwise be employed.
builder.setAbiGenerationMode(AbstractJavacOptions.AbiGenerationMode.CLASS);
}
builder.addAllExtraArguments(jvmLibraryArg.extraArguments);
builder.addAllClassesToRemoveFromJar(jvmLibraryArg.removeClasses);
if (jvmLibraryArg.compiler.isPresent()) {
Either<BuiltInJavac, SourcePath> either = jvmLibraryArg.compiler.get();
if (either.isRight()) {
SourcePath sourcePath = either.getRight();
Optional<BuildRule> possibleRule = ruleFinder.getRule(sourcePath);
if (possibleRule.isPresent() && possibleRule.get() instanceof PrebuiltJar) {
builder.setJavacJarPath(((PrebuiltJar) possibleRule.get()).getSourcePathToOutput());
} else {
builder.setJavacPath(Either.ofRight(sourcePath));
}
}
} else {
if (jvmLibraryArg.javac.isPresent() || jvmLibraryArg.javacJar.isPresent()) {
if (jvmLibraryArg.javac.isPresent() && jvmLibraryArg.javacJar.isPresent()) {
throw new HumanReadableException("Cannot set both javac and javacjar");
}
builder.setJavacPath(jvmLibraryArg.javac.map(Either::ofLeft));
builder.setJavacJarPath(jvmLibraryArg.javacJar);
builder.setCompilerClassName(jvmLibraryArg.compilerClassName);
}
}
AnnotationProcessingParams annotationParams = jvmLibraryArg.buildAnnotationProcessingParams(params.getBuildTarget(), params.getProjectFilesystem(), resolver, defaultOptions.getSafeAnnotationProcessors());
builder.setAnnotationProcessingParams(annotationParams);
return builder.build();
}
Aggregations