treewide: replace template_file rule with expand_template

Less custom rules, more good?

Change-Id: Ie6d3c0c8912ed85058cd8aadfe2e9c7689e01f79
Reviewed-on: https://review.monogon.dev/c/monogon/+/4460
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Tested-by: Jenkins CI
diff --git a/build/utils/template_file.bzl b/build/utils/template_file.bzl
deleted file mode 100644
index 8dc6d24..0000000
--- a/build/utils/template_file.bzl
+++ /dev/null
@@ -1,61 +0,0 @@
-#  Copyright 2020 The Monogon Project Authors.
-#
-#  SPDX-License-Identifier: Apache-2.0
-#
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-
-# Copyright 2018 Josh Pieper, jjp@pobox.com.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-def _dictify(data):
-    result = dict([x.split("=", 1) for x in data])
-    return result
-
-def _template_file_impl(ctx):
-    out = ctx.actions.declare_file(ctx.label.name)
-
-    substitutions = dict(ctx.attr.substitutions)
-    substitutions.update(_dictify(ctx.attr.substitution_list))
-
-    ctx.actions.expand_template(
-        template = ctx.files.src[0],
-        output = out,
-        substitutions = substitutions,
-        is_executable = ctx.attr.is_executable,
-    )
-    return [DefaultInfo(
-        files = depset([out]),
-        data_runfiles = ctx.runfiles(files = [out]),
-    )]
-
-template_file = rule(
-    attrs = {
-        "src": attr.label(allow_files = True),
-        "is_executable": attr.bool(default = False),
-        "substitutions": attr.string_dict(),
-        "substitution_list": attr.string_list(),
-    },
-    output_to_genfiles = True,
-    implementation = _template_file_impl,
-)
diff --git a/third_party/dosfstools/dosfstools.bzl b/third_party/dosfstools/dosfstools.bzl
index e8d966d..9327fbf 100644
--- a/third_party/dosfstools/dosfstools.bzl
+++ b/third_party/dosfstools/dosfstools.bzl
@@ -1,4 +1,4 @@
-load("@@//build/utils:template_file.bzl", "template_file")
+load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
 load("@rules_cc//cc:defs.bzl", "cc_binary")
 
 cc_binary(
@@ -31,9 +31,10 @@
     includes = ["."],
 )
 
-template_file(
-    name = "version.h",
-    src = "src/version.h.in",
+expand_template(
+    name = "version.h_expanded",
+    template = ":src/version.h.in",
+    out = "version.h",
     substitutions = {
         # ONCHANGE(//build/bazel:third_party.MODULE.bazel): version needs to be kept in sync
         "@PACKAGE_VERSION@": "unstable-2022-07-25",
diff --git a/third_party/seccomp/seccomp.bzl b/third_party/seccomp/seccomp.bzl
index 9a010af..7267cbf 100644
--- a/third_party/seccomp/seccomp.bzl
+++ b/third_party/seccomp/seccomp.bzl
@@ -14,7 +14,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-load("@@//build/utils:template_file.bzl", "template_file")
+load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 
 genrule(
@@ -49,9 +49,10 @@
     ],
 )
 
-template_file(
-    name = "seccomp.h",
-    src = "include/seccomp.h.in",
+expand_template(
+    name = "seccomp.h_expanded",
+    template = ":include/seccomp.h.in",
+    out = "seccomp.h",
     substitutions = {
         # Known dependencies relying on this version information:
         # - @com_github_seccomp_libseccomp_golang//:libseccomp-golang
@@ -59,7 +60,6 @@
         "@VERSION_MINOR@": "5",
         "@VERSION_MICRO@": "1",
     },
-    visibility = ["//visibility:public"],
 )
 
 cc_library(
diff --git a/third_party/urcu/urcu.bzl b/third_party/urcu/urcu.bzl
index 351611d..183162f 100644
--- a/third_party/urcu/urcu.bzl
+++ b/third_party/urcu/urcu.bzl
@@ -1,9 +1,10 @@
-load("@@//build/utils:template_file.bzl", "template_file")
+load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 
-template_file(
-    name = "config.h",
-    src = ":config.h.in",
+expand_template(
+    name = "config.h_expanded",
+    template = ":config.h.in",
+    out = "config.h",
     substitutions = {},
 )
 
diff --git a/third_party/util-linux/util-linux.bzl b/third_party/util-linux/util-linux.bzl
index 36e5886..477f872 100644
--- a/third_party/util-linux/util-linux.bzl
+++ b/third_party/util-linux/util-linux.bzl
@@ -14,7 +14,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-load("@@//build/utils:template_file.bzl", "template_file")
+load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
 load("@rules_cc//cc:defs.bzl", "cc_library")
 
 # These are only for the headers of libcommon, which is a private dependency of libblkid and
@@ -59,9 +59,10 @@
     "HAVE___FPENDING",
 ]
 
-template_file(
-    name = "blkid.h",
-    src = "libblkid/src/blkid.h.in",
+expand_template(
+    name = "blkid.h_expanded",
+    template = ":libblkid/src/blkid.h.in",
+    out = "blkid.h",
     substitutions = {
         "@LIBBLKID_VERSION@": "0.0.0",
         "@LIBBLKID_DATE@": "01.01.1970",