blob: f735797a8c3c52243647dc1734d0a42369f9eba0 [file] [log] [blame]
Serge Bazanskif369cfa2020-05-22 18:36:42 +02001# 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(
18 "@io_bazel_rules_go//go:def.bzl",
19 _go_context = "go_context",
Serge Bazanskif369cfa2020-05-22 18:36:42 +020020)
21load(
22 "@bazel_skylib//lib:shell.bzl",
23 "shell",
24)
25
26def _fietsje_runner_impl(ctx):
27 go = _go_context(ctx)
28 out_file = ctx.actions.declare_file(ctx.label.name + ".bash")
29 substitutions = {
30 "@@GOTOOL@@": shell.quote(go.go.path),
31 "@@FIETSJE_SHORT_PATH@@": shell.quote(ctx.executable.fietsje.short_path),
32 }
33 ctx.actions.expand_template(
34 template = ctx.file._template,
35 output = out_file,
36 substitutions = substitutions,
37 is_executable = True,
38 )
39 runfiles = ctx.runfiles(files = [
40 ctx.executable.fietsje,
41 go.go,
42 ])
43 return [DefaultInfo(
44 files = depset([out_file]),
45 runfiles = runfiles,
46 executable = out_file,
47 )]
48
Serge Bazanskif12bedf2021-01-15 16:58:50 +010049_fietsje_runner = rule(
Serge Bazanskif369cfa2020-05-22 18:36:42 +020050 implementation = _fietsje_runner_impl,
51 attrs = {
52 "fietsje": attr.label(
53 default = "//build/fietsje",
54 executable = True,
55 cfg = 'host',
56 ),
57 "_template": attr.label(
58 default = "//build/fietsje:fietsje.bash.in",
59 allow_single_file = True,
60 ),
Serge Bazanskif12bedf2021-01-15 16:58:50 +010061 "_go_context_data": attr.label(
62 default = "@io_bazel_rules_go//:go_context_data",
63 ),
Serge Bazanskif369cfa2020-05-22 18:36:42 +020064 },
Serge Bazanskif12bedf2021-01-15 16:58:50 +010065 toolchains = ["@io_bazel_rules_go//go:toolchain"],
Serge Bazanskif369cfa2020-05-22 18:36:42 +020066)
67
68def fietsje(name):
69 runner_name = name + "-runner"
70 _fietsje_runner(
71 name = runner_name,
72 )
73 native.sh_binary(
74 name = name,
75 srcs = [runner_name],
76 )