blob: e7fb44a014a3cb94973c898216bbb74b336b501b [file] [log] [blame]
Philipp Schrader175a93c2023-02-19 13:13:40 -08001load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory_bin_action")
2
3def _assemble_static_files_impl(ctx):
4 out_dir = ctx.actions.declare_directory(ctx.label.name)
5
6 copy_to_directory_bin = ctx.toolchains["@aspect_bazel_lib//lib:copy_to_directory_toolchain_type"].copy_to_directory_info.bin
7
8 copy_to_directory_bin_action(
9 ctx,
10 dst = out_dir,
11 name = ctx.label.name,
12 copy_to_directory_bin = copy_to_directory_bin,
13 files = ctx.files.pictures + ctx.attr.app_files.files.to_list(),
14 replace_prefixes = ctx.attr.replace_prefixes,
15 )
16
17 return [DefaultInfo(
18 files = depset([out_dir]),
19 runfiles = ctx.runfiles([out_dir]),
20 )]
21
22assemble_static_files = rule(
23 implementation = _assemble_static_files_impl,
24 attrs = {
25 "app_files": attr.label(
26 mandatory = True,
27 ),
28 "pictures": attr.label_list(
29 mandatory = True,
Emily Markova7b786402024-01-24 20:05:24 -080030 allow_files = True,
Philipp Schrader175a93c2023-02-19 13:13:40 -080031 ),
32 "replace_prefixes": attr.string_dict(
33 mandatory = True,
34 ),
35 },
36 toolchains = ["@aspect_bazel_lib//lib:copy_to_directory_toolchain_type"],
37)
Emily Markova7b786402024-01-24 20:05:24 -080038
39def _assemble_service_worker_files_impl(ctx):
40 args = ctx.actions.args()
41 args.add_all(ctx.attr._package.files, before_each = "--input_dir", expand_directories = False)
42 args.add_all(ctx.outputs.outs, before_each = "--output")
43 args.add_all(ctx.attr.outs_as_strings, before_each = "--relative_output")
44 ctx.actions.run(
45 inputs = ctx.attr._package.files,
46 outputs = ctx.outputs.outs,
47 executable = ctx.executable._tool,
48 arguments = [args],
49 mnemonic = "AssembleAngularServiceWorker",
50 )
51
52_assemble_service_worker_files = rule(
53 implementation = _assemble_service_worker_files_impl,
54 attrs = {
55 "outs": attr.output_list(
56 allow_empty = False,
57 mandatory = True,
58 ),
59 "outs_as_strings": attr.string_list(
60 allow_empty = False,
61 mandatory = True,
62 ),
63 "_package": attr.label(
64 default = "//:node_modules/@angular/service-worker",
65 ),
66 "_tool": attr.label(
67 default = "//tools/build_rules/js:assemble_service_worker_files",
68 cfg = "exec",
69 executable = True,
70 ),
71 },
72)
73
74def assemble_service_worker_files(outs, **kwargs):
75 _assemble_service_worker_files(
76 outs = outs,
77 outs_as_strings = outs,
78 **kwargs
79 )