Lorenz Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 1 | load("//metropolis/node/build:def.bzl", "FSSpecInfo") |
| 2 | |
| 3 | def _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], |
| 16 | inputs = [fwlist, modinfo] + ctx.files.firmware_files, |
| 17 | tools = [ctx.executable._fwprune], |
| 18 | executable = ctx.executable._fwprune, |
| 19 | arguments = [modinfo.path, fwlist.path, fsspec_out.path], |
| 20 | ) |
| 21 | |
| 22 | return [DefaultInfo(files = depset([fsspec_out])), FSSpecInfo(spec = fsspec_out, referenced = ctx.files.firmware_files)] |
| 23 | |
| 24 | fsspec_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 | ), |
| 39 | "kernel": attr.label( |
| 40 | doc = """ |
| 41 | Kernel for which firmware should be selected. Needs to have a modinfo OutputGroup. |
| 42 | """, |
| 43 | ), |
| 44 | |
| 45 | # Tool |
| 46 | "_fwprune": attr.label( |
| 47 | default = Label("//metropolis/node/build/fwprune"), |
| 48 | executable = True, |
| 49 | cfg = "exec", |
| 50 | ), |
| 51 | }, |
| 52 | ) |