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
17# TODO(b/149249068): Remove vts10-tradefed.jar after all VTS tests are converted
18general_tests_tools := \
19    $(HOST_OUT_JAVA_LIBRARIES)/cts-tradefed.jar \
20    $(HOST_OUT_JAVA_LIBRARIES)/compatibility-host-util.jar \
21    $(HOST_OUT_JAVA_LIBRARIES)/vts-tradefed.jar \
22    $(HOST_OUT_JAVA_LIBRARIES)/vts10-tradefed.jar
23
24intermediates_dir := $(call intermediates-dir-for,PACKAGING,general-tests)
25general_tests_zip := $(PRODUCT_OUT)/general-tests.zip
26# Create an artifact to include a list of test config files in general-tests.
27general_tests_list_zip := $(PRODUCT_OUT)/general-tests_list.zip
28
29# Filter shared entries between general-tests and device-tests's HOST_SHARED_LIBRARY.FILES,
30# to avoid warning about overriding commands.
31my_host_shared_lib_for_general_tests := \
32  $(foreach m,$(filter $(COMPATIBILITY.device-tests.HOST_SHARED_LIBRARY.FILES),\
33	   $(COMPATIBILITY.general-tests.HOST_SHARED_LIBRARY.FILES)),$(call word-colon,2,$(m)))
34my_general_tests_shared_lib_files := \
35  $(filter-out $(COMPATIBILITY.device-tests.HOST_SHARED_LIBRARY.FILES),\
36	 $(COMPATIBILITY.general-tests.HOST_SHARED_LIBRARY.FILES))
37
38my_host_shared_lib_for_general_tests += $(call copy-many-files,$(my_general_tests_shared_lib_files))
39
40# Create an artifact to include all test config files in general-tests.
41general_tests_configs_zip := $(PRODUCT_OUT)/general-tests_configs.zip
42# Create an artifact to include all shared librariy files in general-tests.
43general_tests_host_shared_libs_zip := $(PRODUCT_OUT)/general-tests_host-shared-libs.zip
44
45$(general_tests_zip) : PRIVATE_general_tests_list_zip := $(general_tests_list_zip)
46$(general_tests_zip) : .KATI_IMPLICIT_OUTPUTS := $(general_tests_list_zip) $(general_tests_configs_zip) $(general_tests_host_shared_libs_zip)
47$(general_tests_zip) : PRIVATE_TOOLS := $(general_tests_tools)
48$(general_tests_zip) : PRIVATE_INTERMEDIATES_DIR := $(intermediates_dir)
49$(general_tests_zip) : PRIVATE_HOST_SHARED_LIBS := $(my_host_shared_lib_for_general_tests)
50$(general_tests_zip) : PRIVATE_general_tests_configs_zip := $(general_tests_configs_zip)
51$(general_tests_zip) : PRIVATE_general_host_shared_libs_zip := $(general_tests_host_shared_libs_zip)
52$(general_tests_zip) : $(COMPATIBILITY.general-tests.FILES) $(general_tests_tools) $(my_host_shared_lib_for_general_tests) $(SOONG_ZIP)
53	rm -rf $(PRIVATE_INTERMEDIATES_DIR)
54	rm -f $@ $(PRIVATE_general_tests_list_zip)
55	mkdir -p $(PRIVATE_INTERMEDIATES_DIR) $(PRIVATE_INTERMEDIATES_DIR)/tools
56	echo $(sort $(COMPATIBILITY.general-tests.FILES)) | tr " " "\n" > $(PRIVATE_INTERMEDIATES_DIR)/list
57	grep $(HOST_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/list > $(PRIVATE_INTERMEDIATES_DIR)/host.list || true
58	grep $(TARGET_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/list > $(PRIVATE_INTERMEDIATES_DIR)/target.list || true
59	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/host.list > $(PRIVATE_INTERMEDIATES_DIR)/host-test-configs.list || true
60	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/target.list > $(PRIVATE_INTERMEDIATES_DIR)/target-test-configs.list || true
61	$(hide) for shared_lib in $(PRIVATE_HOST_SHARED_LIBS); do \
62	  echo $$shared_lib >> $(PRIVATE_INTERMEDIATES_DIR)/host.list; \
63	  echo $$shared_lib >> $(PRIVATE_INTERMEDIATES_DIR)/shared-libs.list; \
64	done
65	grep $(HOST_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/shared-libs.list > $(PRIVATE_INTERMEDIATES_DIR)/host-shared-libs.list || true
66	cp -fp $(PRIVATE_TOOLS) $(PRIVATE_INTERMEDIATES_DIR)/tools/
67	$(SOONG_ZIP) -d -o $@ \
68	  -P host -C $(PRIVATE_INTERMEDIATES_DIR) -D $(PRIVATE_INTERMEDIATES_DIR)/tools \
69	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host.list \
70	  -P target -C $(PRODUCT_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/target.list
71	$(SOONG_ZIP) -d -o $(PRIVATE_general_tests_configs_zip) \
72	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host-test-configs.list \
73	  -P target -C $(PRODUCT_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/target-test-configs.list
74	$(SOONG_ZIP) -d -o $(PRIVATE_general_host_shared_libs_zip) \
75	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host-shared-libs.list
76	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/host.list | sed s%$(HOST_OUT)%host%g > $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
77	grep -e .*\\.config$$ $(PRIVATE_INTERMEDIATES_DIR)/target.list | sed s%$(PRODUCT_OUT)%target%g >> $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
78	$(SOONG_ZIP) -d -o $(PRIVATE_general_tests_list_zip) -C $(PRIVATE_INTERMEDIATES_DIR) -f $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
79
80general-tests: $(general_tests_zip)
81$(call dist-for-goals, general-tests, $(general_tests_zip) $(general_tests_list_zip) $(general_tests_configs_zip) $(general_tests_host_shared_libs_zip))
82
83intermediates_dir :=
84general_tests_tools :=
85general_tests_zip :=
86general_tests_list_zip :=
87general_tests_configs_zip :=
88general_tests_host_shared_libs_zip :=
89