blob: 4315a84f2d6cde2cf8515a1f8c7796ff4dea7689 [file] [log] [blame]
Chris Frantz00c717b2022-07-28 14:58:32 -07001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5def _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
17exclude_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 Frantz07ece742022-07-28 16:08:37 -070026 doc = "File suffixes to exclude from the result",
Chris Frantz00c717b2022-07-28 14:58:32 -070027 ),
28 },
29)