1# Java prebuilt coming from Soong.
2# Extra inputs:
3# LOCAL_SOONG_BUILT_INSTALLED
4# LOCAL_SOONG_CLASSES_JAR
5# LOCAL_SOONG_HEADER_JAR
6# LOCAL_SOONG_DEX_JAR
7# LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR
8
9ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
10  $(call pretty-error,soong_java_prebuilt.mk may only be used from Soong)
11endif
12
13LOCAL_MODULE_SUFFIX := .jar
14LOCAL_BUILT_MODULE_STEM := javalib.jar
15
16intermediates.COMMON := $(call local-intermediates-dir,COMMON)
17
18full_classes_jar := $(intermediates.COMMON)/classes.jar
19full_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar
20full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar
21common_javalib.jar := $(intermediates.COMMON)/javalib.jar
22
23ifdef LOCAL_SOONG_AAR
24  LOCAL_ADDITIONAL_CHECKED_MODULE += $(LOCAL_SOONG_AAR)
25endif
26
27#######################################
28include $(BUILD_SYSTEM)/base_rules.mk
29#######################################
30
31ifdef LOCAL_SOONG_CLASSES_JAR
32  $(eval $(call copy-one-file,$(LOCAL_SOONG_CLASSES_JAR),$(full_classes_jar)))
33  $(eval $(call copy-one-file,$(LOCAL_SOONG_CLASSES_JAR),$(full_classes_pre_proguard_jar)))
34  $(eval $(call add-dependency,$(LOCAL_BUILT_MODULE),$(full_classes_jar)))
35
36  ifneq ($(TURBINE_ENABLED),false)
37    ifdef LOCAL_SOONG_HEADER_JAR
38      $(eval $(call copy-one-file,$(LOCAL_SOONG_HEADER_JAR),$(full_classes_header_jar)))
39    else
40      $(eval $(call copy-one-file,$(full_classes_jar),$(full_classes_header_jar)))
41    endif
42  endif # TURBINE_ENABLED != false
43endif
44
45$(eval $(call copy-one-file,$(LOCAL_PREBUILT_MODULE_FILE),$(LOCAL_BUILT_MODULE)))
46
47ifdef LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR
48  $(eval $(call copy-one-file,$(LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR),\
49    $(intermediates.COMMON)/jacoco-report-classes.jar))
50  $(call add-dependency,$(common_javalib.jar),\
51    $(intermediates.COMMON)/jacoco-report-classes.jar)
52endif
53
54ifdef LOCAL_SOONG_PROGUARD_DICT
55  $(eval $(call copy-one-file,$(LOCAL_SOONG_PROGUARD_DICT),\
56    $(intermediates.COMMON)/proguard_dictionary))
57  $(call add-dependency,$(LOCAL_BUILT_MODULE),\
58    $(intermediates.COMMON)/proguard_dictionary)
59endif
60
61ifdef LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE
62  my_res_package := $(intermediates.COMMON)/package-res.apk
63
64  $(my_res_package): $(LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE)
65	@echo "Copy: $@"
66	$(copy-file-to-target)
67
68  $(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_res_package))
69
70  my_proguard_flags := $(intermediates.COMMON)/export_proguard_flags
71  $(my_proguard_flags): $(LOCAL_SOONG_EXPORT_PROGUARD_FLAGS)
72	@echo "Export proguard flags: $@"
73	rm -f $@
74	touch $@
75	for f in $+; do \
76		echo -e "\n# including $$f" >>$@; \
77		cat $$f >>$@; \
78	done
79
80  $(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_proguard_flags))
81
82  my_static_library_extra_packages := $(intermediates.COMMON)/extra_packages
83  $(eval $(call copy-one-file,$(LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES),$(my_static_library_extra_packages)))
84  $(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_static_library_extra_packages))
85
86  my_static_library_android_manifest := $(intermediates.COMMON)/manifest/AndroidManifest.xml
87  $(eval $(call copy-one-file,$(LOCAL_FULL_MANIFEST_FILE),$(my_static_library_android_manifest)))
88  $(call add-dependency,$(LOCAL_BUILT_MODULE),$(my_static_library_android_manifest))
89endif # LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE
90
91
92ifdef LOCAL_SOONG_DEX_JAR
93  ifndef LOCAL_IS_HOST_MODULE
94    boot_jars := $(foreach pair,$(PRODUCT_BOOT_JARS), $(call word-colon,2,$(pair)))
95    ifneq ($(filter $(LOCAL_MODULE),$(boot_jars)),) # is_boot_jar
96      ifeq (true,$(WITH_DEXPREOPT))
97        # $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE_MODULE) contains modules that installs
98        # all of bootjars' dexpreopt files (.art, .oat, .vdex, ...)
99        # Add them to the required list so they are installed alongside this module.
100        ALL_MODULES.$(my_register_name).REQUIRED_FROM_TARGET += \
101          $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE_MODULE) \
102          $(2ND_DEFAULT_DEX_PREOPT_INSTALLED_IMAGE_MODULE)
103        # Copy $(LOCAL_BUILT_MODULE) and its dependencies when installing boot.art
104        # so that dependencies of $(LOCAL_BUILT_MODULE) (which may include
105        # jacoco-report-classes.jar) are copied for every build.
106        $(foreach m,$(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE_MODULE) $(2ND_DEFAULT_DEX_PREOPT_INSTALLED_IMAGE_MODULE), \
107          $(eval $(call add-dependency,$(firstword $(call module-installed-files,$(m))),$(LOCAL_BUILT_MODULE))) \
108        )
109      endif
110    endif # is_boot_jar
111
112    $(eval $(call copy-one-file,$(LOCAL_SOONG_DEX_JAR),$(common_javalib.jar)))
113    $(eval $(call add-dependency,$(LOCAL_BUILT_MODULE),$(common_javalib.jar)))
114    $(eval $(call add-dependency,$(common_javalib.jar),$(full_classes_jar)))
115    ifneq ($(TURBINE_ENABLED),false)
116      $(eval $(call add-dependency,$(common_javalib.jar),$(full_classes_header_jar)))
117    endif
118  endif
119
120  java-dex : $(LOCAL_BUILT_MODULE)
121else  # LOCAL_SOONG_DEX_JAR
122  ifndef LOCAL_UNINSTALLABLE_MODULE
123    ifndef LOCAL_IS_HOST_MODULE
124      $(call pretty-error,Installable device module must have LOCAL_SOONG_DEX_JAR set)
125    endif
126  endif
127endif  # LOCAL_SOONG_DEX_JAR
128
129my_built_installed := $(foreach f,$(LOCAL_SOONG_BUILT_INSTALLED),\
130  $(call word-colon,1,$(f)):$(PRODUCT_OUT)$(call word-colon,2,$(f)))
131my_installed := $(call copy-many-files, $(my_built_installed))
132ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed)
133ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(my_built_installed)
134ALL_MODULES.$(my_register_name).CLASSES_JAR := $(full_classes_jar)
135$(my_register_name): $(my_installed)
136
137ifdef LOCAL_SOONG_AAR
138  ALL_MODULES.$(my_register_name).AAR := $(LOCAL_SOONG_AAR)
139endif
140
141javac-check : $(full_classes_jar)
142javac-check-$(LOCAL_MODULE) : $(full_classes_jar)
143.PHONY: javac-check-$(LOCAL_MODULE)
144
145ifndef LOCAL_IS_HOST_MODULE
146ifeq ($(LOCAL_SDK_VERSION),system_current)
147my_link_type := java:system
148else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION)))
149my_link_type := java:system
150else ifeq ($(LOCAL_SDK_VERSION),core_current)
151my_link_type := java:core
152else ifneq ($(LOCAL_SDK_VERSION),)
153my_link_type := java:sdk
154else
155my_link_type := java:platform
156endif
157# warn/allowed types are both empty because Soong modules can't depend on
158# make-defined modules.
159my_warn_types :=
160my_allowed_types :=
161
162my_link_deps :=
163my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
164my_common := COMMON
165include $(BUILD_SYSTEM)/link_type.mk
166endif # !LOCAL_IS_HOST_MODULE
167
168# LOCAL_EXPORT_SDK_LIBRARIES set by soong is written to exported-sdk-libs file
169my_exported_sdk_libs_file := $(intermediates.COMMON)/exported-sdk-libs
170$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS := $(LOCAL_EXPORT_SDK_LIBRARIES)
171$(my_exported_sdk_libs_file):
172	@echo "Export SDK libs $@"
173	$(hide) mkdir -p $(dir $@) && rm -f $@
174	$(if $(PRIVATE_EXPORTED_SDK_LIBS),\
175		$(hide) echo $(PRIVATE_EXPORTED_SDK_LIBS) | tr ' ' '\n' > $@,\
176		$(hide) touch $@)
177
178SOONG_ALREADY_CONV += $(LOCAL_MODULE)
179