|
| 1 | +def implement_compile_attributes(lang, self): |
| 2 | + """Add attributes for the X_proto_compile rule""" |
| 3 | + |
| 4 | + name = lang.name |
| 5 | + attrs = self["attrs"] |
| 6 | + |
| 7 | + # Add "gen_java = X" option where X is True if this is the first |
| 8 | + # language specified. |
| 9 | + flag = "gen_" + name |
| 10 | + attrs[flag] = attr.bool( |
| 11 | + default = True, |
| 12 | + ) |
| 13 | + |
| 14 | + # Add a "gen_java_plugin_options=[]". |
| 15 | + opts = flag + "_plugin_options" |
| 16 | + attrs[opts] = attr.string_list() |
| 17 | + |
| 18 | + # If there is a plugin binary, create this label now. |
| 19 | + if hasattr(lang, "protobuf") and hasattr(lang.protobuf, "executable"): |
| 20 | + attrs["gen_protobuf_" + name + "_plugin"] = attr.label( |
| 21 | + default = Label(lang.protobuf.executable), |
| 22 | + cfg = HOST_CFG, |
| 23 | + executable = True, |
| 24 | + ) |
| 25 | + |
| 26 | + # If this language supports gRPC, add this boolean flag in. |
| 27 | + # However, if we didn't load grpc, we don't actually want to |
| 28 | + # generate the label for the executable lest we actually need to |
| 29 | + # have the executable available. TODO: figure out how to write a |
| 30 | + # variable in the loading phase of workspace and read it here. |
| 31 | + |
| 32 | + if hasattr(lang, "grpc"): |
| 33 | + attrs["gen_grpc_" + name] = attr.bool() |
| 34 | + if hasattr(lang.grpc, "executable"): |
| 35 | + attrs["gen_grpc_" + name + "_plugin"] = attr.label( |
| 36 | + default = Label(lang.grpc.executable), |
| 37 | + cfg = HOST_CFG, |
| 38 | + executable = True, |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +def implement_compile_outputs(lang, self): |
| 43 | + """Add customizable outputs for the proto_compile rule""" |
| 44 | + if hasattr(lang, "protobuf") and hasattr(lang.protobuf, "outputs"): |
| 45 | + self["outputs"] += lang.protobuf.outputs |
| 46 | + if hasattr(lang, "grpc") and hasattr(lang.grpc, "outputs"): |
| 47 | + self["outputs"] += lang.grpc.outputs |
| 48 | + |
| 49 | + |
| 50 | +def implement_compile_output_to_genfiles(lang, self): |
| 51 | + self["output_to_genfiles"] = getattr(lang, "output_to_genfiles", self["output_to_genfiles"]) |
| 52 | + |
| 53 | + |
1 | 54 | def get_generated_filename_extensions(lang, self): |
2 | 55 | ctx = self.get("ctx", None) |
3 | 56 | with_grpc = self["with_grpc"] |
@@ -132,59 +185,6 @@ def post_execute(lang, self): |
132 | 185 | pass |
133 | 186 |
|
134 | 187 |
|
135 | | -def implement_compile_attributes(lang, self): |
136 | | - """Add attributes for the X_proto_compile rule""" |
137 | | - |
138 | | - name = lang.name |
139 | | - attrs = self["attrs"] |
140 | | - |
141 | | - # Add "gen_java = X" option where X is True if this is the first |
142 | | - # language specified. |
143 | | - flag = "gen_" + name |
144 | | - attrs[flag] = attr.bool( |
145 | | - default = True, |
146 | | - ) |
147 | | - |
148 | | - # Add a "gen_java_plugin_options=[]". |
149 | | - opts = flag + "_plugin_options" |
150 | | - attrs[opts] = attr.string_list() |
151 | | - |
152 | | - # If there is a plugin binary, create this label now. |
153 | | - if hasattr(lang, "protobuf") and hasattr(lang.protobuf, "executable"): |
154 | | - attrs["gen_protobuf_" + name + "_plugin"] = attr.label( |
155 | | - default = Label(lang.protobuf.executable), |
156 | | - cfg = HOST_CFG, |
157 | | - executable = True, |
158 | | - ) |
159 | | - |
160 | | - # If this language supports gRPC, add this boolean flag in. |
161 | | - # However, if we didn't load grpc, we don't actually want to |
162 | | - # generate the label for the executable lest we actually need to |
163 | | - # have the executable available. TODO: figure out how to write a |
164 | | - # variable in the loading phase of workspace and read it here. |
165 | | - |
166 | | - if hasattr(lang, "grpc"): |
167 | | - attrs["gen_grpc_" + name] = attr.bool() |
168 | | - if hasattr(lang.grpc, "executable"): |
169 | | - attrs["gen_grpc_" + name + "_plugin"] = attr.label( |
170 | | - default = Label(lang.grpc.executable), |
171 | | - cfg = HOST_CFG, |
172 | | - executable = True, |
173 | | - ) |
174 | | - |
175 | | - |
176 | | -def implement_compile_outputs(lang, self): |
177 | | - """Add customizable outputs for the proto_compile rule""" |
178 | | - if hasattr(lang, "protobuf") and hasattr(lang.protobuf, "outputs"): |
179 | | - self["outputs"] += lang.protobuf.outputs |
180 | | - if hasattr(lang, "grpc") and hasattr(lang.grpc, "outputs"): |
181 | | - self["outputs"] += lang.grpc.outputs |
182 | | - |
183 | | - |
184 | | -def implement_compile_output_to_genfiles(lang, self): |
185 | | - self["output_to_genfiles"] = getattr(lang, "output_to_genfiles", self["output_to_genfiles"]) |
186 | | - |
187 | | - |
188 | 188 | CLASS = struct( |
189 | 189 | name = "base", |
190 | 190 |
|
|
0 commit comments