blob: 393b21328a875253c7696b154b21ac6ef95feb21 [file] [log] [blame]
Ying Wang78e75a92014-06-03 10:40:10 -07001# Build an SDK jar file out of the generated stubs
2# Input variable:
3# sdk_stub_name: the name of the SDK stubs; the stub source code should have been generated to
4# $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/$(sdk_stub_name)_intermediates.
5# stub_timestamp: the timestamp file we use as dependency of the generated source.
6# Output variable:
7# full_target: the built classes.jar
8
9# The source files for this library are _all_ generated, something we don't do
10# anywhere else, and the rules don't support. Aditionally, the depenencies on
11# these files don't really matter, because they are all generated as part of
12# building the docs. So for the dependency, we just use the
13# api-stubs-timestamp file, which is the $@ of the droiddoc rule.
14# We also need to depend on framework-res.apk, in order to pull the
15# resource files out of there for aapt.
16#
17# Normally the package rule runs aapt, which includes the resource,
18# but we're not running that in our package rule so just copy in the
19# resource files here.
20intermediates := $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/$(sdk_stub_name)_intermediates
21full_target := $(intermediates)/classes.jar
Nan Zhangc8861182017-08-31 21:36:04 +000022header_target := $(intermediates)/classes-header.jar
Narayan Kamathe54bbd82016-02-05 13:56:15 +000023full_src_target = $(intermediates)/android-stubs-src.jar
Ying Wang78e75a92014-06-03 10:40:10 -070024src_dir := $(intermediates)/src
25classes_dir := $(intermediates)/classes
26framework_res_package := $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
27
Colin Cross8b341962017-10-02 12:23:58 -070028$(full_target) $(full_src_target): PRIVATE_SRC_DIR := $(src_dir)
29$(full_target) $(full_src_target): PRIVATE_INTERMEDIATES_DIR := $(intermediates)
30$(full_target): PRIVATE_FRAMEWORK_RES_PACKAGE := $(framework_res_package)
Yohann Roussele9dcc692016-01-06 13:55:10 +010031
Ying Wang78e75a92014-06-03 10:40:10 -070032$(full_target): PRIVATE_CLASS_INTERMEDIATES_DIR := $(classes_dir)
Ying Wang78e75a92014-06-03 10:40:10 -070033
Andreas Gampebd405952018-01-30 18:23:53 -080034# Disable all warnings. For one, stubs are auto-generated and lack annotations currently. Second,
35# any warnings should have been emitted for the stub sources.
36ifeq (true,$(RUN_ERROR_PRONE))
37$(full_target): PRIVATE_ERRORPRONE_FLAGS := -XepDisableAllChecks
38else
39$(full_target): PRIVATE_ERRORPRONE_FLAGS :=
40endif
41
Colin Cross41e49c32018-07-02 11:29:03 -070042my_use_metalava := $(filter metalava%,$(sdk_stub_name))
43$(warning $(sdk_stub_name) $(my_use_metalava))
44
45ifdef my_use_metalava
Nan Zhang3a1dcff2018-06-06 19:01:05 -070046$(full_target): $(HOST_OUT_JAVA_LIBRARIES)/stub-annotations$(COMMON_JAVA_PACKAGE_SUFFIX)
47$(full_target): PRIVATE_METALAVA_CLASSPATH := -classpath $(HOST_OUT_JAVA_LIBRARIES)/stub-annotations$(COMMON_JAVA_PACKAGE_SUFFIX)
Colin Cross41e49c32018-07-02 11:29:03 -070048$(full_target): $(HOST_OUT_JAVA_LIBRARIES)/metalava.jar
Nan Zhang3a1dcff2018-06-06 19:01:05 -070049else
50$(full_target): PRIVATE_METALAVA_CLASSPATH :=
51endif
52
Narayan Kamathe54bbd82016-02-05 13:56:15 +000053$(full_src_target): $(stub_timestamp)
54 @echo Packaging SDK Stub sources: $@
55 $(hide) cd $(PRIVATE_INTERMEDIATES_DIR) && zip -rq $(notdir $@) $(notdir $(PRIVATE_SRC_DIR))
56
Nan Zhangc8861182017-08-31 21:36:04 +000057$(full_target): $(stub_timestamp) $(framework_res_package) $(ZIPTIME)
Ying Wang78e75a92014-06-03 10:40:10 -070058 @echo Compiling SDK Stubs: $@
59 $(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
60 $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
Narayan Kamatha9453262016-02-05 14:33:29 +000061 $(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)/NOTICES
62 $(hide) if [ ! -f libcore/NOTICE ]; then \
63 echo "Missing notice file : libcore/NOTICE"; \
64 rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
65 exit 1; \
66 fi;
67 $(hide) if [ ! -f libcore/ojluni/NOTICE ]; then \
68 echo "Missing notice file : libcore/ojluni/NOTICE"; \
69 rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
70 exit 1; \
71 fi;
72 $(hide) $(ACP) libcore/NOTICE $(PRIVATE_CLASS_INTERMEDIATES_DIR)/NOTICES/libcore-NOTICE
73 $(hide) $(ACP) libcore/ojluni/NOTICE $(PRIVATE_CLASS_INTERMEDIATES_DIR)/NOTICES/ojluni-NOTICE
Ying Wang78e75a92014-06-03 10:40:10 -070074 $(hide) find $(PRIVATE_SRC_DIR) -name "*.java" > \
Andreas Gampebd405952018-01-30 18:23:53 -080075 $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
76 $(hide) $(TARGET_JAVAC) $(PRIVATE_ERRORPRONE_FLAGS) \
Nan Zhang3a1dcff2018-06-06 19:01:05 -070077 -source 1.8 -target 1.8 -encoding UTF-8 -bootclasspath "" $(PRIVATE_METALAVA_CLASSPATH) \
Tobias Thierer9870de62017-07-18 16:09:42 +010078 -g -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
Ying Wang78e75a92014-06-03 10:40:10 -070079 \@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list \
80 || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
Colin Cross41e49c32018-07-02 11:29:03 -070081ifdef my_use_metalava
82 $(hide) $(JAVA) -jar $(HOST_OUT_JAVA_LIBRARIES)/metalava.jar \
83 --no-banner --rewrite-annotations $(PRIVATE_CLASS_INTERMEDIATES_DIR)
84endif
Ying Wang78e75a92014-06-03 10:40:10 -070085 $(hide) if [ ! -f $(PRIVATE_FRAMEWORK_RES_PACKAGE) ]; then \
86 echo Missing file $(PRIVATE_FRAMEWORK_RES_PACKAGE); \
87 rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
88 exit 1; \
89 fi;
90 $(hide) unzip -qo $(PRIVATE_FRAMEWORK_RES_PACKAGE) -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)
91 $(hide) (cd $(PRIVATE_CLASS_INTERMEDIATES_DIR) && rm -rf classes.dex META-INF)
92 $(hide) mkdir -p $(dir $@)
Nan Zhangc8861182017-08-31 21:36:04 +000093 $(hide) jar -cf $@.tmp -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
94 $(hide) jar -u0f $@.tmp -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) resources.arsc
95 $(hide) $(ZIPTIME) $@.tmp
96 $(hide) $(call commit-change-for-toc,$@)
97
98.KATI_RESTAT: $(full_target)
Yohann Roussel83efd5e2014-09-08 14:48:26 +020099
Nan Zhangc8861182017-08-31 21:36:04 +0000100$(eval $(call copy-one-file,$(full_target),$(header_target)))