...
1# Copyright 2020 The Bazel Authors. All rights reserved.
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
15def _known_imports_impl(ctx):
16 args = ctx.actions.args()
17 args.add("-proto_csv", ctx.file.src)
18 args.add("-known_imports", ctx.outputs.out)
19 args.add("-package", ctx.attr.package)
20 args.add("-var", ctx.attr.var)
21 args.add("-key", str(ctx.attr.key))
22 args.add("-value", str(ctx.attr.value))
23 ctx.actions.run(
24 executable = ctx.executable._bin,
25 inputs = [ctx.file.src],
26 outputs = [ctx.outputs.out],
27 arguments = [args],
28 mnemonic = "KnownImports",
29 )
30 return [DefaultInfo(files = depset([ctx.outputs.out]))]
31
32known_imports = rule(
33 implementation = _known_imports_impl,
34 attrs = {
35 "src": attr.label(
36 allow_single_file = True,
37 mandatory = True,
38 ),
39 "out": attr.output(mandatory = True),
40 "package": attr.string(mandatory = True),
41 "var": attr.string(mandatory = True),
42 "key": attr.int(mandatory = True),
43 "value": attr.int(mandatory = True),
44 "_bin": attr.label(
45 default = Label("//language/proto/gen:gen_known_imports"),
46 executable = True,
47 cfg = "exec",
48 ),
49 },
50)
View as plain text