diff options
author | 2025-03-18 11:23:58 -0700 | |
---|---|---|
committer | 2025-03-18 13:30:29 -0700 | |
commit | 405e20bf3cb7ca6c4c013f12cce73ea041242875 (patch) | |
tree | f2f78e5475d56c270dc2d9dbd2f4fe94e26598dd | |
parent | 30f05352c3e6f4333c77d4af66c253572d3ea6c9 (diff) |
Add soong_config_set_int
For integer-typed values in select()
Bug: 355539748
Test: soong tests
Change-Id: I7ad08c97462efdf33425ba7d67423b39c3d01f95
-rw-r--r-- | common/math.mk | 11 | ||||
-rw-r--r-- | core/config.mk | 13 |
2 files changed, 24 insertions, 0 deletions
diff --git a/common/math.mk b/common/math.mk index 829ceb5e6f..0444631571 100644 --- a/common/math.mk +++ b/common/math.mk @@ -89,6 +89,11 @@ define math_is_number $(strip $(if $(call math_is_number_in_100,$(1)),true,$(call _math_ext_is_number,$(1)))) endef +# Returns true if $(1) is a positive or negative integer. +define math_is_int +$(call math_is_number,$(patsubst -%,%,$(1))) +endef + define math_is_zero $(strip \ $(if $(word 2,$(1)),$(call math-error,Multiple words in a single argument: $(1))) \ @@ -100,6 +105,12 @@ $(call math-expect-true,(call math_is_number,2)) $(call math-expect-true,(call math_is_number,202412)) $(call math-expect-false,(call math_is_number,foo)) $(call math-expect-false,(call math_is_number,-1)) +$(call math-expect-true,(call math_is_int,50)) +$(call math-expect-true,(call math_is_int,-1)) +$(call math-expect-true,(call math_is_int,-528)) +$(call math-expect-true,(call math_is_int,-0)) +$(call math-expect-false,(call math_is_int,--1)) +$(call math-expect-false,(call math_is_int,-)) $(call math-expect-error,(call math_is_number,1 2),Multiple words in a single argument: 1 2) $(call math-expect-error,(call math_is_number,no 2),Multiple words in a single argument: no 2) diff --git a/core/config.mk b/core/config.mk index fafdfe1ac3..38f3f5b802 100644 --- a/core/config.mk +++ b/core/config.mk @@ -330,6 +330,19 @@ $(eval SOONG_CONFIG_$(strip $1)_$(strip $2):=$(filter true,$3)) $(eval SOONG_CONFIG_TYPE_$(strip $1)_$(strip $2):=bool) endef +# soong_config_set_int is the same as soong_config_set, but it will +# also type the variable as an integer, so that when using select() expressions +# in blueprint files they can use integer values instead of strings. +# It will error out if a non-integer is supplied +# $1 is the namespace. $2 is the variable name. $3 is the variable value. +# Ex: $(call soong_config_set_bool,acme,COOL_FEATURE,34) +define soong_config_set_int +$(call soong_config_define_internal,$1,$2) \ +$(if $(call math_is_int,$3),,$(error soong_config_set_int called with non-integer value $(3))) +$(eval SOONG_CONFIG_$(strip $1)_$(strip $2):=$(strip $3)) +$(eval SOONG_CONFIG_TYPE_$(strip $1)_$(strip $2):=int) +endef + # soong_config_set_string_list is the same as soong_config_set, but it will # also type the variable as a list of strings, so that when using select() expressions # in blueprint files they can use list values instead of strings. |