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
21intermediates_dir := $(call intermediates-dir-for,PACKAGING,general-tests)
22general_tests_zip := $(PRODUCT_OUT)/general-tests.zip
23# Create an artifact to include a list of test config files in general-tests.
24general_tests_list_zip := $(PRODUCT_OUT)/general-tests_list.zip
25
26# Filter shared entries between general-tests and device-tests's HOST_SHARED_LIBRARY.FILES,
27# to avoid warning about overriding commands.
28my_host_shared_lib_for_general_tests := \
29  $(foreach m,$(filter $(COMPATIBILITY.device-tests.HOST_SHARED_LIBRARY.FILES),\
30	   $(COMPATIBILITY.general-tests.HOST_SHARED_LIBRARY.FILES)),$(call word-colon,2,$(m)))
31my_general_tests_shared_lib_files := \
32  $(filter-out $(COMPATIBILITY.device-tests.HOST_SHARED_LIBRARY.FILES),\
33	 $(COMPATIBILITY.general-tests.HOST_SHARED_LIBRARY.FILES))
34
35my_host_shared_lib_for_general_tests += $(call copy-many-files,$(my_general_tests_shared_lib_files))
36
37$(general_tests_zip) : PRIVATE_general_tests_list_zip := $(general_tests_list_zip)
38$(general_tests_zip) : .KATI_IMPLICIT_OUTPUTS := $(general_tests_list_zip)
39$(general_tests_zip) : PRIVATE_TOOLS := $(general_tests_tools)
40$(general_tests_zip) : PRIVATE_INTERMEDIATES_DIR := $(intermediates_dir)
41$(general_tests_zip) : PRIVATE_HOST_SHARED_LIBS := $(my_host_shared_lib_for_general_tests)
42$(general_tests_zip) : $(COMPATIBILITY.general-tests.FILES) $(general_tests_tools) $(my_host_shared_lib_for_general_tests) $(SOONG_ZIP)
43	rm -rf $(PRIVATE_INTERMEDIATES_DIR)
44	rm -f $@ $(PRIVATE_general_tests_list_zip)
45	mkdir -p $(PRIVATE_INTERMEDIATES_DIR) $(PRIVATE_INTERMEDIATES_DIR)/tools
46	echo $(sort $(COMPATIBILITY.general-tests.FILES)) | tr " " "\n" > $(PRIVATE_INTERMEDIATES_DIR)/list
47	grep $(HOST_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/list > $(PRIVATE_INTERMEDIATES_DIR)/host.list || true
48	grep $(TARGET_OUT_TESTCASES) $(PRIVATE_INTERMEDIATES_DIR)/list > $(PRIVATE_INTERMEDIATES_DIR)/target.list || true
49	$(hide) for shared_lib in $(PRIVATE_HOST_SHARED_LIBS); do \
50	  echo $$shared_lib >> $(PRIVATE_INTERMEDIATES_DIR)/host.list; \
51	done
52	cp -fp $(PRIVATE_TOOLS) $(PRIVATE_INTERMEDIATES_DIR)/tools/
53	$(SOONG_ZIP) -d -o $@ \
54	  -P host -C $(PRIVATE_INTERMEDIATES_DIR) -D $(PRIVATE_INTERMEDIATES_DIR)/tools \
55	  -P host -C $(HOST_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/host.list \
56	  -P target -C $(PRODUCT_OUT) -l $(PRIVATE_INTERMEDIATES_DIR)/target.list
57	grep -e .*.config$$ $(PRIVATE_INTERMEDIATES_DIR)/host.list | sed s%$(HOST_OUT)%host%g > $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
58	grep -e .*.config$$ $(PRIVATE_INTERMEDIATES_DIR)/target.list | sed s%$(PRODUCT_OUT)%target%g >> $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
59	$(SOONG_ZIP) -d -o $(PRIVATE_general_tests_list_zip) -C $(PRIVATE_INTERMEDIATES_DIR) -f $(PRIVATE_INTERMEDIATES_DIR)/general-tests_list
60
61general-tests: $(general_tests_zip)
62$(call dist-for-goals, general-tests, $(general_tests_zip) $(general_tests_list_zip))
63
64intermediates_dir :=
65general_tests_tools :=
66general_tests_zip :=
67general_tests_list_zip :=
68