1# Copyright (C) 2017 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15.PHONY: general-tests
16
17general_tests_tools := \
18    $(HOST_OUT_JAVA_LIBRARIES)/cts-tradefed.jar \
19    $(HOST_OUT_JAVA_LIBRARIES)/compatibility-host-util.jar \
20    $(HOST_OUT_JAVA_LIBRARIES)/vts-tradefed.jar \
21
22intermediates_dir := $(call intermediates-dir-for,PACKAGING,general-tests)
23general_tests_zip := $(PRODUCT_OUT)/general-tests.zip
24# Create an artifact to include a list of test config files in general-tests.
25general_tests_list_zip := $(PRODUCT_OUT)/general-tests_list.zip
26
27# Filter shared entries between general-tests and device-tests's HOST_SHARED_LIBRARY.FILES,
28# to avoid warning about overriding commands.
29my_host_shared_lib_for_general_tests := \
30  $(foreach m,$(filter $(COMPATIBILITY.device-tests.HOST_SHARED_LIBRARY.FILES),\
31	   $(COMPATIBILITY.general-tests.HOST_SHARED_LIBRARY.FILES)),$(call word-colon,2,$(m)))
32my_general_tests_shared_lib_files := \
33  $(filter-out $(COMPATIBILITY.device-tests.HOST_SHARED_LIBRARY.FILES),\
34	 $(COMPATIBILITY.general-tests.HOST_SHARED_LIBRARY.FILES))
35
36my_host_shared_lib_for_general_tests += $(call copy-many-files,$(my_general_tests_shared_lib_files))
37
38# Create an artifact to include all test config files in general-tests.
39general_tests_configs_zip := $(PRODUCT_OUT)/general-tests_configs.zip
40# Create an artifact to include all shared librariy files in general-tests.
41general_tests_host_shared_libs_zip := $(PRODUCT_OUT)/general-tests_host-shared-libs.zip
42
43$(general_tests_zip) : PRIVATE_general_tests_list_zip := $(general_tests_list_zip)
44$(general_tests_zip) : .KATI_IMPLICIT_OUTPUTS := $(general_tests_list_zip) $(general_tests_configs_zip) $(general_tests_host_shared_libs_zip)
45$(general_tests_zip) : PRIVATE_TOOLS := $(general_tests_tools)
46$(general_tests_zip) : PRIVATE_INTERMEDIATES_DIR := $(intermediates_dir)
47$(general_tests_zip) : PRIVATE_HOST_SHARED_LIBS := $(my_host_shared_lib_for_general_tests)
48$(general_tests_zip) : PRIVATE_general_tests_configs_zip := $(general_tests_configs_zip)
49$(general_tests_zip) : PRIVATE_general_host_shared_libs_zip := $(general_tests_host_shared_libs_zip)
50$(general_tests_zip) : $(COMPATIBILITY.general-tests.FILES) $(general_tests_tools) $(my_host_shared_lib_for_general_tests) $(SOONG_ZIP)
51	rm -rf $(PRIVATE_INTERMEDIATES_DIR)
52	rm -f $@ $(PRIVATE_general_tests_list_zip)
53	mkdir -p $(PRIVATE_INTERMEDIATES_DIR) $(PRIVATE_INTERMEDIATES_DIR)/tools
54	echo $(sort $(COMPATIBILITY.general-tests.FILES)) | tr " " "\n" > $(PRIVATE_INTERMEDIATES_DIR)/list
55	grep $(HOST_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/list > $(PRIVATE_INTERMEDIATES_DIR)/host.list || true
56	grep $(TARGET_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/list > $(PRIVATE_INTERMEDIATES_DIR)/target.list || true
57	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/host.list > $(PRIVATE_INTERMEDIATES_DIR)/host-test-configs.list || true
58	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/target.list > $(PRIVATE_INTERMEDIATES_DIR)/target-test-configs.list || true
59	$(hide) for shared_lib in $(PRIVATE_HOST_SHARED_LIBS); do \
60	  echo $$shared_lib >> $(PRIVATE_INTERMEDIATES_DIR)/host.list; \
61	  echo $$shared_lib >> $(PRIVATE_INTERMEDIATES_DIR)/shared-libs.list; \
62	done
63	grep $(HOST_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/shared-libs.list > $(PRIVATE_INTERMEDIATES_DIR)/host-shared-libs.list || true
64	cp -fp $(PRIVATE_TOOLS) $(PRIVATE_INTERMEDIATES_DIR)/tools/
65	$(SOONG_ZIP) -d -o $@ \
66	  -P host -C $(PRIVATE_INTERMEDIATES_DIR) -D $(PRIVATE_INTERMEDIATES_DIR)/tools \
67	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host.list \
68	  -P target -C $(PRODUCT_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/target.list
69	$(SOONG_ZIP) -d -o $(PRIVATE_general_tests_configs_zip) \
70	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host-test-configs.list \
71	  -P target -C $(PRODUCT_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/target-test-configs.list
72	$(SOONG_ZIP) -d -o $(PRIVATE_general_host_shared_libs_zip) \
73	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host-shared-libs.list
74	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/host.list | sed s%$(HOST_OUT)%host%g > $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
75	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/target.list | sed s%$(PRODUCT_OUT)%target%g >> $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
76	$(SOONG_ZIP) -d -o $(PRIVATE_general_tests_list_zip) -C $(PRIVATE_INTERMEDIATES_DIR) -f $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
77
78general-tests: $(general_tests_zip)
79$(call dist-for-goals, general-tests, $(general_tests_zip) $(general_tests_list_zip) $(general_tests_configs_zip) $(general_tests_host_shared_libs_zip))
80
81intermediates_dir :=
82general_tests_tools :=
83general_tests_zip :=
84general_tests_list_zip :=
85general_tests_configs_zip :=
86general_tests_host_shared_libs_zip :=
87