Serge Bazanski | f369cfa | 2020-05-22 18:36:42 +0200 | [diff] [blame] | 1 | # 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 | |
| 17 | load( |
| 18 | "@io_bazel_rules_go//go:def.bzl", |
| 19 | _go_context = "go_context", |
Serge Bazanski | f369cfa | 2020-05-22 18:36:42 +0200 | [diff] [blame] | 20 | ) |
| 21 | load( |
| 22 | "@bazel_skylib//lib:shell.bzl", |
| 23 | "shell", |
| 24 | ) |
| 25 | |
| 26 | def _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 Bazanski | f12bedf | 2021-01-15 16:58:50 +0100 | [diff] [blame] | 49 | _fietsje_runner = rule( |
Serge Bazanski | f369cfa | 2020-05-22 18:36:42 +0200 | [diff] [blame] | 50 | 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 Bazanski | f12bedf | 2021-01-15 16:58:50 +0100 | [diff] [blame] | 61 | "_go_context_data": attr.label( |
| 62 | default = "@io_bazel_rules_go//:go_context_data", |
| 63 | ), |
Serge Bazanski | f369cfa | 2020-05-22 18:36:42 +0200 | [diff] [blame] | 64 | }, |
Serge Bazanski | f12bedf | 2021-01-15 16:58:50 +0100 | [diff] [blame] | 65 | toolchains = ["@io_bazel_rules_go//go:toolchain"], |
Serge Bazanski | f369cfa | 2020-05-22 18:36:42 +0200 | [diff] [blame] | 66 | ) |
| 67 | |
| 68 | def 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 | ) |