blob: a5ed057993cff9f0d61ecdadd4dc35d53a08f7ce [file] [log] [blame]
Ying Wang956dccc2015-08-28 11:47:03 -07001# Common to host and target Java modules.
2
Colin Cross3277ba32017-12-06 14:37:06 -08003my_soong_problems :=
4
5ifneq ($(filter ../%,$(LOCAL_SRC_FILES)),)
6my_soong_problems += dotdot_srcs
7endif
8
Ying Wang956dccc2015-08-28 11:47:03 -07009###########################################################
Neil Fullerad022512016-01-29 14:22:29 +000010## Java version
11###########################################################
Neil Fullerdecb7972016-03-04 18:00:00 +000012# Use the LOCAL_JAVA_LANGUAGE_VERSION if it is set, otherwise
13# use one based on the LOCAL_SDK_VERSION. If it is < 24
14# pass "1.7" to the tools, if it is unset, >= 24 or "current"
15# pass "1.8".
16#
17# The LOCAL_SDK_VERSION behavior is to ensure that, by default,
18# code that is expected to run on older releases of Android
19# does not use any 1.8 language features that are not supported
20# on earlier runtimes (like default / static interface methods).
21# Modules can override this logic by specifying
22# LOCAL_JAVA_LANGUAGE_VERSION explicitly.
Neil Fullerad022512016-01-29 14:22:29 +000023ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
Colin Cross362f55a2021-11-15 10:58:31 -080024 ifdef LOCAL_IS_HOST_MODULE
25 # Host modules always default to 1.9
Pete Gillin6a88bd42019-10-17 16:21:58 +010026 LOCAL_JAVA_LANGUAGE_VERSION := 1.9
Colin Cross362f55a2021-11-15 10:58:31 -080027 else
Colin Cross82df5162023-09-12 17:56:15 -070028 ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_1_8_SUPPORT)))
Colin Cross362f55a2021-11-15 10:58:31 -080029 LOCAL_JAVA_LANGUAGE_VERSION := 1.7
Colin Cross82df5162023-09-12 17:56:15 -070030 else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_1_9_SUPPORT)))
Colin Cross362f55a2021-11-15 10:58:31 -080031 LOCAL_JAVA_LANGUAGE_VERSION := 1.8
Colin Cross82df5162023-09-12 17:56:15 -070032 else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_11_SUPPORT)))
33 LOCAL_JAVA_LANGUAGE_VERSION := 1.9
34 else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_17_SUPPORT)))
35 LOCAL_JAVA_LANGUAGE_VERSION := 11
Colin Cross362f55a2021-11-15 10:58:31 -080036 else ifneq (,$(LOCAL_SDK_VERSION)$(TARGET_BUILD_USE_PREBUILT_SDKS))
37 # TODO(ccross): allow 1.9 for current and unbundled once we have SDK system modules
38 LOCAL_JAVA_LANGUAGE_VERSION := 1.8
39 else
Colin Cross82df5162023-09-12 17:56:15 -070040 LOCAL_JAVA_LANGUAGE_VERSION := 17
Colin Cross362f55a2021-11-15 10:58:31 -080041 endif
Nicolas Geoffray8d772e22016-02-29 12:07:00 +000042 endif
Neil Fullerad022512016-01-29 14:22:29 +000043endif
44LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
45
46###########################################################
Tobias Thierer7e99d452017-12-20 18:36:56 +000047
48# OpenJDK versions up to 8 shipped with bootstrap and tools jars
49# (rt.jar, jce.jar, tools.jar etc.). These are no longer part of
50# OpenJDK 9, but we still make them available for host tools that
51# are targeting older versions.
52USE_HOST_BOOTSTRAP_JARS := true
53ifeq (,$(filter $(LOCAL_JAVA_LANGUAGE_VERSION), 1.6 1.7 1.8))
54USE_HOST_BOOTSTRAP_JARS := false
55endif
56
57###########################################################
58
59# Drop HOST_JDK_TOOLS_JAR from classpath when targeting versions > 9 (which don't have it).
60# TODO: Remove HOST_JDK_TOOLS_JAR and all references to it once host
61# bootstrap jars are no longer supported (ie. when USE_HOST_BOOTSTRAP_JARS
62# is always false). http://b/38418220
63ifneq ($(USE_HOST_BOOTSTRAP_JARS),true)
64LOCAL_CLASSPATH := $(filter-out $(HOST_JDK_TOOLS_JAR),$(LOCAL_CLASSPATH))
65endif
66
67###########################################################
Ying Wang956dccc2015-08-28 11:47:03 -070068## .proto files: Compile proto files to .java
69###########################################################
Joe Onoratobfc78112017-10-07 23:44:05 -040070ifeq ($(strip $(LOCAL_PROTOC_OPTIMIZE_TYPE)),)
71 LOCAL_PROTOC_OPTIMIZE_TYPE := lite
72endif
Ying Wang956dccc2015-08-28 11:47:03 -070073proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
Ying Wang956dccc2015-08-28 11:47:03 -070074ifneq ($(proto_sources),)
75proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
76
Dan Willemsencf324af2016-12-21 17:37:00 -080077proto_java_intemediate_dir := $(intermediates.COMMON)/proto
Ying Wang956dccc2015-08-28 11:47:03 -070078proto_java_sources_dir := $(proto_java_intemediate_dir)/src
Dan Willemsen84c6c1c2019-06-10 16:31:07 -070079proto_java_srcjar := $(intermediates.COMMON)/proto.srcjar
Ying Wang956dccc2015-08-28 11:47:03 -070080
Dan Willemsen84c6c1c2019-06-10 16:31:07 -070081LOCAL_SRCJARS += $(proto_java_srcjar)
82
83$(proto_java_srcjar): PRIVATE_PROTO_INCLUDES := $(TOP)
84$(proto_java_srcjar): PRIVATE_PROTO_SRC_FILES := $(proto_sources_fullpath)
85$(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_DIR := $(proto_java_sources_dir)
86$(proto_java_srcjar): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
Ying Wang956dccc2015-08-28 11:47:03 -070087ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
Colin Cross869febd2019-08-13 16:57:19 -070088 $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javamicro_out
89 $(proto_java_srcjar): PRIVATE_PROTOC_FLAGS += --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-javamicro
90 $(proto_java_srcjar): $(HOST_OUT_EXECUTABLES)/protoc-gen-javamicro
91else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
92 $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javanano_out
Colin Cross521d4452019-08-13 16:57:56 -070093 $(proto_java_srcjar): PRIVATE_PROTOC_FLAGS += --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-javanano
94 $(proto_java_srcjar): $(HOST_OUT_EXECUTABLES)/protoc-gen-javanano
Colin Cross869febd2019-08-13 16:57:19 -070095else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
96 $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javastream_out
97 $(proto_java_srcjar): PRIVATE_PROTOC_FLAGS += --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-javastream
98 $(proto_java_srcjar): $(HOST_OUT_EXECUTABLES)/protoc-gen-javastream
Ying Wang956dccc2015-08-28 11:47:03 -070099else
Colin Cross869febd2019-08-13 16:57:19 -0700100 $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --java_out
Ying Wang956dccc2015-08-28 11:47:03 -0700101endif
Dan Willemsen84c6c1c2019-06-10 16:31:07 -0700102$(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_PARAMS := $(if $(filter lite,$(LOCAL_PROTOC_OPTIMIZE_TYPE)),lite$(if $(LOCAL_PROTO_JAVA_OUTPUT_PARAMS),:,),)$(LOCAL_PROTO_JAVA_OUTPUT_PARAMS)
103$(proto_java_srcjar) : $(proto_sources_fullpath) $(PROTOC) $(SOONG_ZIP)
Ying Wang956dccc2015-08-28 11:47:03 -0700104 $(call transform-proto-to-java)
105
106#TODO: protoc should output the dependencies introduced by imports.
Ying Wangd5ffec92016-03-01 22:05:25 -0800107
108ALL_MODULES.$(my_register_name).PROTO_FILES := $(proto_sources_fullpath)
Ying Wang956dccc2015-08-28 11:47:03 -0700109endif # proto_sources
110
111#########################################
112## Java resources
113
114# Look for resource files in any specified directories.
115# Non-java and non-doc files will be picked up as resources
116# and included in the output jar file.
117java_resource_file_groups :=
118
119LOCAL_JAVA_RESOURCE_DIRS := $(strip $(LOCAL_JAVA_RESOURCE_DIRS))
120ifneq ($(LOCAL_JAVA_RESOURCE_DIRS),)
121 # This makes a list of words like
122 # <dir1>::<file1>:<file2> <dir2>::<file1> <dir3>:
123 # where each of the files is relative to the directory it's grouped with.
124 # Directories that don't contain any resource files will result in groups
125 # that end with a colon, and they are stripped out in the next step.
126 java_resource_file_groups += \
127 $(foreach dir,$(LOCAL_JAVA_RESOURCE_DIRS), \
128 $(subst $(space),:,$(strip \
129 $(LOCAL_PATH)/$(dir): \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -0700130 $(patsubst ./%,%,$(sort $(shell cd $(LOCAL_PATH)/$(dir) && \
Ying Wang956dccc2015-08-28 11:47:03 -0700131 find . \
132 -type d -a -name ".svn" -prune -o \
133 -type f \
134 -a \! -name "*.java" \
135 -a \! -name "package.html" \
136 -a \! -name "overview.html" \
137 -a \! -name ".*.swp" \
138 -a \! -name ".DS_Store" \
139 -a \! -name "*~" \
140 -print \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -0700141 ))) \
Ying Wang956dccc2015-08-28 11:47:03 -0700142 )) \
143 )
144 java_resource_file_groups := $(filter-out %:,$(java_resource_file_groups))
145endif # LOCAL_JAVA_RESOURCE_DIRS
146
Ying Wang956dccc2015-08-28 11:47:03 -0700147ifneq ($(LOCAL_JAVA_RESOURCE_FILES),)
Colin Cross34a98852017-09-22 13:34:10 -0700148 # Converts LOCAL_JAVA_RESOURCE_FILES := <file> to $(dir $(file))::$(notdir $(file))
149 # and LOCAL_JAVA_RESOURCE_FILES := <dir>:<file> to <dir>::<file>
150 java_resource_file_groups += $(strip $(foreach res,$(LOCAL_JAVA_RESOURCE_FILES), \
151 $(eval _file := $(call word-colon,2,$(res))) \
152 $(if $(_file), \
153 $(eval _base := $(call word-colon,1,$(res))), \
154 $(eval _base := $(dir $(res))) \
155 $(eval _file := $(notdir $(res)))) \
156 $(if $(filter /%, \
157 $(filter-out $(OUT_DIR)/%,$(_base) $(_file))), \
158 $(call pretty-error,LOCAL_JAVA_RESOURCE_FILES may not include absolute paths: $(_base) $(_file))) \
159 $(patsubst %/,%,$(_base))::$(_file)))
160
Ying Wang956dccc2015-08-28 11:47:03 -0700161endif # LOCAL_JAVA_RESOURCE_FILES
162
163ifdef java_resource_file_groups
164 # The full paths to all resources, used for dependencies.
165 java_resource_sources := \
166 $(foreach group,$(java_resource_file_groups), \
167 $(addprefix $(word 1,$(subst :,$(space),$(group)))/, \
168 $(wordlist 2,9999,$(subst :,$(space),$(group))) \
169 ) \
170 )
171 # The arguments to jar that will include these files in a jar file.
172 # Quote the file name to handle special characters (such as #) correctly.
173 extra_jar_args := \
174 $(foreach group,$(java_resource_file_groups), \
175 $(addprefix -C "$(word 1,$(subst :,$(space),$(group)))" , \
176 $(foreach w, $(wordlist 2,9999,$(subst :,$(space),$(group))), "$(w)" ) \
177 ) \
178 )
179 java_resource_file_groups :=
180else
181 java_resource_sources :=
182 extra_jar_args :=
183endif # java_resource_file_groups
184
Ying Wangf8d15d62016-04-26 15:49:56 -0700185#####################################
186## Warn if there is unrecognized file in LOCAL_SRC_FILES.
187my_unknown_src_files := $(filter-out \
Colin Crossb4ee77a2018-03-12 18:23:15 -0700188 %.java %.aidl %.proto %.logtags, \
Ying Wangf8d15d62016-04-26 15:49:56 -0700189 $(LOCAL_SRC_FILES) $(LOCAL_INTERMEDIATE_SOURCES) $(LOCAL_GENERATED_SOURCES))
190ifneq ($(my_unknown_src_files),)
191$(warning $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unknown_src_files))
192endif
193
Ying Wang956dccc2015-08-28 11:47:03 -0700194######################################
195## PRIVATE java vars
196# LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
197# but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
198# You have to set up the dependency in some other way.
Colin Crossf13eb552018-03-07 15:44:54 -0800199need_compile_java := $(strip $(all_java_sources)$(LOCAL_SRCJARS)$(all_res_assets)$(java_resource_sources))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED))
Ying Wang956dccc2015-08-28 11:47:03 -0700200ifdef need_compile_java
201
Colin Crosse8ee68b2017-04-07 16:28:41 -0700202annotation_processor_flags :=
203annotation_processor_deps :=
Colin Crosse46727a2018-06-19 22:50:13 -0700204annotation_processor_jars :=
205
206# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS
207ifeq ($(RUN_ERROR_PRONE),true)
208annotation_processor_jars += $(ERROR_PRONE_JARS)
209LOCAL_JAVACFLAGS += $(ERROR_PRONE_FLAGS)
210LOCAL_JAVACFLAGS += '-Xplugin:ErrorProne $(ERROR_PRONE_CHECKS) $(LOCAL_ERROR_PRONE_FLAGS)'
211endif
Colin Crosse8ee68b2017-04-07 16:28:41 -0700212
213ifdef LOCAL_ANNOTATION_PROCESSORS
Colin Crosse46727a2018-06-19 22:50:13 -0700214 annotation_processor_jars += $(call java-lib-files,$(LOCAL_ANNOTATION_PROCESSORS),true)
Colin Crosse8ee68b2017-04-07 16:28:41 -0700215
216 # b/25860419: annotation processors must be explicitly specified for grok
217 annotation_processor_flags += $(foreach class,$(LOCAL_ANNOTATION_PROCESSOR_CLASSES),-processor $(class))
Colin Crosse46727a2018-06-19 22:50:13 -0700218endif
Colin Crosse8ee68b2017-04-07 16:28:41 -0700219
Colin Crosse46727a2018-06-19 22:50:13 -0700220ifneq (,$(strip $(annotation_processor_jars)))
221annotation_processor_flags += -processorpath $(call normalize-path-list,$(annotation_processor_jars))
222annotation_processor_deps += $(annotation_processor_jars)
Colin Crosse8ee68b2017-04-07 16:28:41 -0700223endif
224
Colin Cross9b2e4c62017-09-26 14:55:43 -0700225full_static_java_libs := $(call java-lib-files,$(LOCAL_STATIC_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
226full_static_java_header_libs := $(call java-lib-header-files,$(LOCAL_STATIC_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
Nan Zhangb3ec5342017-08-31 21:43:04 +0000227
Ying Wang956dccc2015-08-28 11:47:03 -0700228$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000229$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_HEADER_LIBRARIES := $(full_static_java_header_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700230
231$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
232$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
233
234$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
Colin Crosse8ee68b2017-04-07 16:28:41 -0700235$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANNO_INTERMEDIATES_DIR := $(intermediates.COMMON)/anno
Ying Wang956dccc2015-08-28 11:47:03 -0700236$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
Dan Willemsencf324af2016-12-21 17:37:00 -0800237$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES :=
Ying Wang956dccc2015-08-28 11:47:03 -0700238$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
Colin Crossdfc45ec2017-05-26 15:22:02 -0700239$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
Ying Wang956dccc2015-08-28 11:47:03 -0700240
241$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
242
Joel Galenson154ac1d2020-07-30 14:23:31 -0700243# Quickly check class path vars.
Anton Hansson9d030602018-04-12 19:10:03 +0100244disallowed_deps := $(foreach sdk,$(TARGET_AVAILABLE_SDK_VERSIONS),$(call resolve-prebuilt-sdk-module,$(sdk)))
245disallowed_deps += $(foreach sdk,$(TARGET_AVAILABLE_SDK_VERSIONS),\
246 $(foreach sdk_lib,$(JAVA_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,$(sdk),$(sdk_lib))))
247bad_deps := $(filter $(disallowed_deps),$(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES))
248ifneq (,$(bad_deps))
249 $(call pretty-error,SDK modules should not be depended on directly. Please use LOCAL_SDK_VERSION for $(bad_deps))
250endif
251
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700252full_java_bootclasspath_libs :=
253empty_bootclasspath :=
Colin Crossf9602572017-10-12 13:34:40 -0700254my_system_modules :=
Jiyong Park1cf8ee62018-05-22 15:39:59 +0900255exported_sdk_libs_files :=
256my_exported_sdk_libs_file :=
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700257
Ying Wang956dccc2015-08-28 11:47:03 -0700258ifndef LOCAL_IS_HOST_MODULE
Anton Hanssonf5cefdc2018-04-12 16:17:55 +0100259 sdk_libs :=
Anton Hansson8ae30012018-04-24 14:22:51 +0100260
Jiyong Parkcd06fe32018-04-27 16:21:00 +0900261 # When an sdk lib name is listed in LOCAL_JAVA_LIBRARIES, move it to LOCAL_SDK_LIBRARIES, so that
262 # it is correctly redirected to the stubs library.
263 LOCAL_SDK_LIBRARIES += $(filter $(JAVA_SDK_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
264 LOCAL_JAVA_LIBRARIES := $(filter-out $(JAVA_SDK_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
265
Colin Crossf6bc1a12017-09-23 19:47:37 -0700266 ifeq ($(LOCAL_SDK_VERSION),)
267 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
268 # No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700269 empty_bootclasspath := ""
Colin Crossf9602572017-10-12 13:34:40 -0700270 # Most users of LOCAL_NO_STANDARD_LIBRARIES really mean no framework libs,
271 # and manually add back the core libs. The ones that don't are in soong
272 # now, so just always assume that they want the default system modules
Pete Gillin38294752020-07-01 12:44:12 +0100273 my_system_modules := $(LEGACY_CORE_PLATFORM_SYSTEM_MODULES)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700274 else # LOCAL_NO_STANDARD_LIBRARIES
Pete Gillin38294752020-07-01 12:44:12 +0100275 full_java_bootclasspath_libs := $(call java-lib-header-files,$(LEGACY_CORE_PLATFORM_BOOTCLASSPATH_LIBRARIES) $(FRAMEWORK_LIBRARIES))
276 LOCAL_JAVA_LIBRARIES := $(filter-out $(LEGACY_CORE_PLATFORM_BOOTCLASSPATH_LIBRARIES) $(FRAMEWORK_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
277 my_system_modules := $(LEGACY_CORE_PLATFORM_SYSTEM_MODULES)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700278 endif # LOCAL_NO_STANDARD_LIBRARIES
Jiyong Park45bb10c2018-05-03 01:47:35 +0900279
Jeongik Chad05b57a2020-07-08 18:10:38 +0900280 ifneq (,$(TARGET_BUILD_USE_PREBUILT_SDKS))
Jiyong Park45bb10c2018-05-03 01:47:35 +0900281 sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,system_current,$(lib_name)))
282 else
Sundong Ahn2b170412018-05-18 09:55:27 +0900283 # When SDK libraries are referenced from modules built without SDK, provide the all APIs to them
Sundong Ahna9f2ef52018-11-08 18:52:38 +0900284 sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(lib_name))
Jiyong Park45bb10c2018-05-03 01:47:35 +0900285 endif
Colin Crossf6bc1a12017-09-23 19:47:37 -0700286 else
Colin Crossb541aae2017-09-23 19:52:43 -0700287 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
288 $(call pretty-error,Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
289 endif
290 ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
291 $(call pretty-error,Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
292 Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
293 endif
Anton Hansson8ae30012018-04-24 14:22:51 +0100294
Jeongik Chad05b57a2020-07-08 18:10:38 +0900295 ifneq (,$(TARGET_BUILD_USE_PREBUILT_SDKS)$(filter-out %current,$(LOCAL_SDK_VERSION)))
296 # TARGET_BUILD_USE_PREBUILT_SDKS mode or numbered SDK. Use prebuilt modules.
Anton Hansson8ae30012018-04-24 14:22:51 +0100297 sdk_module := $(call resolve-prebuilt-sdk-module,$(LOCAL_SDK_VERSION))
Anton Hanssonf5cefdc2018-04-12 16:17:55 +0100298 sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,$(LOCAL_SDK_VERSION),$(lib_name)))
Anton Hansson8ae30012018-04-24 14:22:51 +0100299 else
300 # Note: the lib naming scheme must be kept in sync with build/soong/java/sdk_library.go.
301 sdk_lib_suffix = $(call pretty-error,sdk_lib_suffix was not set correctly)
302 ifeq (current,$(LOCAL_SDK_VERSION))
Spandan Das0c01c902023-03-20 20:28:25 +0000303 sdk_module := $(ANDROID_PUBLIC_STUBS)
Anton Hansson8ae30012018-04-24 14:22:51 +0100304 sdk_lib_suffix := .stubs
305 else ifeq (system_current,$(LOCAL_SDK_VERSION))
Spandan Das0c01c902023-03-20 20:28:25 +0000306 sdk_module := $(ANDROID_SYSTEM_STUBS)
Anton Hansson8ae30012018-04-24 14:22:51 +0100307 sdk_lib_suffix := .stubs.system
308 else ifeq (test_current,$(LOCAL_SDK_VERSION))
Spandan Das0c01c902023-03-20 20:28:25 +0000309 sdk_module := $(ANDROID_TEST_STUBS)
Jiyong Park6023db82018-04-27 16:23:38 +0900310 sdk_lib_suffix := .stubs.test
Anton Hansson8ae30012018-04-24 14:22:51 +0100311 else ifeq (core_current,$(LOCAL_SDK_VERSION))
Spandan Das0c01c902023-03-20 20:28:25 +0000312 sdk_module := $(ANDROID_CORE_STUBS)
Anton Hansson8ae30012018-04-24 14:22:51 +0100313 sdk_lib_suffix = $(call pretty-error,LOCAL_SDK_LIBRARIES not supported for LOCAL_SDK_VERSION = core_current)
314 endif
315 sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(lib_name)$(sdk_lib_suffix))
316 endif
317 full_java_bootclasspath_libs := $(call java-lib-header-files,$(sdk_module))
Colin Crossf6bc1a12017-09-23 19:47:37 -0700318 endif # LOCAL_SDK_VERSION
Ying Wang956dccc2015-08-28 11:47:03 -0700319
Allen Hair1d226aa2017-10-31 14:05:35 -0700320 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
321 ifneq ($(LOCAL_MODULE),jacocoagent)
322 ifeq ($(EMMA_INSTRUMENT),true)
323 ifneq ($(EMMA_INSTRUMENT_STATIC),true)
324 # For instrumented build, if Jacoco is not being included statically
325 # in instrumented packages then include Jacoco classes into the
326 # bootclasspath.
327 full_java_bootclasspath_libs += $(call java-lib-header-files,jacocoagent)
328 endif # EMMA_INSTRUMENT_STATIC
329 endif # EMMA_INSTRUMENT
330 endif # LOCAL_MODULE == jacocoagent
331 endif # LOCAL_NO_STANDARD_LIBRARIES
332
Colin Crossf6bc1a12017-09-23 19:47:37 -0700333 # In order to compile lambda code javac requires various invokedynamic-
334 # related classes to be present. This change adds stubs needed for
335 # javac to compile lambdas.
Colin Cross5d969a32017-09-22 15:03:38 -0700336 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Jeongik Chad05b57a2020-07-08 18:10:38 +0900337 ifdef TARGET_BUILD_USE_PREBUILT_SDKS
Colin Cross5d969a32017-09-22 15:03:38 -0700338 full_java_bootclasspath_libs += $(call java-lib-header-files,sdk-core-lambda-stubs)
339 else
340 full_java_bootclasspath_libs += $(call java-lib-header-files,core-lambda-stubs)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700341 endif
342 endif
Anton Hanssonf5cefdc2018-04-12 16:17:55 +0100343 full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES) $(sdk_libs),$(LOCAL_IS_HOST_MODULE))
344 full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES) $(sdk_libs),$(LOCAL_IS_HOST_MODULE))
345 sdk_libs :=
Jiyong Park1cf8ee62018-05-22 15:39:59 +0900346
347 # Files that contains the names of SDK libraries exported from dependencies. These will be re-exported.
348 # Note: No need to consider LOCAL_*_ANDROID_LIBRARIES and LOCAL_STATIC_JAVA_AAR_LIBRARIES. They are all appended to
349 # LOCAL_*_JAVA_LIBRARIES in java.mk
350 exported_sdk_libs_files := $(call exported-sdk-libs-files,$(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES))
351 # The file that contains the names of all SDK libraries that this module exports and re-exports
352 my_exported_sdk_libs_file := $(call local-intermediates-dir,COMMON)/exported-sdk-libs
353
Ying Wang956dccc2015-08-28 11:47:03 -0700354else # LOCAL_IS_HOST_MODULE
355
Colin Crossf6bc1a12017-09-23 19:47:37 -0700356 ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
357 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700358 empty_bootclasspath := ""
Colin Crossf6bc1a12017-09-23 19:47:37 -0700359 else
Pete Gillin38294752020-07-01 12:44:12 +0100360 full_java_bootclasspath_libs := $(call java-lib-header-files,$(addsuffix -hostdex,$(LEGACY_CORE_PLATFORM_BOOTCLASSPATH_LIBRARIES)),true)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700361 endif
Ying Wang956dccc2015-08-28 11:47:03 -0700362
Pete Gillin38294752020-07-01 12:44:12 +0100363 my_system_modules := $(LEGACY_CORE_PLATFORM_SYSTEM_MODULES)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700364 full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
365 full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),true)
366 else # !USE_CORE_LIB_BOOTCLASSPATH
Tobias Thierer7e99d452017-12-20 18:36:56 +0000367 # Give host-side tools a version of OpenJDK's standard libraries
368 # close to what they're targeting. As of Dec 2017, AOSP is only
369 # bundling OpenJDK 8 and 9, so nothing < 8 is available.
370 #
371 # When building with OpenJDK 8, the following should have no
372 # effect since those jars would be available by default.
373 #
374 # When building with OpenJDK 9 but targeting a version < 1.8,
375 # putting them on the bootclasspath means that:
376 # a) code can't (accidentally) refer to OpenJDK 9 specific APIs
377 # b) references to existing APIs are not reinterpreted in an
378 # OpenJDK 9-specific way, eg. calls to subclasses of
379 # java.nio.Buffer as in http://b/70862583
380 ifeq ($(USE_HOST_BOOTSTRAP_JARS),true)
381 full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/jce.jar
382 full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/rt.jar
383 endif
Colin Crossf6bc1a12017-09-23 19:47:37 -0700384 full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
385 $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
Colin Cross98caed62017-10-25 17:33:38 -0700386 full_shared_java_header_libs := $(full_shared_java_libs)
Colin Crossf6bc1a12017-09-23 19:47:37 -0700387 endif # USE_CORE_LIB_BOOTCLASSPATH
Ying Wang956dccc2015-08-28 11:47:03 -0700388endif # !LOCAL_IS_HOST_MODULE
389
Jim Tang5c6410e2021-11-03 16:13:05 +0800390# (b/204397180) Record ALL_DEPS by default.
bralee09033622019-01-17 15:11:23 +0800391ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS) $(full_java_bootclasspath_libs)
Jiyong Park1cf8ee62018-05-22 15:39:59 +0900392
393# Export the SDK libs. The sdk library names listed in LOCAL_SDK_LIBRARIES are first exported.
394# Then sdk library names exported from dependencies are all re-exported.
395$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS_FILES := $(exported_sdk_libs_files)
396$(my_exported_sdk_libs_file): PRIVATE_SDK_LIBS := $(sort $(LOCAL_SDK_LIBRARIES))
397$(my_exported_sdk_libs_file): $(exported_sdk_libs_files)
398 @echo "Export SDK libs $@"
399 $(hide) mkdir -p $(dir $@) && rm -f $@ $@.temp
400 $(if $(PRIVATE_SDK_LIBS),\
401 echo $(PRIVATE_SDK_LIBS) | tr ' ' '\n' > $@.temp,\
402 touch $@.temp)
403 $(if $(PRIVATE_EXPORTED_SDK_LIBS_FILES),\
404 cat $(PRIVATE_EXPORTED_SDK_LIBS_FILES) >> $@.temp)
405 $(hide) cat $@.temp | sort -u > $@
406 $(hide) rm -f $@.temp
407
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700408ifdef empty_bootclasspath
409 ifdef full_java_bootclasspath_libs
410 $(call pretty-error,internal error: empty_bootclasspath and full_java_bootclasspath_libs should not both be set)
411 endif
412endif
413
Colin Crossf9602572017-10-12 13:34:40 -0700414full_java_system_modules_deps :=
415my_system_modules_dir :=
416$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES :=
Colin Cross82df5162023-09-12 17:56:15 -0700417ifeq (,$(filter $(LOCAL_JAVA_LANGUAGE_VERSION),$(JAVA_LANGUAGE_VERSIONS_WITHOUT_SYSTEM_MODULES)))
Colin Crossf9602572017-10-12 13:34:40 -0700418 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES := true
419 ifdef my_system_modules
420 ifneq ($(my_system_modules),none)
421 ifndef SOONG_SYSTEM_MODULES_$(my_system_modules)
422 $(call pretty-error, Invalid system modules $(my_system_modules))
423 endif
Dan Willemsen70b934e2019-06-13 16:50:22 +0000424 full_java_system_modules_deps := $(SOONG_SYSTEM_MODULES_DEPS_$(my_system_modules))
425 my_system_modules_dir := $(SOONG_SYSTEM_MODULES_$(my_system_modules))
Colin Crossf9602572017-10-12 13:34:40 -0700426 endif
427 endif
428endif
429
Colin Crossb541aae2017-09-23 19:52:43 -0700430$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(full_java_bootclasspath_libs)
431$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EMPTY_BOOTCLASSPATH := $(empty_bootclasspath)
Tobias Thierer0276db12017-11-01 16:53:09 +0000432$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES := $(my_system_modules)
433$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES_DIR := $(my_system_modules_dir)
434$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES_LIBS := $(call java-lib-files,$(SOONG_SYSTEM_MODULES_LIBS_$(my_system_modules)))
Tobias Thiererf795dcb2018-01-09 20:33:08 +0000435$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PATCH_MODULE := $(LOCAL_PATCH_MODULE)
Colin Cross1d1e5ef2017-09-23 18:19:05 -0700436
Ying Wang956dccc2015-08-28 11:47:03 -0700437ifndef LOCAL_IS_HOST_MODULE
438# This is set by packages that are linking to other packages that export
439# shared libraries, allowing them to make use of the code in the linked apk.
440apk_libraries := $(sort $(LOCAL_APK_LIBRARIES) $(LOCAL_RES_LIBRARIES))
441ifneq ($(apk_libraries),)
Colin Cross9b2e4c62017-09-26 14:55:43 -0700442 link_apk_libraries := $(call app-lib-files,$(apk_libraries))
443 link_apk_header_libs := $(call app-lib-header-files,$(apk_libraries))
Ying Wang956dccc2015-08-28 11:47:03 -0700444
445 # link against the jar with full original names (before proguard processing).
446 full_shared_java_libs += $(link_apk_libraries)
Colin Cross98caed62017-10-25 17:33:38 -0700447 full_shared_java_header_libs += $(link_apk_header_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700448endif
449
450# This is set by packages that contain instrumentation, allowing them to
451# link against the package they are instrumenting. Currently only one such
452# package is allowed.
453LOCAL_INSTRUMENTATION_FOR := $(strip $(LOCAL_INSTRUMENTATION_FOR))
454ifdef LOCAL_INSTRUMENTATION_FOR
455 ifneq ($(words $(LOCAL_INSTRUMENTATION_FOR)),1)
456 $(error \
457 $(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
458 endif
459
460 link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
461 APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
462 # link against the jar with full original names (before proguard processing).
Colin Cross950f1ef2017-04-05 15:30:42 -0700463 link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes-pre-proguard.jar
Colin Cross7dc90432017-09-26 16:17:24 -0700464 ifneq ($(TURBINE_ENABLED),false)
465 link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes-header.jar
466 else
467 link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
468 endif
Colin Cross98caed62017-10-25 17:33:38 -0700469 full_shared_java_libs += $(link_instr_classes_jar)
470 full_shared_java_header_libs += $(link_instr_classes_header_jar)
Ying Wang956dccc2015-08-28 11:47:03 -0700471endif # LOCAL_INSTRUMENTATION_FOR
472endif # LOCAL_IS_HOST_MODULE
473
474endif # need_compile_java
475
476# We may want to add jar manifest or jar resource files even if there is no java code at all.
477$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
478jar_manifest_file :=
479ifneq ($(strip $(LOCAL_JAR_MANIFEST)),)
480jar_manifest_file := $(LOCAL_PATH)/$(LOCAL_JAR_MANIFEST)
481$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST := $(jar_manifest_file)
482else
483$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
484endif
485
486##########################################################
Ying Wang956dccc2015-08-28 11:47:03 -0700487
Colin Cross98caed62017-10-25 17:33:38 -0700488full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
489full_java_header_libs := $(full_shared_java_header_libs) $(full_static_java_header_libs)
490
Ying Wang6f9bd2a2016-03-29 12:41:42 -0700491$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_LIBRARIES := $(full_java_libs)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000492$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
Colin Cross98caed62017-10-25 17:33:38 -0700493$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SHARED_JAVA_HEADER_LIBRARIES := $(full_shared_java_header_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700494
495ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \
496 $(ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR) $(LOCAL_INTERMEDIATE_SOURCE_DIR)
497
Colin Cross579668b2018-08-14 13:13:47 -0700498
499##########################################################
500# Copy NOTICE files of transitive static dependencies
501# Don't do this in mm, since many of the targets won't exist.
Colin Cross579668b2018-08-14 13:13:47 -0700502installed_static_library_notice_file_targets := \
503 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
Jaewoong Junge8cb1952018-11-08 16:53:02 -0800504 NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-JAVA_LIBRARIES-$(lib))
Colin Cross579668b2018-08-14 13:13:47 -0700505
506$(notice_target): | $(installed_static_library_notice_file_targets)
507$(LOCAL_INSTALLED_MODULE): | $(notice_target)
508
Ying Wang956dccc2015-08-28 11:47:03 -0700509###########################################################
Dan Willemsen62dfb592016-07-08 21:33:05 -0700510# Verify that all libraries are safe to use
511###########################################################
512ifndef LOCAL_IS_HOST_MODULE
Dan Willemsen62dfb592016-07-08 21:33:05 -0700513ifeq ($(LOCAL_SDK_VERSION),system_current)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700514my_link_type := java:system
Jiyong Park3d71a082018-02-23 18:12:59 +0900515my_warn_types :=
Jiyong Park5ebca302018-01-31 00:14:55 +0900516my_allowed_types := java:sdk java:system java:core
Sundong Ahn5a44d1f2017-10-16 19:20:34 +0900517else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION)))
518my_link_type := java:system
Jiyong Park3d71a082018-02-23 18:12:59 +0900519my_warn_types :=
Jiyong Park5ebca302018-01-31 00:14:55 +0900520my_allowed_types := java:sdk java:system java:core
521else ifeq ($(LOCAL_SDK_VERSION),core_current)
522my_link_type := java:core
523my_warn_types :=
524my_allowed_types := java:core
Dan Willemsen62dfb592016-07-08 21:33:05 -0700525else ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700526my_link_type := java:sdk
Jiyong Park3d71a082018-02-23 18:12:59 +0900527my_warn_types :=
Jiyong Park5ebca302018-01-31 00:14:55 +0900528my_allowed_types := java:sdk java:core
Dan Willemsen62dfb592016-07-08 21:33:05 -0700529else
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700530my_link_type := java:platform
531my_warn_types :=
Jiyong Park5ebca302018-01-31 00:14:55 +0900532my_allowed_types := java:sdk java:system java:platform java:core
Dan Willemsen62dfb592016-07-08 21:33:05 -0700533endif
Dan Willemsen62dfb592016-07-08 21:33:05 -0700534
Dan Willemsenbb6393c2017-11-17 15:39:52 -0800535my_link_deps := $(addprefix JAVA_LIBRARIES:,$(LOCAL_STATIC_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES))
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700536my_link_deps += $(addprefix APPS:,$(apk_libraries))
537
538my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
539my_common := COMMON
540include $(BUILD_SYSTEM)/link_type.mk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700541endif # !LOCAL_IS_HOST_MODULE
Colin Cross3277ba32017-12-06 14:37:06 -0800542
543ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
544
545SOONG_CONV.$(LOCAL_MODULE).PROBLEMS := \
546 $(SOONG_CONV.$(LOCAL_MODULE).PROBLEMS) $(my_soong_problems)
547SOONG_CONV.$(LOCAL_MODULE).DEPS := \
548 $(SOONG_CONV.$(LOCAL_MODULE).DEPS) \
549 $(LOCAL_STATIC_JAVA_LIBRARIES) \
550 $(LOCAL_JAVA_LIBRARIES) \
551 $(LOCAL_JNI_SHARED_LIBRARIES)
552SOONG_CONV.$(LOCAL_MODULE).TYPE := java
Joe Onorato02fb89a2020-06-27 00:10:23 -0700553SOONG_CONV.$(LOCAL_MODULE).MAKEFILES := \
554 $(SOONG_CONV.$(LOCAL_MODULE).MAKEFILES) $(LOCAL_MODULE_MAKEFILE)
555SOONG_CONV.$(LOCAL_MODULE).INSTALLED := \
556 $(SOONG_CONV.$(LOCAL_MODULE).INSTALLED) $(LOCAL_INSTALLED_MODULE)
Colin Cross3277ba32017-12-06 14:37:06 -0800557SOONG_CONV := $(SOONG_CONV) $(LOCAL_MODULE)
558
559endif