Search in sources :

Example 76 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class JvmLibraryArg method addProcessors.

void addProcessors(AnnotationProcessingParams.Builder builder, BuildRuleResolver resolver, BuildTarget owner) {
    for (BuildTarget pluginTarget : plugins) {
        BuildRule pluginRule = resolver.getRule(pluginTarget);
        if (!(pluginRule instanceof JavaAnnotationProcessor)) {
            throw new HumanReadableException(String.format("%s: only java_annotation_processor rules can be specified as plugins. " + "%s is not a java_annotation_processor.", owner, pluginTarget));
        }
        JavaAnnotationProcessor plugin = (JavaAnnotationProcessor) pluginRule;
        builder.addProcessor(plugin.getProcessorProperties());
    }
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildRule(com.facebook.buck.rules.BuildRule)

Example 77 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class SourceBasedAbiStubber method newValidatingTaskListener.

public static Object newValidatingTaskListener(ClassLoaderCache classLoaderCache, JavaCompiler.CompilationTask task, BootClasspathOracle bootClasspathOracle, Diagnostic.Kind messageKind) {
    try {
        final ClassLoader pluginClassLoader = PluginLoader.getPluginClassLoader(classLoaderCache, task);
        final Class<?> validatingTaskListenerClass = Class.forName("com.facebook.buck.jvm.java.abi.source.ValidatingTaskListener", false, pluginClassLoader);
        final Constructor<?> constructor = validatingTaskListenerClass.getConstructor(JavaCompiler.CompilationTask.class, BootClasspathOracle.class, Diagnostic.Kind.class);
        return constructor.newInstance(task, bootClasspathOracle, messageKind);
    } catch (ReflectiveOperationException e) {
        throw new HumanReadableException(e, "Could not load source-generated ABI validator. Your compiler might not support this. " + "If it doesn't, you may need to disable source-based ABI generation.");
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) JavaCompiler(javax.tools.JavaCompiler) Diagnostic(javax.tools.Diagnostic)

Example 78 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class PythonTestDescription method createBuildRule.

@Override
public <A extends Arg> PythonTest createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, final A args) throws HumanReadableException, NoSuchBuildTargetException {
    PythonPlatform pythonPlatform = pythonPlatforms.getValue(params.getBuildTarget()).orElse(pythonPlatforms.getValue(args.platform.<Flavor>map(InternalFlavor::of).orElse(pythonPlatforms.getFlavors().iterator().next())));
    CxxPlatform cxxPlatform = cxxPlatforms.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Path baseModule = PythonUtil.getBasePath(params.getBuildTarget(), args.baseModule);
    Optional<ImmutableMap<BuildTarget, Version>> selectedVersions = targetGraph.get(params.getBuildTarget()).getSelectedVersions();
    ImmutableMap<Path, SourcePath> srcs = PythonUtil.getModules(params.getBuildTarget(), resolver, ruleFinder, pathResolver, pythonPlatform, cxxPlatform, "srcs", baseModule, args.srcs, args.platformSrcs, args.versionedSrcs, selectedVersions);
    ImmutableMap<Path, SourcePath> resources = PythonUtil.getModules(params.getBuildTarget(), resolver, ruleFinder, pathResolver, pythonPlatform, cxxPlatform, "resources", baseModule, args.resources, args.platformResources, args.versionedResources, selectedVersions);
    // Convert the passed in module paths into test module names.
    ImmutableSet.Builder<String> testModulesBuilder = ImmutableSet.builder();
    for (Path name : srcs.keySet()) {
        testModulesBuilder.add(PythonUtil.toModuleName(params.getBuildTarget(), name.toString()));
    }
    ImmutableSet<String> testModules = testModulesBuilder.build();
    // Construct a build rule to generate the test modules list source file and
    // add it to the build.
    BuildRule testModulesBuildRule = createTestModulesSourceBuildRule(params, getTestModulesListPath(params.getBuildTarget(), params.getProjectFilesystem()), testModules);
    resolver.addToIndex(testModulesBuildRule);
    String mainModule;
    if (args.mainModule.isPresent()) {
        mainModule = args.mainModule.get();
    } else {
        mainModule = PythonUtil.toModuleName(params.getBuildTarget(), getTestMainName().toString());
    }
    // Build up the list of everything going into the python test.
    PythonPackageComponents testComponents = PythonPackageComponents.of(ImmutableMap.<Path, SourcePath>builder().put(getTestModulesListName(), testModulesBuildRule.getSourcePathToOutput()).put(getTestMainName(), pythonBuckConfig.getPathToTestMain(params.getProjectFilesystem())).putAll(srcs).build(), resources, ImmutableMap.of(), ImmutableSet.of(), args.zipSafe);
    PythonPackageComponents allComponents = PythonUtil.getAllComponents(params, resolver, ruleFinder, testComponents, pythonPlatform, cxxBuckConfig, cxxPlatform, args.linkerFlags.stream().map(MacroArg.toMacroArgFunction(PythonUtil.MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver)::apply).collect(MoreCollectors.toImmutableList()), pythonBuckConfig.getNativeLinkStrategy(), args.preloadDeps);
    // Build the PEX using a python binary rule with the minimum dependencies.
    PythonBinary binary = binaryDescription.createPackageRule(params.withBuildTarget(getBinaryBuildTarget(params.getBuildTarget())), resolver, ruleFinder, pythonPlatform, cxxPlatform, mainModule, args.extension, allComponents, args.buildArgs, args.packageStyle.orElse(pythonBuckConfig.getPackageStyle()), PythonUtil.getPreloadNames(resolver, cxxPlatform, args.preloadDeps));
    resolver.addToIndex(binary);
    ImmutableList.Builder<Pair<Float, ImmutableSet<Path>>> neededCoverageBuilder = ImmutableList.builder();
    for (NeededCoverageSpec coverageSpec : args.neededCoverage) {
        BuildRule buildRule = resolver.getRule(coverageSpec.getBuildTarget());
        if (params.getDeps().contains(buildRule) && buildRule instanceof PythonLibrary) {
            PythonLibrary pythonLibrary = (PythonLibrary) buildRule;
            ImmutableSortedSet<Path> paths;
            if (coverageSpec.getPathName().isPresent()) {
                Path path = coverageSpec.getBuildTarget().getBasePath().resolve(coverageSpec.getPathName().get());
                if (!pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform).getModules().keySet().contains(path)) {
                    throw new HumanReadableException("%s: path %s specified in needed_coverage not found in target %s", params.getBuildTarget(), path, buildRule.getBuildTarget());
                }
                paths = ImmutableSortedSet.of(path);
            } else {
                paths = ImmutableSortedSet.copyOf(pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform).getModules().keySet());
            }
            neededCoverageBuilder.add(new Pair<Float, ImmutableSet<Path>>(coverageSpec.getNeededCoverageRatio(), paths));
        } else {
            throw new HumanReadableException("%s: needed_coverage requires a python library dependency. Found %s instead", params.getBuildTarget(), buildRule);
        }
    }
    Supplier<ImmutableMap<String, String>> testEnv = () -> ImmutableMap.copyOf(Maps.transformValues(args.env, MACRO_HANDLER.getExpander(params.getBuildTarget(), params.getCellRoots(), resolver)));
    // Generate and return the python test rule, which depends on the python binary rule above.
    return PythonTest.from(params, ruleFinder, testEnv, binary, args.labels, neededCoverageBuilder.build(), args.testRuleTimeoutMs.map(Optional::of).orElse(defaultTestRuleTimeoutMs), args.contacts);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) BuildRule(com.facebook.buck.rules.BuildRule) Pair(com.facebook.buck.model.Pair) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) Optional(java.util.Optional) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ImmutableMap(com.google.common.collect.ImmutableMap) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 79 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class CellProvider method createForLocalBuild.

/**
   * Create a cell provider at a given root.
   */
public static CellProvider createForLocalBuild(ProjectFilesystem rootFilesystem, Watchman watchman, BuckConfig rootConfig, CellConfig rootCellConfigOverrides, KnownBuildRuleTypesFactory knownBuildRuleTypesFactory) throws IOException {
    DefaultCellPathResolver rootCellCellPathResolver = new DefaultCellPathResolver(rootFilesystem.getRootPath(), rootConfig.getConfig());
    ImmutableMap<RelativeCellName, Path> transitiveCellPathMapping = rootCellCellPathResolver.getTransitivePathMapping();
    ImmutableMap<Path, RawConfig> pathToConfigOverrides;
    try {
        pathToConfigOverrides = rootCellConfigOverrides.getOverridesByPath(transitiveCellPathMapping);
    } catch (CellConfig.MalformedOverridesException e) {
        throw new HumanReadableException(e.getMessage());
    }
    ImmutableSet<Path> allRoots = ImmutableSet.copyOf(transitiveCellPathMapping.values());
    return new CellProvider(cellProvider -> new CacheLoader<Path, Cell>() {

        @Override
        public Cell load(Path cellPath) throws IOException, InterruptedException {
            Path normalizedCellPath = cellPath.toRealPath().normalize();
            Preconditions.checkState(allRoots.contains(normalizedCellPath), "Cell %s outside of transitive closure of root cell (%s).", normalizedCellPath, allRoots);
            RawConfig configOverrides = Optional.ofNullable(pathToConfigOverrides.get(normalizedCellPath)).orElse(RawConfig.of(ImmutableMap.of()));
            Config config = Configs.createDefaultConfig(normalizedCellPath, configOverrides);
            DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(normalizedCellPath, config);
            cellPathResolver.getCellPaths().forEach((name, path) -> {
                Path pathInRootResolver = rootCellCellPathResolver.getCellPaths().get(name);
                if (pathInRootResolver == null) {
                    throw new HumanReadableException("In the config of %s:  %s.%s must exist in the root cell's cell mappings.", cellPath.toString(), DefaultCellPathResolver.REPOSITORIES_SECTION, name);
                } else if (!pathInRootResolver.equals(path)) {
                    throw new HumanReadableException("In the config of %s:  %s.%s must point to the same directory as the root " + "cell's cell mapping: (root) %s != (current) %s", cellPath.toString(), DefaultCellPathResolver.REPOSITORIES_SECTION, name, pathInRootResolver, path);
                }
            });
            ProjectFilesystem cellFilesystem = new ProjectFilesystem(normalizedCellPath, config);
            BuckConfig buckConfig = new BuckConfig(config, cellFilesystem, rootConfig.getArchitecture(), rootConfig.getPlatform(), rootConfig.getEnvironment(), cellPathResolver);
            return new Cell(cellPathResolver.getKnownRoots(), cellFilesystem, watchman, buckConfig, knownBuildRuleTypesFactory, cellProvider);
        }
    }, cellProvider -> {
        try {
            return new Cell(rootCellCellPathResolver.getKnownRoots(), rootFilesystem, watchman, rootConfig, knownBuildRuleTypesFactory, cellProvider);
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted while loading root cell", e);
        } catch (IOException e) {
            throw new HumanReadableException("Failed to load root cell", e);
        }
    });
}
Also used : Path(java.nio.file.Path) LoadingCache(com.google.common.cache.LoadingCache) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Config(com.facebook.buck.config.Config) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) Configs(com.facebook.buck.config.Configs) HumanReadableException(com.facebook.buck.util.HumanReadableException) Watchman(com.facebook.buck.io.Watchman) Function(java.util.function.Function) RawConfig(com.facebook.buck.config.RawConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) CacheLoader(com.google.common.cache.CacheLoader) ExecutionException(java.util.concurrent.ExecutionException) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) CacheBuilder(com.google.common.cache.CacheBuilder) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) Config(com.facebook.buck.config.Config) RawConfig(com.facebook.buck.config.RawConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) IOException(java.io.IOException) RawConfig(com.facebook.buck.config.RawConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) HumanReadableException(com.facebook.buck.util.HumanReadableException) CellConfig(com.facebook.buck.config.CellConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 80 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class PythonBinaryDescription method createInPlaceBinaryRule.

private PythonInPlaceBinary createInPlaceBinaryRule(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, String mainModule, Optional<String> extension, PythonPackageComponents components, ImmutableSet<String> preloadLibraries) {
    // We don't currently support targeting Windows.
    if (cxxPlatform.getLd().resolve(resolver) instanceof WindowsLinker) {
        throw new HumanReadableException("%s: cannot build in-place python binaries for Windows (%s)", params.getBuildTarget(), cxxPlatform.getFlavor());
    }
    // Add in any missing init modules into the python components.
    SourcePath emptyInit = createEmptyInitModule(params, resolver);
    components = components.withModules(addMissingInitModules(components.getModules(), emptyInit));
    BuildTarget linkTreeTarget = params.getBuildTarget().withAppendedFlavors(InternalFlavor.of("link-tree"));
    Path linkTreeRoot = BuildTargets.getGenPath(params.getProjectFilesystem(), linkTreeTarget, "%s");
    SymlinkTree linkTree = resolver.addToIndex(new SymlinkTree(linkTreeTarget, params.getProjectFilesystem(), linkTreeRoot, ImmutableMap.<Path, SourcePath>builder().putAll(components.getModules()).putAll(components.getResources()).putAll(components.getNativeLibraries()).build(), ruleFinder));
    return PythonInPlaceBinary.from(params, resolver, cxxPlatform, pythonPlatform, mainModule, components, extension.orElse(pythonBuckConfig.getPexExtension()), preloadLibraries, pythonBuckConfig.legacyOutputPath(), ruleFinder, linkTree, pythonPlatform.getEnvironment());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SymlinkTree(com.facebook.buck.rules.SymlinkTree) WindowsLinker(com.facebook.buck.cxx.WindowsLinker) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget)

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