//
// Copyright (C) 2024 The Android Open-Source Project
//
// 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.

syntax = "proto2";
package android.release_config_proto;
option go_package = "android/soong/release_config/release_config_proto";

import "build_flags_src.proto";

// This protobuf file defines messages used to represent the release config for
// the android build system, delivered as a build artifact for use by tools such
// as Gantry.
//
// The following format requirements apply across various message fields:
//
// # name: name of the flag
//
//    format: an uppercase string in SNAKE_CASE format starting with RELEASE_,
//      no consecutive underscores, and no leading digit. For example
//      RELEASE_MY_PACKAGE_FLAG is a valid name, while MY_PACKAGE_FLAG, and
//      RELEASE_MY_PACKAGE__FLAG are invalid.
//
// # package: package to which the flag belongs
//
//    format: lowercase strings in snake_case format, delimited by dots, no
//      consecutive underscores and no leading digit in each string. For example
//      com.android.mypackage is a valid name while com.android.myPackage,
//      com.android.1mypackage are invalid

message Tracepoint {
  // Path to declaration or value file relative to $TOP
  optional string source = 1;
  optional Value value = 201;
}

message FlagArtifact {
  // The original declaration
  optional FlagDeclaration flag_declaration = 1;

  // Value for the flag
  optional Value value = 201;

  // Trace of where the flag value was assigned.
  repeated Tracepoint traces = 8;
}

message FlagArtifacts {
  // The artifacts
  repeated FlagArtifact flags = 1;
  reserved "flag_artifacts";
}

message ReleaseConfigArtifact {
  // The name of the release config.
  // See # name for format detail
  optional string name = 1;

  // Other names by which this release is known (for example, `next`)
  repeated string other_names = 2;

  // The complete set of build flags in this release config, after all
  // inheritance and other processing is complete.
  repeated FlagArtifact flags = 3;
  reserved "flag_artifacts";

  // The (complete) list of aconfig_value_sets Soong modules to use.
  repeated string aconfig_value_sets = 4;

  // The names of the release_config_artifacts from which we inherited.
  // Included for reference only.
  repeated string inherits = 5;

  // The release config directories used for this config.  This includes
  // directories that provide flag declarations, but do not provide any flag
  // values specific to this release config.
  // For example, "build/release".
  repeated string directories = 6;

  // Prior stage(s) for flag advancement (during development).
  // Once a flag has met criteria in a prior stage, it can advance to this one.
  repeated string prior_stages = 7;

  // The release config directories that contribute directly to this release
  // config.  The listed directories contain at least a `release_config` message
  // for this release config.
  repeated string value_directories = 8;

  // The ReleaseConfigType of this release config.
  optional ReleaseConfigType release_config_type = 9;

  // Whether to disallow this release config as TARGET_RELEASE.
  // If true, this release config can only be inherited, it cannot be used
  // directly in a build.
  optional bool disallow_lunch_use = 10;
}

message ReleaseConfigsArtifact {
  // The active release config for this build.
  optional ReleaseConfigArtifact release_config = 1;

  // All other release configs defined for this TARGET_PRODUCT.
  repeated ReleaseConfigArtifact other_release_configs = 2;

  // Map of release_config_artifact.directories to release_config_map message.
  map<string, ReleaseConfigMap> release_config_maps_map = 3;
}
