blob: 53572ac12011b769aecd62d0fab92c6c24cf45c9 [file] [log] [blame]
Damien Martin-Guillerezebb00392015-09-29 11:55:59 +00001// Copyright 2015 The Bazel Authors. All rights reserved.
Alex Humesky2f3f4cf2015-09-29 01:42:00 +00002//
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
15syntax = "proto2";
16package blaze.invocation_policy;
17
Joe Finneydc4dddf2017-09-14 20:45:02 +020018// option java_api_version = 2;
Alex Humesky2f3f4cf2015-09-29 01:42:00 +000019option 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.
23message InvocationPolicy {
ccalvarinefc9b632017-05-03 19:05:22 +020024 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +000028 repeated FlagPolicy flag_policies = 1;
29}
30
31// A policy for controlling the value of a flag.
32message 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 //
dannark8fb8a282017-09-01 00:41:34 +020039 // The "no" prefix will not be parsed, so for boolean flags, use
Alex Humesky2f3f4cf2015-09-29 01:42:00 +000040 // the flag's full name and explicitly set it to true or false.
41 optional string flag_name = 1;
42
Janak Ramakrishnane9cd0f32016-04-29 22:46:16 +000043 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +000052 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
62message SetValue {
63 // Use this value for the specified flag, overriding any default or user-set
Alex Humesky05950072016-05-09 18:38:55 +000064 // value (unless append is set to true for repeatable flags).
Alex Humesky2f3f4cf2015-09-29 01:42:00 +000065 //
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 Humesky05950072016-05-09 18:38:55 +000071 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +000073 //
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 Humesky05950072016-05-09 18:38:55 +0000107
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 Humesky2f3f4cf2015-09-29 01:42:00 +0000113}
114
115message 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 Calvarinb63727a2017-03-13 14:49:45 +0000118 //
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
ccalvarinefc9b632017-05-03 19:05:22 +0200123 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +0000127}
128
129message DisallowValues {
Alex Humeskyb1f55c82016-10-25 01:06:39 +0000130 // Obsolete new_default_value field.
131 reserved 2;
132
Alex Humesky2f3f4cf2015-09-29 01:42:00 +0000133 // It is an error for the user to use any of these values (that is, the Bazel
Alex Humeskyb1f55c82016-10-25 01:06:39 +0000134 // command will fail), unless new_value or use_default is set.
Alex Humesky2f3f4cf2015-09-29 01:42:00 +0000135 //
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 Humeskyb1f55c82016-10-25 01:06:39 +0000146 oneof replacement_value {
Alex Humeskyb1f55c82016-10-25 01:06:39 +0000147 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +0000163}
164
165message AllowValues {
Alex Humeskyb1f55c82016-10-25 01:06:39 +0000166 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +0000171 repeated string allowed_values = 1;
172
Alex Humeskyb1f55c82016-10-25 01:06:39 +0000173 oneof replacement_value {
Alex Humeskyb1f55c82016-10-25 01:06:39 +0000174 // 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 Humesky2f3f4cf2015-09-29 01:42:00 +0000190}