Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | def _exclude_files_impl(ctx): |
| 6 | out = [] |
| 7 | for src in ctx.files.srcs: |
| 8 | include = True |
| 9 | for suffix in ctx.attr.exclude_suffix: |
| 10 | if src.path.endswith(suffix): |
| 11 | include = False |
| 12 | break |
| 13 | if include: |
| 14 | out.append(src) |
| 15 | return [DefaultInfo(files = depset(out))] |
| 16 | |
| 17 | exclude_files = rule( |
| 18 | implementation = _exclude_files_impl, |
| 19 | attrs = { |
| 20 | "srcs": attr.label_list( |
| 21 | allow_files = True, |
| 22 | mandatory = True, |
| 23 | doc = "Targets producing file outputs", |
| 24 | ), |
| 25 | "exclude_suffix": attr.string_list( |
Chris Frantz | 07ece74 | 2022-07-28 16:08:37 -0700 | [diff] [blame] | 26 | doc = "File suffixes to exclude from the result", |
Chris Frantz | 00c717b | 2022-07-28 14:58:32 -0700 | [diff] [blame] | 27 | ), |
| 28 | }, |
| 29 | ) |