From c1f17ffc7d4fa6225274b9f8007d6f7fae03ab08 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 5 Oct 2016 16:57:27 -0700 Subject: [PATCH] Replace product variable stashing with .KATI_READONLY Instead of using rot13 / rot26, use the Kati extension to mark these variables as readonly. Move $(strip) for a few variables to before they're marked readonly. Use a different variable for modifications to BOARD_KERNEL_CMDLINE in build/core/Makefile. Test: build/tools/kati_all_products.mk on AOSP and internal master Test: build-aosp_bullhead.ninja the same before / after Change-Id: If98b24af763831a9c5c2de38037a69ab1bf9e023 --- core/Makefile | 24 +++++++++++------------- core/config.mk | 3 +++ core/main.mk | 13 +++---------- core/product.mk | 26 ++++---------------------- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/core/Makefile b/core/Makefile index 42d42bb47f..9a6ced4133 100644 --- a/core/Makefile +++ b/core/Makefile @@ -522,12 +522,10 @@ endif INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS)) -BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE)) ifdef BOARD_KERNEL_BASE INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE) endif -BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE)) ifdef BOARD_KERNEL_PAGESIZE INTERNAL_BOOTIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE) endif @@ -539,9 +537,9 @@ VERITY_KEYID := veritykeyid=id:`openssl x509 -in $(PRODUCTS.$(INTERNAL_PRODUCT). endif endif -BOARD_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID)) -ifdef BOARD_KERNEL_CMDLINE -INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)" +INTERNAL_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID)) +ifdef INTERNAL_KERNEL_CMDLINE +INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)" endif INTERNAL_MKBOOTIMG_VERSION_ARGS := \ @@ -632,6 +630,7 @@ endif # TARGET_BOOTIMAGE_USE_EXT2 endif # BOARD_USES_RECOVERY_AS_BOOT else # TARGET_NO_KERNEL +INTERNAL_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE)) # HACK: The top-level targets depend on the bootimage. Not all targets # can produce a bootimage, though, and emulator targets need the ramdisk # instead. Fake it out by calling the ramdisk the bootimage. @@ -977,13 +976,12 @@ INTERNAL_RECOVERYIMAGE_ARGS := \ --ramdisk $(recovery_ramdisk) # Assumes this has already been stripped -ifdef BOARD_KERNEL_CMDLINE - INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)" +ifdef INTERNAL_KERNEL_CMDLINE + INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)" endif ifdef BOARD_KERNEL_BASE INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE) endif -BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE)) ifdef BOARD_KERNEL_PAGESIZE INTERNAL_RECOVERYIMAGE_ARGS += --pagesize $(BOARD_KERNEL_PAGESIZE) endif @@ -1346,7 +1344,7 @@ define build-boottarball-target $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)" $(hide) mkdir -p $(PRODUCT_OUT)/boot $(hide) cp -f $(INTERNAL_BOOTIMAGE_FILES) $(PRODUCT_OUT)/boot/. - $(hide) echo $(BOARD_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline + $(hide) echo $(INTERNAL_KERNEL_CMDLINE) > $(PRODUCT_OUT)/boot/cmdline $(hide) $(MKTARBALL) $(FS_GET_STATS) \ $(PRODUCT_OUT) boot $(PRIVATE_BOOT_TAR) \ $(INSTALLED_BOOTTARBALL_TARGET) $(TARGET_OUT) @@ -1812,8 +1810,8 @@ ifdef INSTALLED_2NDBOOTLOADER_TARGET $(hide) $(ACP) \ $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/$(PRIVATE_RECOVERY_OUT)/second endif -ifdef BOARD_KERNEL_CMDLINE - $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline +ifdef INTERNAL_KERNEL_CMDLINE + $(hide) echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/cmdline endif ifdef BOARD_KERNEL_BASE $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/$(PRIVATE_RECOVERY_OUT)/base @@ -1841,8 +1839,8 @@ ifdef INSTALLED_2NDBOOTLOADER_TARGET $(hide) $(ACP) \ $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second endif -ifdef BOARD_KERNEL_CMDLINE - $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline +ifdef INTERNAL_KERNEL_CMDLINE + $(hide) echo "$(INTERNAL_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline endif ifdef BOARD_KERNEL_BASE $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base diff --git a/core/config.mk b/core/config.mk index bab31b7889..cf1e8e5ade 100644 --- a/core/config.mk +++ b/core/config.mk @@ -216,6 +216,9 @@ ifeq ($(TARGET_CPU_ABI),) endif TARGET_CPU_ABI2 := $(strip $(TARGET_CPU_ABI2)) +BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE)) +BOARD_KERNEL_PAGESIZE := $(strip $(BOARD_KERNEL_PAGESIZE)) + # Commands to generate .toc file common to ELF .so files. define _gen_toc_command_for_elf $(hide) ($($(PRIVATE_2ND_ARCH_VAR_PREFIX)$(PRIVATE_PREFIX)READELF) -d $(1) | grep SONAME || echo "No SONAME for $1") > $(2) diff --git a/core/main.mk b/core/main.mk index de77927a06..dabe0936fa 100644 --- a/core/main.mk +++ b/core/main.mk @@ -504,12 +504,9 @@ endif FULL_BUILD := true -# Before we go and include all of the module makefiles, stash away -# the PRODUCT_* values so that later we can verify they are not modified. -stash_product_vars:=true -ifeq ($(stash_product_vars),true) - $(call stash-product-vars, __STASHED) -endif +# Before we go and include all of the module makefiles, mark the PRODUCT_* +# values readonly so that they won't be modified. +$(call readonly-product-vars) ifneq ($(ONE_SHOT_MAKEFILE),) # We've probably been invoked by the "mm" shell function @@ -574,10 +571,6 @@ endif # ONE_SHOT_MAKEFILE # Now with all Android.mks loaded we can do post cleaning steps. include $(BUILD_SYSTEM)/post_clean.mk -ifeq ($(stash_product_vars),true) - $(call assert-product-vars, __STASHED) -endif - # ------------------------------------------------------------------- # All module makefiles have been included at this point. # ------------------------------------------------------------------- diff --git a/core/product.mk b/core/product.mk index 7193cf78d2..d4790d5af7 100644 --- a/core/product.mk +++ b/core/product.mk @@ -296,33 +296,15 @@ _product_stash_var_list += \ GLOBAL_CLANG_CFLAGS_NO_OVERRIDE \ # -# Stash values of the variables in _product_stash_var_list. -# $(1): Renamed prefix +# Mark the variables in _product_stash_var_list as readonly # -define stash-product-vars +define readonly-product-vars $(foreach v,$(_product_stash_var_list), \ - $(eval $(strip $(1))_rot26_$(v):=$$($$(v))) \ + $(eval $(v) ?=) \ + $(eval .KATI_READONLY := $(v)) \ ) endef -# -# Assert that the the variable stashed by stash-product-vars remains untouched. -# $(1): The prefix as supplied to stash-product-vars -# -define assert-product-vars -$(strip \ - $(eval changed_variables:=) - $(foreach v,$(_product_stash_var_list), \ - $(if $(call streq,$($(v)),$($(strip $(1))_rot26_$(v))),, \ - $(eval $(warning $(v) has been modified: $($(v)))) \ - $(eval $(warning previous value: $($(strip $(1))_$(call rot13,$(v))))) \ - $(eval changed_variables := $(changed_variables) $(v))) \ - ) \ - $(if $(changed_variables),\ - $(eval $(error The following variables have been changed: $(changed_variables))),) -) -endef - define add-to-product-copy-files-if-exists $(if $(wildcard $(word 1,$(subst :, ,$(1)))),$(1)) endef