blob: 65997f66bbb8fbf7fa39efee776ef9a9c7b2c3bf [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",
20 _go_rule = "go_rule",
21)
22load(
23 "@bazel_skylib//lib:shell.bzl",
24 "shell",
25)
26
27def _fietsje_runner_impl(ctx):
28 go = _go_context(ctx)
29 out_file = ctx.actions.declare_file(ctx.label.name + ".bash")
30 substitutions = {
31 "@@GOTOOL@@": shell.quote(go.go.path),
32 "@@FIETSJE_SHORT_PATH@@": shell.quote(ctx.executable.fietsje.short_path),
33 }
34 ctx.actions.expand_template(
35 template = ctx.file._template,
36 output = out_file,
37 substitutions = substitutions,
38 is_executable = True,
39 )
40 runfiles = ctx.runfiles(files = [
41 ctx.executable.fietsje,
42 go.go,
43 ])
44 return [DefaultInfo(
45 files = depset([out_file]),
46 runfiles = runfiles,
47 executable = out_file,
48 )]
49
50_fietsje_runner = _go_rule(
51 implementation = _fietsje_runner_impl,
52 attrs = {
53 "fietsje": attr.label(
54 default = "//build/fietsje",
55 executable = True,
56 cfg = 'host',
57 ),
58 "_template": attr.label(
59 default = "//build/fietsje:fietsje.bash.in",
60 allow_single_file = True,
61 ),
62 },
63)
64
65def fietsje(name):
66 runner_name = name + "-runner"
67 _fietsje_runner(
68 name = runner_name,
69 )
70 native.sh_binary(
71 name = name,
72 srcs = [runner_name],
73 )