1LOCAL_PATH := $(call my-dir)
2
3#LINT.IfChange
4LOCAL_bluetooth_project_dir := $(LOCAL_PATH)
5
6LOCAL_cert_test_sources := \
7	$(call all-named-files-under,*.py,blueberry) \
8	$(call all-named-files-under,*.yaml,blueberry) \
9	setup.py
10LOCAL_cert_test_sources := \
11	$(filter-out gd_cert_venv% venv%, $(LOCAL_cert_test_sources))
12LOCAL_cert_test_sources := \
13	$(addprefix $(LOCAL_PATH)/, $(LOCAL_cert_test_sources))
14
15LOCAL_host_executables := \
16	$(HOST_OUT_EXECUTABLES)/bluetooth_stack_with_facade \
17	$(HOST_OUT_EXECUTABLES)/bt_topshim_facade \
18	$(HOST_OUT_EXECUTABLES)/root-canal
19
20LOCAL_host_python_hci_packets_library := \
21	$(SOONG_OUT_DIR)/.intermediates/packages/modules/Bluetooth/system/pdl/hci/gd_hci_packets_python3_gen/gen/hci_packets.py
22
23LOCAL_host_python_smp_packets_library := \
24	$(SOONG_OUT_DIR)/.intermediates/packages/modules/Bluetooth/system/pdl/security/gd_smp_packets_python3_gen/gen/smp_packets.py
25
26LOCAL_host_libraries := \
27	$(HOST_OUT_SHARED_LIBRARIES)/libbase.so \
28	$(HOST_OUT_SHARED_LIBRARIES)/libbinder.so \
29	$(HOST_OUT_SHARED_LIBRARIES)/libbinder_ndk.so \
30	$(HOST_OUT_SHARED_LIBRARIES)/libbluetooth.so \
31	$(HOST_OUT_SHARED_LIBRARIES)/libbluetooth_gd.so \
32	$(HOST_OUT_SHARED_LIBRARIES)/libc++.so \
33	$(HOST_OUT_SHARED_LIBRARIES)/libchrome.so \
34	$(HOST_OUT_SHARED_LIBRARIES)/libcrypto-host.so \
35	$(HOST_OUT_SHARED_LIBRARIES)/libcutils.so \
36	$(HOST_OUT_SHARED_LIBRARIES)/libevent-host.so \
37	$(HOST_OUT_SHARED_LIBRARIES)/libflatbuffers-cpp.so \
38	$(HOST_OUT_SHARED_LIBRARIES)/libgrpc++.so \
39	$(HOST_OUT_SHARED_LIBRARIES)/libgrpc_wrap.so \
40	$(HOST_OUT_SHARED_LIBRARIES)/liblog.so \
41	$(HOST_OUT_SHARED_LIBRARIES)/libssl-host.so \
42	$(HOST_OUT_SHARED_LIBRARIES)/libz-host.so \
43	$(HOST_OUT_SHARED_LIBRARIES)/libprotobuf-cpp-full.so \
44	$(HOST_OUT_SHARED_LIBRARIES)/libunwindstack.so \
45	$(HOST_OUT_SHARED_LIBRARIES)/libutils.so \
46	$(HOST_OUT_SHARED_LIBRARIES)/liblzma.so \
47	$(HOST_OUT_SHARED_LIBRARIES)/server_configurable_flags.so
48
49LOCAL_target_executables := \
50	$(TARGET_OUT_EXECUTABLES)/bluetooth_stack_with_facade
51
52LOCAL_target_libraries := \
53	$(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.bluetooth@1.0.so \
54	$(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.bluetooth@1.1.so \
55	$(TARGET_OUT_SHARED_LIBRARIES)/libandroid_runtime_lazy.so \
56	$(TARGET_OUT_SHARED_LIBRARIES)/libbase.so \
57	$(TARGET_OUT_SHARED_LIBRARIES)/libbinder_ndk.so \
58	$(TARGET_OUT_SHARED_LIBRARIES)/libbinder.so \
59	$(TARGET_OUT_SHARED_LIBRARIES)/libc++.so \
60	$(TARGET_OUT_SHARED_LIBRARIES)/libcrypto.so \
61	$(TARGET_OUT_SHARED_LIBRARIES)/libcutils.so \
62	$(TARGET_OUT_SHARED_LIBRARIES)/libgrpc_wrap.so \
63	$(TARGET_OUT_SHARED_LIBRARIES)/libgrpc++.so \
64	$(TARGET_OUT_SHARED_LIBRARIES)/libhidlbase.so \
65	$(TARGET_OUT_SHARED_LIBRARIES)/liblog.so \
66	$(TARGET_OUT_SHARED_LIBRARIES)/liblzma.so \
67	$(TARGET_OUT_SHARED_LIBRARIES)/libprotobuf-cpp-full.so \
68	$(TARGET_OUT_SHARED_LIBRARIES)/libssl.so \
69	$(TARGET_OUT_SHARED_LIBRARIES)/libunwindstack.so \
70	$(TARGET_OUT_SHARED_LIBRARIES)/libutils.so \
71	$(TARGET_OUT_SHARED_LIBRARIES)/libz.so \
72	$(TARGET_OUT_SHARED_LIBRARIES)/server_configurable_flags.so
73	# libclang_rt.asan-aarch64-android.so is only generated for ASAN build and included automatically
74	# on devices
75	# $(TARGET_OUT_SHARED_LIBRARIES)/libclang_rt.asan-aarch64-android.so \
76	# libc.so, libdl_android.so, libdl.so, and libm.so are provided by com.android.runtime APEX
77	# Hence we cannot manually add them here
78	# $(TARGET_OUT_SHARED_LIBRARIES)/libc.so \
79	# $(TARGET_OUT_SHARED_LIBRARIES)/libdl_android.so \
80	# $(TARGET_OUT_SHARED_LIBRARIES)/libdl.so \
81	# $(TARGET_OUT_SHARED_LIBRARIES)/libm.so \
82	# libstatssocket.so is provided by co.android.os.statsd APEX
83	# $(TARGET_OUT_SHARED_LIBRARIES)/libstatssocket.so
84	# linux-vdso.so.1 is always provided by OS
85	# $(TARGET_OUT_SHARED_LIBRARIES)/linux-vdso.so.1
86#LINT.ThenChange(blueberry/tests/gd/cert/gd_device.py)
87
88bluetooth_cert_src_and_bin_zip := \
89	$(call intermediates-dir-for,PACKAGING,bluetooth_cert_src_and_bin,HOST)/bluetooth_cert_src_and_bin.zip
90
91# Assume 64-bit OS
92$(bluetooth_cert_src_and_bin_zip): PRIVATE_bluetooth_project_dir := $(LOCAL_bluetooth_project_dir)
93$(bluetooth_cert_src_and_bin_zip): PRIVATE_cert_test_sources := $(LOCAL_cert_test_sources)
94$(bluetooth_cert_src_and_bin_zip): PRIVATE_host_executables := $(LOCAL_host_executables)
95$(bluetooth_cert_src_and_bin_zip): PRIVATE_host_libraries := $(LOCAL_host_libraries)
96$(bluetooth_cert_src_and_bin_zip): PRIVATE_host_python_hci_packets_library := $(LOCAL_host_python_hci_packets_library)
97$(bluetooth_cert_src_and_bin_zip): PRIVATE_host_python_smp_packets_library := $(LOCAL_host_python_smp_packets_library)
98$(bluetooth_cert_src_and_bin_zip): PRIVATE_target_executables := $(LOCAL_target_executables)
99$(bluetooth_cert_src_and_bin_zip): PRIVATE_target_libraries := $(LOCAL_target_libraries)
100$(bluetooth_cert_src_and_bin_zip): $(SOONG_ZIP) $(LOCAL_cert_test_sources) \
101		$(LOCAL_host_executables) $(LOCAL_host_libraries) $(LOCAL_host_python_libraries) \
102		$(LOCAL_host_python_hci_packets_library) \
103		$(LOCAL_host_python_smp_packets_library) \
104		$(LOCAL_target_executables) $(LOCAL_target_libraries)
105	$(hide) $(SOONG_ZIP) -d -o $@ \
106		-C $(PRIVATE_bluetooth_project_dir) $(addprefix -f ,$(PRIVATE_cert_test_sources)) \
107		-C $(dir $(PRIVATE_host_python_hci_packets_library)) -f $(PRIVATE_host_python_hci_packets_library) \
108		-C $(dir $(PRIVATE_host_python_smp_packets_library)) -f $(PRIVATE_host_python_smp_packets_library) \
109		-C $(HOST_OUT_EXECUTABLES) $(addprefix -f ,$(PRIVATE_host_executables)) \
110		-P lib64 \
111		-C $(HOST_OUT_SHARED_LIBRARIES) $(addprefix -f ,$(PRIVATE_host_libraries)) \
112		-P target \
113		-C $(TARGET_OUT_EXECUTABLES) $(addprefix -f ,$(PRIVATE_target_executables)) \
114		-C $(TARGET_OUT_SHARED_LIBRARIES) $(addprefix -f ,$(PRIVATE_target_libraries))
115
116$(call declare-container-license-metadata,$(bluetooth_cert_src_and_bin_zip),\
117    SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD SPDX-license-identifier-MIT legacy_unencumbered,\
118    notice, $(LOCAL_PATH)/../NOTICE,,packages/modules/Bluetooth)
119$(call declare-container-license-deps,$(bluetooth_cert_src_and_bin_zip),\
120    $(LOCAL_target_executables) $(LOCAL_target_libraries),$(bluetooth_cert_src_and_bin_zip):)
121
122# TODO: Find a better way to locate output from SOONG genrule()
123LOCAL_facade_generated_py_zip := \
124	$(SOONG_OUT_DIR)/.intermediates/packages/modules/Bluetooth/system/BlueberryFacadeAndCertGeneratedStub_py/gen/blueberry_facade_generated_py.zip
125
126bluetooth_cert_tests_py_package_zip := \
127	$(call intermediates-dir-for,PACKAGING,bluetooth_cert_tests_py_package,HOST)/bluetooth_cert_tests.zip
128
129$(bluetooth_cert_tests_py_package_zip): PRIVATE_bluetooth_project_dir := $(LOCAL_bluetooth_project_dir)
130$(bluetooth_cert_tests_py_package_zip): PRIVATE_cert_src_and_bin_zip := $(bluetooth_cert_src_and_bin_zip)
131$(bluetooth_cert_tests_py_package_zip): PRIVATE_facade_generated_py_zip := $(LOCAL_facade_generated_py_zip)
132$(bluetooth_cert_tests_py_package_zip): $(SOONG_ZIP) \
133		$(bluetooth_cert_src_and_bin_zip) $(bluetooth_cert_generated_py_zip)
134	@echo "Packaging Bluetooth Cert Tests into $@"
135	@rm -rf $(dir $@)bluetooth_cert_tests
136	@mkdir -p $(dir $@)bluetooth_cert_tests
137	$(hide) unzip -o -q $(PRIVATE_cert_src_and_bin_zip) -d $(dir $@)bluetooth_cert_tests
138	$(hide) unzip -o -q $(PRIVATE_facade_generated_py_zip) -d $(dir $@)bluetooth_cert_tests
139	# Make all subdirectory Python packages except lib64 and target
140	$(hide) for f in `find $(dir $@)bluetooth_cert_tests -type d -name "*" \
141					-not -path "$(dir $@)bluetooth_cert_tests/target*" \
142					-not -path "$(dir $@)bluetooth_cert_tests/lib64*"` \
143			; do (touch -a $$f/__init__.py) ; done
144	$(hide) $(SOONG_ZIP) -d -o $@ -C $(dir $@)bluetooth_cert_tests -D $(dir $@)bluetooth_cert_tests \
145		-P llvm_binutils -C $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION) \
146		-f $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-cov \
147		-f $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-profdata \
148		-f $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/bin/llvm-symbolizer \
149		-f $(LLVM_PREBUILTS_BASE)/linux-x86/$(LLVM_PREBUILTS_VERSION)/lib/x86_64-unknown-linux-gnu/libc++.so
150
151$(call declare-container-license-metadata,$(bluetooth_cert_tests_py_package_zip),\
152    SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD SPDX-license-identifier-MIT legacy_unencumbered,\
153    notice, $(LOCAL_PATH)/../NOTICE,,packages/modules/Bluetooth)
154$(call declare-container-license-deps,$(bluetooth_cert_tests_py_package_zip),\
155    $(bluetooth_cert_src_and_bin_zip) $(bluetooth_cert_generated_py_zip),$(bluetooth_cert_tests_py_package_zip):)
156
157$(call dist-for-goals,bluetooth_stack_with_facade,$(bluetooth_cert_tests_py_package_zip):bluetooth_cert_tests.zip)
158