1# Copyright (C) 2015 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#
16# Input variables
17#
18# $(support_module) - name of the support library module
19# $(support_module_api_dir) - dir to store API files
20# $(support_module_java_libraries) - dependent libraries
21# $(support_module_java_packages) - list of package names containing public classes
22# $(support_module_src_files) - list of source files
23# $(support_module_aidl_includes) - list of aidl files
24# $(api_check_current_msg_file) - file containing error message for current API check
25# $(api_check_last_msg_file) - file containing error message for last SDK API check
26# ---------------------------------------------
27
28#
29# Generate the stub source files
30# ---------------------------------------------
31include $(CLEAR_VARS)
32
33support_module_api_file := \
34    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(support_module)_api.txt
35support_module_removed_file := \
36    $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/$(support_module)_removed.txt
37
38LOCAL_MODULE := $(support_module)-stubs
39LOCAL_MODULE_CLASS := JAVA_LIBRARIES
40LOCAL_MODULE_TAGS := optional
41
42LOCAL_SRC_FILES := $(support_module_src_files)
43LOCAL_AIDL_INCLUDES := $(support_module_aidl_includes)
44LOCAL_JAVA_LIBRARIES := $(support_module_java_libraries)
45LOCAL_ADDITIONAL_JAVA_DIR := \
46    $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(support_module),,COMMON)/src
47LOCAL_SDK_VERSION := $(SUPPORT_CURRENT_SDK_VERSION)
48
49LOCAL_DROIDDOC_STUB_OUT_DIR := $(TARGET_OUT_COMMON_INTERMEDIATES)/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/src
50
51LOCAL_DROIDDOC_OPTIONS:= \
52    -stubpackages "$(subst $(space),:,$(support_module_java_packages))" \
53    -api $(support_module_api_file) \
54    -removedApi $(support_module_removed_file) \
55    -nodocs
56
57LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR := build/tools/droiddoc/templates-sdk
58LOCAL_UNINSTALLABLE_MODULE := true
59
60include $(BUILD_DROIDDOC)
61support_stub_stamp := $(full_target)
62$(support_module_api_file) : $(full_target)
63
64#
65# Check API
66# ---------------------------------------------
67last_released_sdk_$(support_module) := $(lastword $(call numerically_sort, \
68    $(filter-out current, \
69        $(patsubst $(support_module_api_dir)/%.txt,%, $(wildcard $(support_module_api_dir)/*.txt)) \
70    )))
71
72# Check that the API we're building hasn't broken the last-released SDK version
73# if it exists
74ifneq ($(last_released_sdk_$(support_module)),)
75$(eval $(call check-api, \
76    $(support_module)-checkapi-last, \
77    $(support_module_api_dir)/$(last_released_sdk_$(support_module)).txt, \
78    $(support_module_api_file), \
79    $(support_module_api_dir)/removed.txt, \
80    $(support_module_removed_file), \
81    -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 -hide 26 -hide 27 \
82        -warning 7 -warning 8 -warning 9 -warning 10 -warning 11 -warning 12 \
83        -warning 13 -warning 14 -warning 15 -warning 16 -warning 17 -warning 18, \
84    cat $(api_check_last_msg_file), \
85    check-support-api, \
86    $(support_stub_stamp)))
87endif
88
89# Check that the API we're building hasn't changed from the not-yet-released
90# SDK version.
91$(eval $(call check-api, \
92    $(support_module)-checkapi-current, \
93    $(support_module_api_dir)/current.txt, \
94    $(support_module_api_file), \
95    $(support_module_api_dir)/removed.txt, \
96    $(support_module_removed_file), \
97    -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 \
98        -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 \
99        -error 21 -error 23 -error 24 -error 25, \
100    cat $(api_check_current_msg_file), \
101    check-support-api, \
102    $(support_stub_stamp)))
103
104.PHONY: update-$(support_module)-api
105update-$(support_module)-api: PRIVATE_API_DIR := $(support_module_api_dir)
106update-$(support_module)-api: PRIVATE_MODULE := $(support_module)
107update-$(support_module)-api: PRIVATE_REMOVED_API_FILE := $(support_module_removed_file)
108update-$(support_module)-api: $(support_module_api_file) | $(ACP)
109	@echo Copying $(PRIVATE_MODULE) current.txt
110	$(hide) $(ACP) $< $(PRIVATE_API_DIR)/current.txt
111	@echo Copying $(PRIVATE_MODULE) removed.txt
112	$(hide) $(ACP) $(PRIVATE_REMOVED_API_FILE) $(PRIVATE_API_DIR)/removed.txt
113
114# Run this update API task on the update-support-api task
115update-support-api: update-$(support_module)-api
116
117#
118# Clear variables
119# ---------------------------------------------
120support_module :=
121support_module_api_dir :=
122support_module_src_files :=
123support_module_aidl_includes :=
124support_module_java_libraries :=
125support_module_java_packages :=
126support_module_api_file :=
127support_module_removed_file :=
128support_stub_stamp :=
129