blob: 8b48ecf97b2504a3a5c7943fd6d6472a18fc5662 [file]
// 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_BUILD_EVENT_STREAMER_H_
#define NINJA_BUILD_EVENT_STREAMER_H_
#include <map>
#include <string>
#include "bes_types.h"
#include "status.h"
struct OutputStream;
/// Writes Build Event Protocol messages in response
/// to build events.
class BuildEventStreamer : 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).
BuildEventStreamer(const char* ninja_command,
const std::string& config_string,
const BuildMetadataMap& metadata,
const std::string& build_id, int64_t start_time_millis,
OutputStream* out);
virtual ~BuildEventStreamer();
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
BuildEventStreamer(const BuildEventStreamer&) = delete;
BuildEventStreamer(BuildEventStreamer&&) = default;
BuildEventStreamer& operator=(const BuildEventStreamer&) = delete;
BuildEventStreamer& operator=(BuildEventStreamer&&) = default;
private:
const char* ninja_command_;
std::string config_string_;
BuildMetadataMap metadata_;
std::string build_id_;
int64_t start_time_millis_;
// Output stream (should be configured un-buffered)
// Not owned, so the stream object should outlive this object.
OutputStream* out_ = nullptr;
};
#endif // NINJA_BUILD_EVENT_STREAMER_H_