android_kernel_samsung_sm8650/uapi_unpacker.bzl
John Moon 13a5aa4fac build: Export UAPI headers as Bazel cc_library
There's currently no way for userspace programs building with
Bazel to ingest the kernel UAPI headers. Kleaf generates a tarball
of the headers, but a Bazel cc_binary rule cannot use that as an
input.

Define a native Bazel header-only cc_library which userspace
programs can use to build with the kernel's UAPI headers. For
example:

cc_binary(
    name = "foo",
    srcs = ["foo.c"],
    deps = ["//msm-kernel:kalama_gki_uapi_header_library"],
)

Change-Id: Ib884d9123e4ffd0bead97e8cebb5a3456e73b2a6
Signed-off-by: John Moon <quic_johmoo@quicinc.com>
2022-11-14 16:02:01 -08:00

32 lines
931 B
Python

def _uapi_unpacker_impl(ctx):
input_tar = ctx.file.kernel_uapi_headers
out_dir = ctx.actions.declare_directory(ctx.label.name + "_uapi_headers")
ctx.actions.run_shell(
outputs = [out_dir],
inputs = [input_tar],
arguments = [input_tar.path, out_dir.path],
progress_message = "Unpacking UAPI headers",
command = """
tar_file="${PWD}/$1"
out_dir="${PWD}/$2"
mkdir -p "$out_dir"
cd "$out_dir"
tar --strip-components=2 -xzf "$tar_file"
""",
)
return [DefaultInfo(files = depset([out_dir]))]
uapi_unpacker = rule(
implementation = _uapi_unpacker_impl,
doc = """Unpack `kernel-uapi-headers.tar.gz`""",
attrs = {
"kernel_uapi_headers": attr.label(
allow_single_file = True,
mandatory = True,
doc = "the kernel_uapi_headers tarball or label",
),
},
)