Merge "Implement LOCAL_TEST_DATA to ship data with tests"

This commit is contained in:
Treehugger Robot 2016-12-14 03:52:31 +00:00 committed by Gerrit Code Review
commit dd0e69d47f
3 changed files with 45 additions and 2 deletions

View file

@ -460,6 +460,33 @@ COMPATIBILITY.$(LOCAL_COMPATIBILITY_SUITE).FILES := \
$(my_all_targets) : $(my_compat_files)
endif # LOCAL_COMPATIBILITY_SUITE
###########################################################
## Test Data
###########################################################
my_test_data_pairs :=
my_installed_test_data :=
ifneq ($(filter NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
ifneq ($(strip $(LOCAL_TEST_DATA)),)
ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
my_test_data_pairs := $(strip $(foreach td,$(LOCAL_TEST_DATA), \
$(eval _file := $(call word-colon,2,$(td))) \
$(if $(_file), \
$(eval _base := $(call word-colon,1,$(td))), \
$(eval _base := $(LOCAL_PATH)) \
$(eval _file := $(call word-colon,1,$(td)))) \
$(if $(findstring ..,$(_file)),$(error $(LOCAL_MODULE_MAKEFILE): LOCAL_TEST_DATA may not include '..': $(_file))) \
$(if $(filter /%,$(_base) $(_file)),$(error $(LOCAL_MODULE_MAKEFILE): LOCAL_TEST_DATA may not include absolute paths: $(_base) $(_file))) \
$(call append-path,$(_base),$(_file)):$(call append-path,$(my_module_path),$(_file))))
my_installed_test_data := $(call copy-many-files,$(my_test_data_pairs))
$(LOCAL_INSTALLED_MODULE): $(my_installed_test_data)
endif
endif
endif
###########################################################
## Register with ALL_MODULES
###########################################################
@ -481,11 +508,12 @@ ALL_MODULES.$(my_register_name).BUILT := \
ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE))
ALL_MODULES.$(my_register_name).INSTALLED := \
$(strip $(ALL_MODULES.$(my_register_name).INSTALLED) \
$(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed) $(my_installed_symlinks))
$(LOCAL_INSTALLED_MODULE) $(my_init_rc_installed) $(my_installed_symlinks) \
$(my_installed_test_data))
ALL_MODULES.$(my_register_name).BUILT_INSTALLED := \
$(strip $(ALL_MODULES.$(my_register_name).BUILT_INSTALLED) \
$(LOCAL_BUILT_MODULE):$(LOCAL_INSTALLED_MODULE) \
$(my_init_rc_pairs))
$(my_init_rc_pairs) $(my_test_data_pairs))
endif
ifdef LOCAL_PICKUP_FILES
# Files or directories ready to pick up by the build system

View file

@ -209,6 +209,7 @@ LOCAL_STATIC_JAVA_LIBRARIES:=
LOCAL_STATIC_LIBRARIES:=
LOCAL_STRIP_MODULE:=
LOCAL_SYSTEM_SHARED_LIBRARIES:=none
LOCAL_TEST_DATA:=
LOCAL_TEST_MODULE_TO_PROGUARD_WITH:=
LOCAL_TIDY:=
LOCAL_TIDY_CHECKS:=

View file

@ -468,6 +468,20 @@ $(strip \
)
endef
###########################################################
## Find test data in a form required by LOCAL_TEST_DATA
## $(1): the base dir, relative to the root of the source tree.
## $(3): the file name pattern to be passed to find as "-name"
## $(2): a list of subdirs of the base dir
###########################################################
define find-test-data-in-subdirs
$(foreach f,$(sort $(patsubst ./%,%, \
$(shell cd $(1) ; \
find -L $(3) -type f -and -name $(2) -and -not -name ".*") \
)),$(1):$(f))
endef
###########################################################
## Function we can evaluate to introduce a dynamic dependency
###########################################################