// Copyright 2025 The Pigweed Authors
//
// 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
//
//     https://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.
syntax = "proto3";

package pw.build.proto;

import "pw_build/proto/workflows.proto";

message Action {
  // The binary to launch.
  string executable = 1;

  // Arguments to pass to the action.
  repeated string args = 2;

  // Environment variables to populate for this action.
  map<string, string> env = 3;

  enum InvocationLocation {
    // Prefer running from the output directory whenever possible. This
    // minimizes potential for build artifacts leaking out into the source tree.
    OUTPUT_DIRECTORY = 0;
    // Some build actions like GN generation are best run from the root of the
    // project.
    // WARNING: Do not ever use this to generate files into the source tree.
    PROJECT_ROOT = 1;
    // Some build actions like Bazel need to be run from the invoker CWD.
    // WARNING: Do not ever use this to generate files into the source tree.
    INVOKER_CWD = 2;
  }

  InvocationLocation run_from = 4;
}

message JobResponse {
  // The definition of the requested job as a series of actions.
  repeated Action actions = 1;
}

message JobRequest {
  // A job request may be a single tool, or some kind of build.
  oneof type {
    Build build = 1;
    Tool tool = 2;
  }
}

message BuildDriverRequest {
  // A series of JobRequest messages that should be converted into one or more
  // actions.
  repeated JobRequest jobs = 1;
}

message BuildDriverResponse {
  // A series of JobResponse messages that define action sequences for a
  // BuildDriverRequest.
  repeated JobResponse jobs = 1;
}
