Include and inherit statements in Starlark

In make, an include statement can include file paths with variables and will ignore nonexistent files when prefixed with a minus. The product configuration equivalent is the inherit-product-if-exists function. Starlark uses load statements with files identified by string literal, and if a file doesn't exist, Starlark throws an error.

To work around this limitation, the Starlark converter:

  • finds all Makefiles that could match the path that involves variables
  • emits Starlark load statements for all of them
  • chooses the correct one at runtime

Note that the generated Starlark code may look unnatural as it lists all the matching paths even though only one will be executed.

We recommend removing variable references in the include/inherit-product statements.

When variable references cannot be avoided, try to minimize the variable part. For example:

MY_DIR := path/to/$(TARGET_PRODUCT)
include $(MY_DIR)/file.mk

causes converter to generate a load statement for each file.mk in the source tree, whereas

include path/to/$(TARGET_PRODUCT)/file.mk

restricts it to file.mk files under path/to. Of course, removing the usage of TARGET_PRODUCT as well would be ideal.