OSDN Git Service

Add option to fail when Android.mk files change PRODUCT_* variables.
authorJoe Onorato <joeo@google.com>
Tue, 14 Sep 2010 17:09:48 +0000 (13:09 -0400)
committerJoe Onorato <joeo@google.com>
Tue, 14 Sep 2010 17:13:27 +0000 (13:13 -0400)
It's turned off for now.

Change-Id: I0b5a3ce5fdc7693c8ebd870312f0c2e13fdb8b22

core/definitions.mk
core/main.mk
core/product.mk

index 7c69ce1..09a8829 100644 (file)
@@ -534,6 +534,30 @@ $(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
 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
+## the empty string if they are not equal.
+###########################################################
+define streq
+$(strip $(if $(strip $(1)),\
+  $(if $(strip $(2)),\
+    $(if $(filter-out __,_$(subst $(strip $(1)),,$(strip $(2)))$(subst $(strip $(2)),,$(strip $(1)))_),,true), \
+    ),\
+  $(if $(strip $(2)),\
+    ,\
+    true)\
+ ))
+endef
+
+###########################################################
 ## Convert "a b c" into "a:b:c"
 ###########################################################
 
index 325a0e5..35760d6 100644 (file)
@@ -472,6 +472,13 @@ endif      # !BUILD_TINY_ANDROID
 
 endif  # !SDK_ONLY
 
+# Before we go and include all of the module makefiles, stash away
+# the PRODUCT_* values so you can't get to them.
+stash_product_vars:=#true
+ifeq ($(stash_product_vars),true)
+  $(call stash-product-vars, __STASHED, DO_NOT_USE_IN_ANDROID_MK_)
+endif
+
 ifneq ($(ONE_SHOT_MAKEFILE),)
 # We've probably been invoked by the "mm" shell function
 # with a subdirectory's makefile.
@@ -502,6 +509,11 @@ subdir_makefiles := \
 include $(subdir_makefiles)
 endif # ONE_SHOT_MAKEFILE
 
+ifeq ($(stash_product_vars),true)
+  $(call assert-product-vars, __STASHED, DO_NOT_USE_IN_ANDROID_MK_)
+  $(call restore-product-vars, __STASHED)
+endif
+
 # -------------------------------------------------------------------
 # All module makefiles have been included at this point.
 # -------------------------------------------------------------------
index 7594f6f..e425e02 100644 (file)
@@ -186,3 +186,47 @@ endef
 define resolve-short-product-name
 $(strip $(call _resolve-short-product-name,$(1)))
 endef
+
+
+#
+# Rename the variables in _product_var_list.
+# $(1): Renamed prefix
+# $(2): New value prefix.  The new value will be $(2)$(VARNAME)
+#
+define stash-product-vars
+$(foreach v,$(_product_var_list), \
+        $(eval $(strip $(1))_$(call rot13,$(v)):=$$($$(v))) \
+        $(eval $(v):=$(2)$$(v)) \
+ )
+endef
+
+#
+# Assert that the the variable stashed by stash-product-vars remains untouched.
+# $(1): The prefix as supplied to stash-product-vars
+# $(2): The expected value prefix.  The value should be $(2)$(VARNAME)
+#
+define assert-product-vars
+$(strip \
+  $(eval changed_variables:=)
+  $(foreach v,$(_product_var_list), \
+    $(if $(call streq,$($(v)),$(2)$(v)),, \
+        $(eval $(warning $(v) has been modified: $($(v)))) \
+        $(eval changed_variables := $(changed_variables) $(v))) \
+   ) \
+  $(if $(changed_variables),\
+    $(eval $(error The following variables have been changed: $(changed_variables))),)
+)
+endef
+# ... $(eval $(warning $(v) $($(v)),$(2)$(v) streq-->$(call streq,$($(v)),$(2)$(v)))) \
+
+#
+# Restore the product variables as stashed by stash-product-vars
+# $(1): The prefix as supplied to stash-product-vars
+#
+define restore-product-vars
+$(foreach v,$(_product_var_list), \
+        $(eval $(v):=$($(strip $(1))_$(call rot13,$(v)))) \
+        $(eval $(strip $(1))_$(v):=) \
+ )
+endef
+