blob: 5903754b976ff61202905b22bc0144b9fe09e90e [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(
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010019 "@io_bazel_rules_go//go:def.bzl",
20 "GoLibrary",
21 "go_context",
22 "go_library",
23)
24
25def _bindata_impl(ctx):
26 out = ctx.actions.declare_file("bindata.go")
27
28 arguments = ctx.actions.args()
29 arguments.add_all([
30 "-pkg",
31 ctx.attr.package,
32 "-prefix",
Lorenz Brunf8574872020-07-28 17:12:04 +020033 ctx.label.workspace_root,
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010034 "-o",
35 out,
36 ])
37 arguments.add_all(ctx.files.srcs)
38
39 ctx.actions.run(
40 inputs = ctx.files.srcs,
41 outputs = [out],
42 executable = ctx.file.bindata,
43 arguments = [arguments],
44 )
45
46 go = go_context(ctx)
47
48 source_files = [out]
49
50 library = go.new_library(
51 go,
52 srcs = source_files,
53 )
54 source = go.library_to_source(go, None, library, False)
55 providers = [library, source]
56 output_groups = {
57 "go_generated_srcs": source_files,
58 }
59
60 return providers + [OutputGroupInfo(**output_groups)]
61
Serge Bazanskif12bedf2021-01-15 16:58:50 +010062bindata = rule(
63 implementation = _bindata_impl,
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010064 attrs = {
Serge Bazanskif12bedf2021-01-15 16:58:50 +010065 "srcs": attr.label_list(
66 mandatory = True,
67 allow_files = True,
68 ),
69 "package": attr.string(
70 mandatory = True,
71 ),
72 "bindata": attr.label(
73 allow_single_file = True,
74 default = Label("@com_github_kevinburke_go_bindata//go-bindata"),
75 ),
76 "_go_context_data": attr.label(
77 default = "@io_bazel_rules_go//:go_context_data",
78 ),
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010079 },
Serge Bazanskif12bedf2021-01-15 16:58:50 +010080 toolchains = ["@io_bazel_rules_go//go:toolchain"],
Hendrik Hofstadt4b0e5c02019-11-07 20:21:24 +010081)