kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/bazel_artifact_reader.cc (about)

     1  /*
     2   * Copyright 2020 The Kythe Authors. All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *   http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  #include "kythe/cxx/extractor/bazel_artifact_reader.h"
    17  
    18  #include <optional>
    19  #include <utility>
    20  #include <vector>
    21  
    22  #include "kythe/cxx/extractor/bazel_artifact.h"
    23  #include "kythe/cxx/extractor/bazel_artifact_selector.h"
    24  
    25  namespace kythe {
    26  
    27  void BazelArtifactReader::Next() {
    28    if (event_reader_->Done()) return;
    29    event_reader_->Next();
    30    Select();
    31  }
    32  
    33  void BazelArtifactReader::Select() {
    34    for (; !event_reader_->Done(); event_reader_->Next()) {
    35      const auto& event = event_reader_->Ref();
    36      for (auto& selector : selectors_) {
    37        if (std::optional<BazelArtifact> artifact = selector.Select(event)) {
    38          value_ = *std::move(artifact);
    39          return;
    40        }
    41      }
    42    }
    43    // Both we and the underlying reader are done; propagate the status.
    44    value_ = event_reader_->status();
    45  }
    46  
    47  /* static */
    48  std::vector<AnyArtifactSelector> BazelArtifactReader::DefaultSelectors() {
    49    return {ExtraActionSelector{}};
    50  }
    51  }  // namespace kythe