// Copyright 2014 The Bazel Authors. 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.

syntax = "proto2";

package skydoc;

// internal options

message Attribute {
  // Indicates the type of attribute.
  enum Discriminator {
    INTEGER = 1;             // int_value
    STRING = 2;              // string_value
    LABEL = 3;               // string_value
    OUTPUT = 4;              // string_value
    STRING_LIST = 5;         // string_list_value
    LABEL_LIST = 6;          // string_list_value
    OUTPUT_LIST = 7;         // string_list_value
    DISTRIBUTION_SET = 8;    // string_list_value - order is unimportant
    LICENSE = 9;             // license
    STRING_DICT = 10;        // string_dict_value
    FILESET_ENTRY_LIST = 11; // fileset_list_value
    LABEL_LIST_DICT = 12;    // label_list_dict_value
    STRING_LIST_DICT = 13;   // string_list_dict_value
    BOOLEAN = 14;            // int, bool and string value
    TRISTATE = 15;           // tristate, int and string value
    INTEGER_LIST = 16;       // int_list_value
    UNKNOWN = 18;            // unknown type, use only for build extensions
    LABEL_DICT_UNARY = 19;   // label_dict_unary_value
    SELECTOR_LIST = 20;      // selector_list
    NAME = 21;               // name, use only for the name attribute
    LABEL_KEYED_STRING_DICT = 22; // label_keyed_string_dict

    // Deprecated.
    DEPRECATED_STRING_DICT_UNARY = 17;
  }
}

// Information about allowed rule classes for a specific attribute of a rule.
message AllowedRuleClassInfo {
  enum AllowedRuleClasses {
    ANY = 1;  // Any rule is allowed to be in this attribute
    SPECIFIED = 2;  // Only the explicitly listed rules are allowed
  }

  required AllowedRuleClasses policy = 1;

  // Rule class names of rules allowed in this attribute, e.g "cc_library",
  // "py_binary". Only present if the allowed_rule_classes field is set to
  // SPECIFIED.
  repeated string allowed_rule_class = 2;
}

// Information about an output target for a rule.
message OutputTarget {
  // The template name of the output target (e.g. %{name}.jar.
  optional string template = 1;
  // The documentation for the output target.
  optional string documentation = 2;
}

// This message represents a single attribute of a single rule.
message AttributeDefinition {
  // Rule name, e.g. "cc_library"
  required string name = 1;
  required Attribute.Discriminator type = 2;
  required bool mandatory = 3;

  // Only present for attributes of type LABEL and LABEL_LIST.
  optional AllowedRuleClassInfo allowed_rule_classes = 4;
  // The documentation for the attribute.
  optional string documentation = 5;
  // The string representation of the default value of the attribute.
  optional string default = 6;
}

message RuleDefinition {
  required string name = 1;
  // Only contains documented attributes
  repeated AttributeDefinition attribute = 2;
  // The documentation for the rule.
  optional string documentation = 3;
  // Documentation illustrating example usages of the rule.
  optional string example_documentation = 4;

  // The list of outputs for this rule.
  repeated OutputTarget output = 5;

  enum Type {
    RULE = 1;
    MACRO = 2;
    REPOSITORY_RULE = 3;
  }
  optional Type type = 6;
}

message BuildLanguage {
  // Only contains documented rule definitions
  repeated RuleDefinition rule = 1;
}
