Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b011810c authored by Dan Willemsen's avatar Dan Willemsen
Browse files

Optimize rebuilds by reducing $(shell) usage

$(shell) isn't particularly fast in Kati, and they have to be executed
both when reading the makefiles and determining whether the ninja file
needs to be regenerated.

Right now, the regen time is mostly hidden because we run them in
parallel. We've also configured it to ignore any commands that contain
"echo", "date", or the output directory. That happens to remove most
commands that contain side effects, so running them in parallel is fine.

But the side effects contain some important things, like the clean up
necessary when switching products. So I'm removing those filters, and
then we'll need to run the shell commands in sequence, since there will
be side-effects. That makes regen take longer though, so use pure-Make
implementations instead of $(shell) where possible.

This set of changes reduces aosp/master aosp_arm64-eng build $(shell)
usage and time by 2/3:

*kati*: func shell time: 3.135095 / 709
*kati*: func shell time: 1.067331 / 236

Bug: 30947985
Test: Manual test lines for math functions
Test: Compare build-aosp_arm64.ninja before/after
Change-Id: I4fc9d6318957992921972994f277c17918e7e1eb
parent 0a5b59e7
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -103,9 +103,7 @@ ifdef LOCAL_SDK_VERSION
  # missing API levels to existing ones where necessary, but we're not doing
  # missing API levels to existing ones where necessary, but we're not doing
  # that for the generated libraries. Clip the API level to the minimum where
  # that for the generated libraries. Clip the API level to the minimum where
  # appropriate.
  # appropriate.
  my_ndk_api := \
  my_ndk_api := $(call math_max,$(LOCAL_SDK_VERSION),$(my_min_sdk_version))
    $(shell if [ $(LOCAL_SDK_VERSION) -lt $(my_min_sdk_version) ]; then \
        echo $(my_min_sdk_version); else echo $(LOCAL_SDK_VERSION); fi)


  # Traditionally this has come from android/api-level.h, but with the libc
  # Traditionally this has come from android/api-level.h, but with the libc
  # headers unified it must be set by the build system since we don't have
  # headers unified it must be set by the build system since we don't have
+49 −9
Original line number Original line Diff line number Diff line
@@ -717,15 +717,6 @@ define jack-lib-files
$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
$(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
endef
endef


###########################################################
## Run rot13 on a string
## $(1): the string.  Must be one line.
###########################################################
define rot13
$(shell echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M')
endef


###########################################################
###########################################################
## Returns true if $(1) and $(2) are equal.  Returns
## Returns true if $(1) and $(2) are equal.  Returns
## the empty string if they are not equal.
## the empty string if they are not equal.
@@ -3169,6 +3160,55 @@ endif
endif
endif
endef
endef


###########################################################
# Basic math functions for positive integers <= 100
#
# (SDK versions for example)
###########################################################
__MATH_NUMBERS :=  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 \
                  21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
                  41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
                  61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \
                  81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

# Returns true if $(1) is a positive integer <= 100, otherwise returns nothing.
define math_is_number
$(strip \
  $(if $(1),,$(error Argument missing)) \
  $(if $(word 2,$(1)),$(error Multiple words in a single argument: $(1))) \
  $(if $(filter $(1),$(__MATH_NUMBERS)),true))
endef

#$(warning true == $(call math_is_number,2))
#$(warning == $(call math_is_number,foo))
#$(call math_is_number,1 2)
#$(call math_is_number,no 2)

define _math_check_valid
$(if $(call math_is_number,$(1)),,$(error Only positive integers <= 100 are supported (not $(1))))
endef

#$(call _math_check_valid,0)
#$(call _math_check_valid,1)
#$(call _math_check_valid,100)
#$(call _math_check_valid,101)
#$(call _math_check_valid,)
#$(call _math_check_valid,1 2)

# Returns the greater of $1 or $2.
# If $1 or $2 is not a positive integer <= 100, then an error is generated.
define math_max
$(strip $(call _math_check_valid,$(1)) $(call _math_check_valid,$(2)) \
  $(lastword $(filter $(1) $(2),$(__MATH_NUMBERS))))
endef

#$(call math_max)
#$(call math_max,1)
#$(call math_max,1 2,3)
#$(warning 1 == $(call math_max,1,1))
#$(warning 42 == $(call math_max,5,42))
#$(warning 42 == $(call math_max,42,5))

###########################################################
###########################################################
## Other includes
## Other includes
###########################################################
###########################################################
+2 −2
Original line number Original line Diff line number Diff line
@@ -301,7 +301,7 @@ _product_stash_var_list += \
#
#
define stash-product-vars
define stash-product-vars
$(foreach v,$(_product_stash_var_list), \
$(foreach v,$(_product_stash_var_list), \
        $(eval $(strip $(1))_$(call rot13,$(v)):=$$($$(v))) \
        $(eval $(strip $(1))_rot26_$(v):=$$($$(v))) \
 )
 )
endef
endef


@@ -313,7 +313,7 @@ define assert-product-vars
$(strip \
$(strip \
  $(eval changed_variables:=)
  $(eval changed_variables:=)
  $(foreach v,$(_product_stash_var_list), \
  $(foreach v,$(_product_stash_var_list), \
    $(if $(call streq,$($(v)),$($(strip $(1))_$(call rot13,$(v)))),, \
    $(if $(call streq,$($(v)),$($(strip $(1))_rot26_$(v))),, \
        $(eval $(warning $(v) has been modified: $($(v)))) \
        $(eval $(warning $(v) has been modified: $($(v)))) \
        $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \
        $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \
        $(eval changed_variables := $(changed_variables) $(v))) \
        $(eval changed_variables := $(changed_variables) $(v))) \