Example #1
0
  @Override
  protected void preloadOrThrow(QueryExpression caller, Collection<String> patterns)
      throws QueryException, TargetParsingException {
    Map<String, SkyKey> keys = new HashMap<>(patterns.size());

    for (String pattern : patterns) {
      try {
        keys.put(
            pattern,
            TargetPatternValue.key(
                pattern, TargetPatternEvaluator.DEFAULT_FILTERING_POLICY, parserPrefix));
      } catch (TargetParsingException e) {
        reportBuildFileError(caller, e.getMessage());
      }
    }
    // Get all the patterns in one batch call
    Map<SkyKey, SkyValue> existingPatterns = graph.getSuccessfulValues(keys.values());

    for (String pattern : patterns) {
      SkyKey patternKey = keys.get(pattern);
      if (patternKey == null) {
        // Exception was thrown when creating key above. Skip.
        continue;
      }
      TargetParsingException targetParsingException = null;
      if (existingPatterns.containsKey(patternKey)) {
        // The graph already contains a value or exception for this target pattern, so we use it.
        TargetPatternValue value = (TargetPatternValue) existingPatterns.get(patternKey);
        if (value != null) {
          precomputedPatterns.put(pattern, value.getTargets().getTargets());
        } else {
          // 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.
          targetParsingException =
              (TargetParsingException)
                  Preconditions.checkNotNull(graph.getException(patternKey), pattern);
        }
      }

      if (targetParsingException != null) {
        reportBuildFileError(caller, targetParsingException.getMessage());
      }
    }
  }
Example #2
0
  @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());
      }
    }
  }