| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 1 | load("//osbase/build/fsspec:def.bzl", "FSSpecInfo", "fsspec_core_impl") |
| 2 | |
| 3 | def _erofs_image_impl(ctx): |
| 4 | fs_name = ctx.label.name + ".img" |
| 5 | fs_out = ctx.actions.declare_file(fs_name) |
| 6 | |
| 7 | fsspec_core_impl(ctx, ctx.executable._mkerofs, fs_out) |
| 8 | |
| 9 | return [DefaultInfo(files = depset([fs_out]))] |
| 10 | |
| 11 | erofs_image = rule( |
| 12 | implementation = _erofs_image_impl, |
| 13 | doc = """ |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 14 | Build an EROFS. All files specified in files and all specified symlinks will be contained. |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 15 | Executable files will have their permissions set to 0555, non-executable files will have |
| 16 | their permissions set to 0444. All parent directories will be created with 0555 permissions. |
| 17 | """, |
| 18 | attrs = { |
| 19 | "files": attr.string_keyed_label_dict( |
| 20 | mandatory = True, |
| 21 | allow_files = True, |
| 22 | doc = """ |
| 23 | Dictionary of Labels to String, placing a given Label's output file in the EROFS at the location |
| 24 | specified by the String value. The specified labels must only have a single output. |
| 25 | """, |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 26 | ), |
| 27 | "symlinks": attr.string_dict( |
| 28 | default = {}, |
| 29 | doc = """ |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 30 | Symbolic links to create. Similar format as in `files`, so the key is the location of the |
| Tim Windelschmidt | ad4d954 | 2025-03-24 20:20:13 +0100 | [diff] [blame] | 31 | symlink itself and the value of it is target of the symlink. Only raw strings are allowed as targets, |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 32 | labels are not permitted. Include the file using `files`, then symlink to its location. |
| Tim Windelschmidt | ad4d954 | 2025-03-24 20:20:13 +0100 | [diff] [blame] | 33 | """, |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 34 | ), |
| 35 | "fsspecs": attr.label_list( |
| 36 | default = [], |
| 37 | doc = """ |
| 38 | List of file system specs (osbase.build.fsspec.FSSpec) to also include in the resulting image. |
| 39 | These will be merged with all other given attributes. |
| 40 | """, |
| 41 | providers = [FSSpecInfo], |
| 42 | allow_files = True, |
| 43 | ), |
| 44 | |
| 45 | # Tools, implicit dependencies. |
| 46 | "_mkerofs": attr.label( |
| 47 | default = Label("//osbase/build/mkerofs"), |
| 48 | executable = True, |
| 49 | cfg = "exec", |
| 50 | ), |
| 51 | }, |
| 52 | ) |