Search in sources :

Example 71 with HumanReadableException

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;
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Example 72 with HumanReadableException

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) FluentIterable(com.google.common.collect.FluentIterable) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException)

Example 73 with HumanReadableException

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);
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 74 with HumanReadableException

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);
    }
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) HumanReadableException(com.facebook.buck.util.HumanReadableException) MacroException(com.facebook.buck.model.MacroException)

Example 75 with HumanReadableException

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildRule(com.facebook.buck.rules.BuildRule)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15