| // Copyright 2025 Google Inc. All Rights Reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #ifndef NINJA_RESULTSTORE_STREAMER_H_ |
| #define NINJA_RESULTSTORE_STREAMER_H_ |
| |
| #include <map> |
| #include <memory> |
| #include <string> |
| #include <vector> |
| |
| #include "bes_types.h" |
| #include "status.h" |
| |
| struct OutputStream; |
| |
| namespace rs { |
| namespace google { |
| namespace devtools { |
| namespace resultstore { |
| namespace v2 { |
| struct Invocation; |
| struct UploadRequest; |
| } // namespace v2 |
| } // namespace resultstore |
| } // namespace devtools |
| } // namespace google |
| } // namespace rs |
| |
| /// Writes ResultStore Protocol messages that contain |
| /// to results and timing information. |
| class ResultStoreStreamer : public Status { |
| public: |
| /// ninja_command: the full command used to invoke ninja |
| /// config_string: text representation of ninja configuration |
| /// metadata: user-defined metadata string values |
| /// build_id: (optional) a build identifier string, can be empty. |
| /// start_time_millis: start time of build in ms. |
| /// out: output stream to write build events (unbuffered). |
| ResultStoreStreamer(const std::vector<std::string>& ninja_command, |
| const std::string& config_string, |
| const BuildMetadataMap& metadata, |
| const std::string& build_id, int64_t start_time_millis, |
| OutputStream* out); |
| virtual ~ResultStoreStreamer(); |
| |
| void EdgeAddedToPlan(const Edge* edge) override; |
| void EdgeRemovedFromPlan(const Edge* edge) override; |
| void BuildEdgeStarted(const Edge* edge, int64_t start_time_millis) override; |
| void BuildEdgeFinished(Edge* edge, int64_t start_time_millis, |
| int64_t end_time_millis, ExitStatus exit_code, |
| const std::string& output) override; |
| void BuildStarted() override; |
| void BuildFinished(ExitStatus exit_status) override; |
| |
| void SetExplanations(Explanations*) override; |
| |
| void InfoV(const char* msg, va_list) override; |
| void WarningV(const char* msg, va_list) override; |
| void ErrorV(const char* msg, va_list) override; |
| |
| // disallow copy, but allow move |
| ResultStoreStreamer(const ResultStoreStreamer&) = delete; |
| ResultStoreStreamer(ResultStoreStreamer&&) = default; |
| ResultStoreStreamer& operator=(const ResultStoreStreamer&) = delete; |
| ResultStoreStreamer& operator=(ResultStoreStreamer&&) = default; |
| |
| private: |
| |
| // Invocation ID (build_id) |
| const std::string& invocation_id() const; |
| |
| typedef ::rs::google::devtools::resultstore::v2::UploadRequest UploadRequest; |
| void PostRequest(const UploadRequest&); |
| |
| private: |
| /// Original ninja invocation command. |
| std::vector<std::string> ninja_command_; |
| |
| /// BuildConfig string. |
| std::string config_string_; |
| |
| /// Generic metadata for publishing builds. |
| BuildMetadataMap metadata_; |
| |
| /// Start time of ninja invocation. |
| int64_t start_time_millis_ = 0; |
| |
| typedef ::rs::google::devtools::resultstore::v2::Invocation Invocation; |
| /// Initial invocation parameters. |
| std::unique_ptr<Invocation> initial_invocation_; |
| |
| // Output stream (should be configured un-buffered) |
| // Not owned, so the stream object should outlive this object. |
| OutputStream* out_ = nullptr; |
| }; |
| |
| #endif // NINJA_RESULTSTORE_STREAMER_H_ |