blob: 23293c1f7196c2b3c3d4a93c62e5dc18022d0255 [file] [log] [blame]
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +01001# Copyright 2020 The Monogon Project Authors.
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17load("@bazel_gazelle//:deps.bzl", "go_repository")
18load(
19 "@io_bazel_rules_go//go/private:rules/rule.bzl",
20 "go_rule",
21)
22load(
23 "@io_bazel_rules_go//go:def.bzl",
24 "GoLibrary",
25 "go_context",
26 "go_library",
27)
28
29def _bindata_impl(ctx):
30 out = ctx.actions.declare_file("bindata.go")
31
32 arguments = ctx.actions.args()
33 arguments.add_all([
34 "-pkg",
35 ctx.attr.package,
36 "-prefix",
37 ctx.label.package,
38 "-o",
39 out,
40 ])
41 arguments.add_all(ctx.files.srcs)
42
43 ctx.actions.run(
44 inputs = ctx.files.srcs,
45 outputs = [out],
46 executable = ctx.file.bindata,
47 arguments = [arguments],
48 )
49
50 go = go_context(ctx)
51
52 source_files = [out]
53
54 library = go.new_library(
55 go,
56 srcs = source_files,
57 )
58 source = go.library_to_source(go, None, library, False)
59 providers = [library, source]
60 output_groups = {
61 "go_generated_srcs": source_files,
62 }
63
64 return providers + [OutputGroupInfo(**output_groups)]
65
66bindata = go_rule(
67 _bindata_impl,
68 attrs = {
69 "srcs": attr.label_list(mandatory = True, allow_files = True),
70 "package": attr.string(mandatory = True),
71 "bindata": attr.label(allow_single_file = True, default = Label("@com_github_kevinburke_go_bindata//go-bindata")),
72 },
73)