1# 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
22jack_lib := $(intermediates)/classes.jack
23dex_toc := $(intermediates)/classes.dex.toc
24full_src_target = $(intermediates)/android-stubs-src.jar
25src_dir := $(intermediates)/src
26classes_dir := $(intermediates)/classes
27framework_res_package := $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
28
29$(full_target) $(jack_lib) $(full_src_target): PRIVATE_SRC_DIR := $(src_dir)
30$(full_target) $(jack_lib) $(full_src_target): PRIVATE_INTERMEDIATES_DIR := $(intermediates)
31$(full_target) $(jack_lib): PRIVATE_FRAMEWORK_RES_PACKAGE := $(framework_res_package)
32
33$(full_target): PRIVATE_CLASS_INTERMEDIATES_DIR := $(classes_dir)
34
35$(full_src_target): $(stub_timestamp)
36	@echo Packaging SDK Stub sources: $@
37	$(hide) cd $(PRIVATE_INTERMEDIATES_DIR) && zip -rq $(notdir $@) $(notdir $(PRIVATE_SRC_DIR))
38
39$(full_target): $(stub_timestamp) $(framework_res_package)
40	@echo Compiling SDK Stubs: $@
41	$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
42	$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
43	$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)/NOTICES
44	$(hide) if [ ! -f libcore/NOTICE ]; then \
45	echo "Missing notice file : libcore/NOTICE"; \
46	rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
47	exit 1; \
48	fi;
49	$(hide) if [ ! -f libcore/ojluni/NOTICE ]; then \
50	echo "Missing notice file : libcore/ojluni/NOTICE"; \
51	rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
52	exit 1; \
53	fi;
54	$(hide) $(ACP) libcore/NOTICE $(PRIVATE_CLASS_INTERMEDIATES_DIR)/NOTICES/libcore-NOTICE
55	$(hide) $(ACP) libcore/ojluni/NOTICE $(PRIVATE_CLASS_INTERMEDIATES_DIR)/NOTICES/ojluni-NOTICE
56	$(hide) find $(PRIVATE_SRC_DIR) -name "*.java" > \
57        $(PRIVATE_INTERMEDIATES_DIR)/java-source-list
58	$(hide) $(TARGET_JAVAC) -source 1.8 -target 1.8 -encoding ascii -bootclasspath "" \
59			-g -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
60			\@$(PRIVATE_INTERMEDIATES_DIR)/java-source-list \
61		|| ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
62	$(hide) if [ ! -f $(PRIVATE_FRAMEWORK_RES_PACKAGE) ]; then \
63		echo Missing file $(PRIVATE_FRAMEWORK_RES_PACKAGE); \
64		rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
65		exit 1; \
66	fi;
67	$(hide) unzip -qo $(PRIVATE_FRAMEWORK_RES_PACKAGE) -d $(PRIVATE_CLASS_INTERMEDIATES_DIR)
68	$(hide) (cd $(PRIVATE_CLASS_INTERMEDIATES_DIR) && rm -rf classes.dex META-INF)
69	$(hide) mkdir -p $(dir $@)
70	$(hide) jar -cf $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
71	$(hide) jar -u0f $@ -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) resources.arsc
72
73$(jack_lib) : $(stub_timestamp) $(framework_res_package) $(JACK) | setup-jack-server
74	@echo Compiling SDK Stubs with Jack: $@
75	rm -rf $(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.tmp
76	$(hide) if [ ! -f $(PRIVATE_FRAMEWORK_RES_PACKAGE) ]; then \
77		echo Missing file $(PRIVATE_FRAMEWORK_RES_PACKAGE); \
78		rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR); \
79		exit 1; \
80	fi;
81	mkdir -p $(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.tmp
82	$(hide) unzip -qo $(PRIVATE_FRAMEWORK_RES_PACKAGE) -d $(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.tmp
83	$(hide) mkdir -p $(dir $@)
84	$(hide) find $(PRIVATE_SRC_DIR) -name "*.java" > \
85		$(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.java-source-list
86	$(call call-jack) \
87		-D jack.java.source.version=1.8 \
88		-D jack.android.min-api-level=$(PLATFORM_JACK_MIN_SDK_VERSION) \
89		--import-resource $(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.tmp \
90		--output-jack $@ \
91		@$(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.java-source-list \
92		|| ( rm -f $@ ; $(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.tmp ; exit 41 )
93	$(hide) rm -rf $(PRIVATE_INTERMEDIATES_DIR)/jack-rsc.tmp
94
95$(call define-jar-to-toc-rule, $(full_target))
96
97# As we don't have .dex file for the SDK stub, we cannot generate .toc
98# file from .dex file. Use .toc file generated from .jar instead.
99$(dex_toc): $(full_target).toc $(jack_lib)
100	$(hide) cp $< $@.tmp
101	$(call commit-change-for-toc, $@)
102.KATI_RESTAT: $(dex_toc)
103