• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Constraints corresponding to product variables."""
2
3load(":constants.bzl", "constants")
4load(":settings.bzl", "soong_config_variables")
5
6package(default_visibility = ["//visibility:public"])
7
8# Unlike product config variables below, these are dynamically generated from
9# Soong, since the list of config variables are dynamically defined in
10# Android.bp files and not hardcoded into Soong.
11soong_config_variables(
12    bool_vars = constants.SoongConfigBoolVariables,
13    string_vars = constants.SoongConfigStringVariables,
14    value_vars = constants.SoongConfigValueVariables,
15)
16
17# Generate one constraint_value for each product_variable
18# The constraint_value for <var> can be within a select() to specify an
19# attribute value for the same conditions product_variable.<var>, for most
20# cases, that is when the value of <var> is true. For example,
21#
22# product_variables: {
23#     debuggable: {
24#         cflags: ["debug_flag1", "debug_flag2"],
25#     },
26# }
27#
28# translates into:
29#
30# cflags = select({
31#   "//build/bazel/product_variables:debuggable": ["debug_flag1", "debug_flag2"],
32#   "//conditions:default": [],
33# }),
34[
35    (
36        constraint_setting(name = product_variable + "_constraint"),
37        constraint_value(
38            name = product_variable,
39            constraint_setting = product_variable + "_constraint",
40        ),
41    )
42    for product_variable in constants.ProductVariables
43]
44
45# Caution: do not use these arch-variant product variables directly.
46# If you have a complex combination of product variable and architecture/os/etc,
47# prefer instead to craft an appropriate configuration in your BUILD file.
48# See: https://docs.bazel.build/versions/master/configurable-attributes.html
49# Within bp2build, :safestack-android should be used when an attribute value is
50# conditional on both safestack:true and the os is android.
51#
52# e.g.
53# target: {
54#     android: {
55#         product_variables: {
56#             safestack: {
57#                 cflags: ["-Dsafestack-android"],
58#             },
59#         },
60#     },
61# },
62#
63# would translate to:
64#
65# cflags = select({
66#     "//build/bazel/product_variables:safestack-android": ["-Dsafestack-android"],
67#     "//conditions:default": [],
68# }),
69[
70    [config_setting(
71        name = product_variable + "-" + variant,
72        constraint_values = [
73            ":" + product_variable,
74            variantConstraint,
75        ],
76    ) for variant, variantConstraint in constants.ArchVariantToConstraints.items()]
77    for product_variable in constants.ArchVariantProductVariables
78]
79