blob: 507532efdf62b2e4b471d4686d274dc84ee6ad10 [file] [log] [blame]
Lorenz Brun17c4c8b2022-02-01 12:59:47 +01001load("//metropolis/node/build:def.bzl", "FSSpecInfo")
2
3def _fsspec_linux_firmware(ctx):
4 fsspec_out = ctx.actions.declare_file(ctx.label.name + ".prototxt")
5
6 fwlist = ctx.actions.declare_file(ctx.label.name + "-fwlist.txt")
7 ctx.actions.write(
8 output = fwlist,
9 content = "\n".join([f.path for f in ctx.files.firmware_files]),
10 )
11
12 modinfo = ctx.attr.kernel[OutputGroupInfo].modinfo.to_list()[0]
13
14 ctx.actions.run(
15 outputs = [fsspec_out],
Lorenz Brund3ce0ac2022-03-03 12:51:21 +010016 inputs = [fwlist, modinfo, ctx.file.metadata] + ctx.files.firmware_files,
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010017 tools = [ctx.executable._fwprune],
18 executable = ctx.executable._fwprune,
Lorenz Brund3ce0ac2022-03-03 12:51:21 +010019 arguments = [modinfo.path, fwlist.path, ctx.file.metadata.path, fsspec_out.path],
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010020 )
21
22 return [DefaultInfo(files = depset([fsspec_out])), FSSpecInfo(spec = fsspec_out, referenced = ctx.files.firmware_files)]
23
24fsspec_linux_firmware = rule(
25 implementation = _fsspec_linux_firmware,
26 doc = """
27 Generates a partial filesystem spec containing all firmware files required by a given kernel at the
28 default firmware load path (/lib/firmware).
29 """,
30 attrs = {
31 "firmware_files": attr.label_list(
32 mandatory = True,
33 allow_files = True,
34 doc = """
35 List of firmware files. Generally at least a filegroup of the linux-firmware repository should
36 be in here.
37 """,
38 ),
Lorenz Brund3ce0ac2022-03-03 12:51:21 +010039 "metadata": attr.label(
40 mandatory = True,
41 allow_single_file = True,
42 doc = """
43 The metadata file for the Linux firmware. Currently this is the WHENCE file at the root of the
44 linux-firmware repository. Used for resolving additional links.
45 """,
46 ),
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010047 "kernel": attr.label(
48 doc = """
49 Kernel for which firmware should be selected. Needs to have a modinfo OutputGroup.
50 """,
51 ),
52
53 # Tool
54 "_fwprune": attr.label(
55 default = Label("//metropolis/node/build/fwprune"),
56 executable = True,
57 cfg = "exec",
58 ),
59 },
60)