blob: e639867c5f72215b301982f497effce8d84571b5 [file] [log] [blame]
Jan Schär07e69052025-05-12 16:34:15 +00001# Copyright The Monogon Project Authors.
2# SPDX-License-Identifier: Apache-2.0
3
4def _test_product_info_impl(ctx):
5 raw_product_info = json.encode({
6 "id": ctx.attr.os_id,
7 "name": ctx.attr.os_name,
8 "version": "0.0.0",
9 "variant": ctx.attr.architecture,
10 "architecture": ctx.attr.architecture,
11 })
12 product_info_file = ctx.actions.declare_file(ctx.label.name + ".json")
13 ctx.actions.write(product_info_file, raw_product_info)
14 return [DefaultInfo(files = depset([product_info_file]))]
15
16_test_product_info = rule(
17 implementation = _test_product_info_impl,
18 attrs = {
19 "os_name": attr.string(mandatory = True),
20 "os_id": attr.string(mandatory = True),
21 "architecture": attr.string(mandatory = True),
22 },
23)
24
25def _test_product_info_macro_impl(**kwargs):
26 _test_product_info(
27 architecture = select({
28 "@platforms//cpu:x86_64": "x86_64",
29 "@platforms//cpu:aarch64": "aarch64",
30 }),
31 **kwargs
32 )
33
34test_product_info = macro(
35 inherit_attrs = _test_product_info,
36 attrs = {"architecture": None},
37 implementation = _test_product_info_macro_impl,
38 doc = "This is a simplified variant of product_info for use in tests.",
39)