@@ -8,75 +8,22 @@ visibility([
88 "//third_party/grpc/bazel" ,
99])
1010
11- # Maps flag names to their native reference
12- _FLAGS = {
13- "protocopt" : struct (
14- native = lambda ctx : getattr (ctx .fragments .proto , "experimental_protoc_opts" ),
15- default = [],
16- ),
17- "experimental_proto_descriptor_sets_include_source_info" : struct (
18- native = lambda ctx : getattr (ctx .attr , "_experimental_proto_descriptor_sets_include_source_info_native" )[BuildSettingInfo ].value ,
19- default = False ,
20- ),
21- "proto_compiler" : struct (native = lambda ctx : getattr (ctx .attr , "_proto_compiler_native" )[BuildSettingInfo ].value , default = "@bazel_tools//tools/proto:protoc" ),
22- "strict_proto_deps" : struct (
23- native = lambda ctx : getattr (ctx .attr , "_strict_proto_deps_native" )[BuildSettingInfo ].value ,
24- default = "error" ,
25- ),
26- "strict_public_imports" : struct (
27- native = lambda ctx : getattr (ctx .attr , "_strict_public_imports_native" )[BuildSettingInfo ].value ,
28- default = "off" ,
29- ),
30- "cc_proto_library_header_suffixes" : struct (
31- native = lambda ctx : getattr (ctx .fragments .proto , "cc_proto_library_header_suffixes" ),
32- default = [".pb.h" ],
33- ),
34- "cc_proto_library_source_suffixes" : struct (
35- native = lambda ctx : getattr (ctx .fragments .proto , "cc_proto_library_source_suffixes" ),
36- default = [".pb.cc" ],
37- ),
38- "proto_toolchain_for_java" : struct (
39- native = lambda ctx : "//:java_toolchain" ,
40- default = "//:java_toolchain" ,
41- ),
42- "proto_toolchain_for_javalite" : struct (
43- native = lambda ctx : "//:javalite_toolchain" ,
44- default = "//:javalite_toolchain" ,
45- ),
46- "proto_toolchain_for_cc" : struct (
47- native = lambda ctx : "//:cc_toolchain" ,
48- default = "//:cc_toolchain" ,
49- ),
50- }
51-
5211def get_flag_value (ctx , flag_name ):
53- """Returns the value of the given flag in Starlark if it's set, otherwise reads the Java flag value, if the proto fragment exists .
12+ """Returns the value of the given flag attribute from rule context .
5413
5514 Args:
5615 ctx: The rule context.
5716 flag_name: The name of the flag to get the value for.
5817
5918 Returns:
60- The value of the flag.
19+ The value of the flag. If the value is a list, returns a mutable copy.
6120 """
62-
63- # We probably got here from toolchains.find_toolchain. Leave the attribute alone.
64- if flag_name not in _FLAGS :
65- return getattr (ctx .attr , "_" + flag_name )
66-
67- starlark_flag = getattr (ctx .attr , "_" + flag_name )
68-
69- # Label flags don't have a BuildSettingInfo, just get the value.
70- if "toolchain" in flag_name :
71- starlark_flag_is_set = starlark_flag .label != _FLAGS [flag_name ].default
72- starlark_value = starlark_flag
73- else :
74- starlark_flag_is_set = starlark_flag [BuildSettingInfo ].value != _FLAGS [flag_name ].default
75- starlark_value = starlark_flag [BuildSettingInfo ].value
76-
77- # Starlark flags take precedence over native flags.
78- # Also of course, use the Starlark value if the proto fragment no longer exists.
79- if starlark_flag_is_set or not hasattr (ctx .fragments , "proto" ):
80- return starlark_value
81- else :
82- return _FLAGS [flag_name ].native (ctx )
21+ attr_val = getattr (ctx .attr , "_" + flag_name )
22+ if BuildSettingInfo in attr_val :
23+ val = attr_val [BuildSettingInfo ].value
24+ if type (val ) == "list" :
25+ return list (val )
26+ return val
27+ if type (attr_val ) == "list" :
28+ return list (attr_val )
29+ return attr_val
0 commit comments