Search in sources :

Example 1 with BatchCallback

use of com.google.devtools.build.lib.util.BatchCallback in project bazel by bazelbuild.

the class TargetPatternFunction method compute.

@Override
public SkyValue compute(SkyKey key, Environment env) throws TargetPatternFunctionException, InterruptedException {
    TargetPatternValue.TargetPatternKey patternKey = ((TargetPatternValue.TargetPatternKey) key.argument());
    ResolvedTargets<Target> resolvedTargets;
    try {
        EnvironmentBackedRecursivePackageProvider provider = new EnvironmentBackedRecursivePackageProvider(env);
        RecursivePackageProviderBackedTargetPatternResolver resolver = new RecursivePackageProviderBackedTargetPatternResolver(provider, env.getListener(), patternKey.getPolicy(), MultisetSemaphore.<PackageIdentifier>unbounded());
        TargetPattern parsedPattern = patternKey.getParsedPattern();
        ImmutableSet<PathFragment> excludedSubdirectories = patternKey.getExcludedSubdirectories();
        final Set<Target> results = CompactHashSet.create();
        BatchCallback<Target, RuntimeException> callback = new BatchCallback<Target, RuntimeException>() {

            @Override
            public void process(Iterable<Target> partialResult) {
                Iterables.addAll(results, partialResult);
            }
        };
        parsedPattern.eval(resolver, excludedSubdirectories, callback, RuntimeException.class);
        resolvedTargets = ResolvedTargets.<Target>builder().addAll(results).build();
    } catch (TargetParsingException e) {
        throw new TargetPatternFunctionException(e);
    } catch (MissingDepException e) {
        // implementations that are unconcerned with MissingDepExceptions.
        return null;
    }
    Preconditions.checkNotNull(resolvedTargets, key);
    ResolvedTargets.Builder<Label> resolvedLabelsBuilder = ResolvedTargets.builder();
    for (Target target : resolvedTargets.getTargets()) {
        resolvedLabelsBuilder.add(target.getLabel());
    }
    for (Target target : resolvedTargets.getFilteredTargets()) {
        resolvedLabelsBuilder.remove(target.getLabel());
    }
    return new TargetPatternValue(resolvedLabelsBuilder.build());
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Label(com.google.devtools.build.lib.cmdline.Label) Target(com.google.devtools.build.lib.packages.Target) TargetPattern(com.google.devtools.build.lib.cmdline.TargetPattern) TargetParsingException(com.google.devtools.build.lib.cmdline.TargetParsingException) ResolvedTargets(com.google.devtools.build.lib.cmdline.ResolvedTargets) BatchCallback(com.google.devtools.build.lib.util.BatchCallback) MissingDepException(com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException)

Aggregations

Label (com.google.devtools.build.lib.cmdline.Label)1 ResolvedTargets (com.google.devtools.build.lib.cmdline.ResolvedTargets)1 TargetParsingException (com.google.devtools.build.lib.cmdline.TargetParsingException)1 TargetPattern (com.google.devtools.build.lib.cmdline.TargetPattern)1 Target (com.google.devtools.build.lib.packages.Target)1 MissingDepException (com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException)1 BatchCallback (com.google.devtools.build.lib.util.BatchCallback)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1