@Nullable @Override public SkyValue compute(SkyKey key, Environment env) throws SkyFunctionException, InterruptedException { TargetPatternValue.TargetPatternKey patternKey = ((TargetPatternValue.TargetPatternKey) key.argument()); // DepsOfPatternPreparer below expects to be able to ignore the filtering policy from the // TargetPatternKey, which should be valid because PrepareDepsOfPatternValue.keys // unconditionally creates TargetPatternKeys with the NO_FILTER filtering policy. (Compare // with SkyframeTargetPatternEvaluator, which can create TargetPatternKeys with other // filtering policies like FILTER_TESTS or FILTER_MANUAL.) This check makes sure that the // key's filtering policy is NO_FILTER as expected. Preconditions.checkState( patternKey.getPolicy().equals(FilteringPolicies.NO_FILTER), patternKey.getPolicy()); try { TargetPattern parsedPattern = patternKey.getParsedPattern(); DepsOfPatternPreparer preparer = new DepsOfPatternPreparer(env, pkgPath.get()); ImmutableSet<String> excludedSubdirectories = patternKey.getExcludedSubdirectories(); parsedPattern.eval(preparer, excludedSubdirectories); } catch (TargetParsingException e) { throw new PrepareDepsOfPatternFunctionException(e); } catch (MissingDepException e) { // The DepsOfPatternPreparer constructed above might throw MissingDepException to signal // when it has a dependency on a missing Environment value. return null; } return PrepareDepsOfPatternValue.INSTANCE; }
@Override public void getTargetsMatchingPattern( QueryExpression owner, String pattern, Callback<Target> callback) throws QueryException { if (precomputedPatterns.containsKey(pattern)) { Set<Label> labels = precomputedPatterns.get(pattern); if (labels != null) { try { makeTargetsFromLabels(labels, callback); } catch (InterruptedException e) { throw new QueryException(owner, e.getMessage()); } } else { TargetParsingException exception; try { // Because the graph was always initialized via a keep_going build, we know that the // exception stored here must be a TargetParsingException. Thus the comment in // SkyframeTargetPatternEvaluator#parseTargetPatternKeys describing the situation in which // the exception acceptance must be looser does not apply here. exception = (TargetParsingException) Preconditions.checkNotNull( graph.getException( TargetPatternValue.key( pattern, TargetPatternEvaluator.DEFAULT_FILTERING_POLICY, parserPrefix)), pattern); } catch (TargetParsingException e) { exception = e; } reportBuildFileError(owner, exception.getMessage()); } } else { // If the graph doesn't contain a value for this target pattern, try to directly evaluate // it, by making use of packages already present in the graph. try { TargetPatternKey targetPatternKey = ((TargetPatternKey) TargetPatternValue.key( pattern, TargetPatternEvaluator.DEFAULT_FILTERING_POLICY, parserPrefix) .argument()); GraphBackedRecursivePackageProvider provider = new GraphBackedRecursivePackageProvider(graph, universeTargetPatternKeys, pkgPath); ExecutorService threadPool = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat("GetPackages-%d").build()); RecursivePackageProviderBackedTargetPatternResolver resolver = new RecursivePackageProviderBackedTargetPatternResolver( provider, eventHandler, targetPatternKey.getPolicy(), threadPool); TargetPattern parsedPattern = targetPatternKey.getParsedPattern(); FilteringBatchingUniquifyingCallback wrapper = new FilteringBatchingUniquifyingCallback(callback); parsedPattern.eval(resolver, wrapper, QueryException.class); wrapper.processLastPending(); } catch (TargetParsingException e) { reportBuildFileError(owner, e.getMessage()); } catch (InterruptedException e) { throw new QueryException(owner, e.getMessage()); } } }