Damien Martin-Guillerez | ebb0039 | 2015-09-29 11:55:59 +0000 | [diff] [blame] | 1 | // Copyright 2015 The Bazel Authors. All rights reserved. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | syntax = "proto2"; |
| 16 | package blaze.invocation_policy; |
| 17 | |
Joe Finney | dc4dddf | 2017-09-14 20:45:02 +0200 | [diff] [blame] | 18 | // option java_api_version = 2; |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 19 | option java_package = "com.google.devtools.build.lib.runtime.proto"; |
| 20 | |
| 21 | // The --invocation_policy flag takes a base64-encoded binary-serialized or text |
| 22 | // formatted InvocationPolicy message. |
| 23 | message InvocationPolicy { |
ccalvarin | efc9b63 | 2017-05-03 19:05:22 +0200 | [diff] [blame] | 24 | // Order matters. |
| 25 | // After expanding policies on expansion flags or flags with implicit |
| 26 | // requirements, only the final policy on a specific flag will be enforced |
| 27 | // onto the user's command line. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 28 | repeated FlagPolicy flag_policies = 1; |
| 29 | } |
| 30 | |
| 31 | // A policy for controlling the value of a flag. |
| 32 | message FlagPolicy { |
| 33 | // The name of the flag to enforce this policy on. |
| 34 | // |
| 35 | // Note that this should be the full name of the flag, not the abbreviated |
| 36 | // name of the flag. If the user specifies the abbreviated name of a flag, |
| 37 | // that flag will be matched using its full name. |
| 38 | // |
dannark | 8fb8a28 | 2017-09-01 00:41:34 +0200 | [diff] [blame] | 39 | // The "no" prefix will not be parsed, so for boolean flags, use |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 40 | // the flag's full name and explicitly set it to true or false. |
| 41 | optional string flag_name = 1; |
| 42 | |
Janak Ramakrishnan | e9cd0f3 | 2016-04-29 22:46:16 +0000 | [diff] [blame] | 43 | // If set, this flag policy is applied only if one of the given commands or a |
| 44 | // command that inherits from one of the given commands is being run. For |
| 45 | // instance, if "build" is one of the commands here, then this policy will |
| 46 | // apply to any command that inherits from build, such as info, coverage, or |
| 47 | // test. If empty, this flag policy is applied for all commands. This allows |
| 48 | // the policy setter to add all policies to the proto without having to |
| 49 | // determine which Bazel command the user is actually running. Additionally, |
| 50 | // Bazel allows multiple flags to be defined by the same name, and the |
| 51 | // specific flag definition is determined by the command. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 52 | repeated string commands = 2; |
| 53 | |
| 54 | oneof operation { |
| 55 | SetValue set_value = 3; |
| 56 | UseDefault use_default = 4; |
| 57 | DisallowValues disallow_values = 5; |
| 58 | AllowValues allow_values = 6; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | message SetValue { |
| 63 | // Use this value for the specified flag, overriding any default or user-set |
Alex Humesky | 0595007 | 2016-05-09 18:38:55 +0000 | [diff] [blame] | 64 | // value (unless append is set to true for repeatable flags). |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 65 | // |
| 66 | // This field is repeated for repeatable flags. It is an error to set |
| 67 | // multiple values for a flag that is not actually a repeatable flag. |
| 68 | // This requires at least 1 value, if even the empty string. |
| 69 | // |
| 70 | // If the flag allows multiple values, all of its values are replaced with the |
Alex Humesky | 0595007 | 2016-05-09 18:38:55 +0000 | [diff] [blame] | 71 | // value or values from the policy (i.e., no diffing or merging is performed), |
| 72 | // unless the append field (see below) is set to true. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 73 | // |
| 74 | // Note that some flags are tricky. For example, some flags look like boolean |
| 75 | // flags, but are actually Void expansion flags that expand into other flags. |
| 76 | // The Bazel flag parser will accept "--void_flag=false", but because |
| 77 | // the flag is Void, the "=false" is ignored. It can get even trickier, like |
| 78 | // "--novoid_flag" which is also an expansion flag with the type Void whose |
| 79 | // name is explicitly "novoid_flag" and which expands into other flags that |
| 80 | // are the opposite of "--void_flag". For expansion flags, it's best to |
| 81 | // explicitly override the flags they expand into. |
| 82 | // |
| 83 | // Other flags may be differently tricky: A flag could have a converter that |
| 84 | // converts some string to a list of values, but that flag may not itself have |
| 85 | // allowMultiple set to true. |
| 86 | // |
| 87 | // An example is "--test_tag_filters": this flag sets its converter to |
| 88 | // CommaSeparatedOptionListConverter, but does not set allowMultiple to true. |
| 89 | // So "--test_tag_filters=foo,bar" results in ["foo", "bar"], however |
| 90 | // "--test_tag_filters=foo --test_tag_filters=bar" results in just ["bar"] |
| 91 | // since the 2nd value overrides the 1st. |
| 92 | // |
| 93 | // Similarly, "--test_tag_filters=foo,bar --test_tag_filters=baz,qux" results |
| 94 | // in ["baz", "qux"]. For flags like these, the policy should specify |
| 95 | // "foo,bar" instead of separately specifying "foo" and "bar" so that the |
| 96 | // converter is appropriately invoked. |
| 97 | // |
| 98 | // Note that the opposite is not necessarily |
| 99 | // true: for a flag that specifies allowMultiple=true, "--flag=foo,bar" |
| 100 | // may fail to parse or result in an unexpected value. |
| 101 | repeated string flag_value = 1; |
| 102 | |
| 103 | // Whether to allow this policy to be overridden by user-specified values. |
| 104 | // When set, if the user specified a value for this flag, use the value |
| 105 | // from the user, otherwise use the value specified in this policy. |
| 106 | optional bool overridable = 2; |
Alex Humesky | 0595007 | 2016-05-09 18:38:55 +0000 | [diff] [blame] | 107 | |
| 108 | // If true, and if the flag named in the policy is a repeatable flag, then |
| 109 | // the values listed in flag_value do not replace all the user-set or default |
| 110 | // values of the flag, but instead append to them. If the flag is not |
| 111 | // repeatable, then this has no effect. |
| 112 | optional bool append = 3; |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | message UseDefault { |
| 116 | // Use the default value of the flag, as defined by Bazel (or equivalently, do |
| 117 | // not allow the user to set this flag). |
Chloe Calvarin | b63727a | 2017-03-13 14:49:45 +0000 | [diff] [blame] | 118 | // |
| 119 | // Note on implementation: UseDefault sets the default by clearing the flag, |
| 120 | // so that when the value is requested and no flag is found, the flag parser |
| 121 | // returns the default. This is mostly relevant for expansion flags: it will |
| 122 | // erase user values in *all* flags that the expansion flag expands to. Only |
ccalvarin | efc9b63 | 2017-05-03 19:05:22 +0200 | [diff] [blame] | 123 | // use this on expansion flags if this is acceptable behavior. Since the last |
| 124 | // policy wins, later policies on this same flag will still remove the |
| 125 | // expanded UseDefault, so there is a way around, but it's really best not to |
| 126 | // use this on expansion flags at all. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | message DisallowValues { |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 130 | // Obsolete new_default_value field. |
| 131 | reserved 2; |
| 132 | |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 133 | // It is an error for the user to use any of these values (that is, the Bazel |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 134 | // command will fail), unless new_value or use_default is set. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 135 | // |
| 136 | // For repeatable flags, if any one of the values in the flag matches a value |
| 137 | // in the list of disallowed values, an error is thrown. |
| 138 | // |
| 139 | // Care must be taken for flags with complicated converters. For example, |
| 140 | // it's possible for a repeated flag to be of type List<List<T>>, so that |
| 141 | // "--foo=a,b --foo=c,d" results in foo=[["a","b"], ["c", "d"]]. In this case, |
| 142 | // it is not possible to disallow just "b", nor will ["b", "a"] match, nor |
| 143 | // will ["b", "c"] (but ["a", "b"] will still match). |
| 144 | repeated string disallowed_values = 1; |
| 145 | |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 146 | oneof replacement_value { |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 147 | // If set and if the value of the flag is disallowed (including the default |
| 148 | // value of the flag if the user doesn't specify a value), use this value as |
| 149 | // the value of the flag instead of raising an error. This does not apply to |
| 150 | // repeatable flags and is ignored if the flag is a repeatable flag. |
| 151 | string new_value = 3; |
| 152 | |
| 153 | // If set and if the value of the flag is disallowed, use the default value |
| 154 | // of the flag instead of raising an error. Unlike new_value, this works for |
| 155 | // repeatable flags, but note that the default value for repeatable flags is |
| 156 | // always empty. |
| 157 | // |
| 158 | // Note that it is an error to disallow the default value of the flag and |
| 159 | // to set use_default, unless the flag is a repeatable flag where the |
| 160 | // default value is always the empty list. |
| 161 | UseDefault use_default = 4; |
| 162 | } |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | message AllowValues { |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 166 | // Obsolete new_default_value field. |
| 167 | reserved 2; |
| 168 | |
| 169 | // It is an error for the user to use any value not in this list, unless |
| 170 | // new_value or use_default is set. |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 171 | repeated string allowed_values = 1; |
| 172 | |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 173 | oneof replacement_value { |
Alex Humesky | b1f55c8 | 2016-10-25 01:06:39 +0000 | [diff] [blame] | 174 | // If set and if the value of the flag is disallowed (including the default |
| 175 | // value of the flag if the user doesn't specify a value), use this value as |
| 176 | // the value of the flag instead of raising an error. This does not apply to |
| 177 | // repeatable flags and is ignored if the flag is a repeatable flag. |
| 178 | string new_value = 3; |
| 179 | |
| 180 | // If set and if the value of the flag is disallowed, use the default value |
| 181 | // of the flag instead of raising an error. Unlike new_value, this works for |
| 182 | // repeatable flags, but note that the default value for repeatable flags is |
| 183 | // always empty. |
| 184 | // |
| 185 | // Note that it is an error to disallow the default value of the flag and |
| 186 | // to set use_default, unless the flag is a repeatable flag where the |
| 187 | // default value is always the empty list. |
| 188 | UseDefault use_default = 4; |
| 189 | } |
Alex Humesky | 2f3f4cf | 2015-09-29 01:42:00 +0000 | [diff] [blame] | 190 | } |