1# Common to host and target Java modules.
2
3my_soong_problems :=
4
5ifneq ($(filter ../%,$(LOCAL_SRC_FILES)),)
6my_soong_problems += dotdot_srcs
7endif
8
9ifneq (,$(LOCAL_JNI_SHARED_LIBRARIES))
10my_soong_problems += jni_libs
11endif
12
13###########################################################
14## Java version
15###########################################################
16# Use the LOCAL_JAVA_LANGUAGE_VERSION if it is set, otherwise
17# use one based on the LOCAL_SDK_VERSION. If it is < 24
18# pass "1.7" to the tools, if it is unset, >= 24 or "current"
19# pass "1.8".
20#
21# The LOCAL_SDK_VERSION behavior is to ensure that, by default,
22# code that is expected to run on older releases of Android
23# does not use any 1.8 language features that are not supported
24# on earlier runtimes (like default / static interface methods).
25# Modules can override this logic by specifying
26# LOCAL_JAVA_LANGUAGE_VERSION explicitly.
27ifeq (,$(LOCAL_JAVA_LANGUAGE_VERSION))
28  ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_18_SUPPORT)))
29    LOCAL_JAVA_LANGUAGE_VERSION := 1.7
30  else ifneq (,$(filter $(LOCAL_SDK_VERSION), $(TARGET_SDK_VERSIONS_WITHOUT_JAVA_19_SUPPORT)))
31    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
32  else ifneq (,$(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS_USE_PREBUILT_SDK))
33    # TODO(ccross): allow 1.9 for current and unbundled once we have SDK system modules
34    LOCAL_JAVA_LANGUAGE_VERSION := 1.8
35  else
36    LOCAL_JAVA_LANGUAGE_VERSION := 1.9
37  endif
38endif
39LOCAL_JAVACFLAGS += -source $(LOCAL_JAVA_LANGUAGE_VERSION) -target $(LOCAL_JAVA_LANGUAGE_VERSION)
40
41###########################################################
42
43# OpenJDK versions up to 8 shipped with bootstrap and tools jars
44# (rt.jar, jce.jar, tools.jar etc.). These are no longer part of
45# OpenJDK 9, but we still make them available for host tools that
46# are targeting older versions.
47USE_HOST_BOOTSTRAP_JARS := true
48ifeq (,$(filter $(LOCAL_JAVA_LANGUAGE_VERSION), 1.6 1.7 1.8))
49USE_HOST_BOOTSTRAP_JARS := false
50endif
51
52###########################################################
53
54# Drop HOST_JDK_TOOLS_JAR from classpath when targeting versions > 9 (which don't have it).
55# TODO: Remove HOST_JDK_TOOLS_JAR and all references to it once host
56# bootstrap jars are no longer supported (ie. when USE_HOST_BOOTSTRAP_JARS
57# is always false). http://b/38418220
58ifneq ($(USE_HOST_BOOTSTRAP_JARS),true)
59LOCAL_CLASSPATH := $(filter-out $(HOST_JDK_TOOLS_JAR),$(LOCAL_CLASSPATH))
60endif
61
62###########################################################
63## .proto files: Compile proto files to .java
64###########################################################
65ifeq ($(strip $(LOCAL_PROTOC_OPTIMIZE_TYPE)),)
66  LOCAL_PROTOC_OPTIMIZE_TYPE := lite
67endif
68proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
69ifneq ($(proto_sources),)
70proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
71
72proto_java_intemediate_dir := $(intermediates.COMMON)/proto
73proto_java_sources_dir := $(proto_java_intemediate_dir)/src
74proto_java_srcjar := $(intermediates.COMMON)/proto.srcjar
75
76LOCAL_SRCJARS += $(proto_java_srcjar)
77
78$(proto_java_srcjar): PRIVATE_PROTO_INCLUDES := $(TOP)
79$(proto_java_srcjar): PRIVATE_PROTO_SRC_FILES := $(proto_sources_fullpath)
80$(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_DIR := $(proto_java_sources_dir)
81$(proto_java_srcjar): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
82ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
83  $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javamicro_out
84  $(proto_java_srcjar): PRIVATE_PROTOC_FLAGS += --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-javamicro
85  $(proto_java_srcjar): $(HOST_OUT_EXECUTABLES)/protoc-gen-javamicro
86else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
87  $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javanano_out
88  $(proto_java_srcjar): PRIVATE_PROTOC_FLAGS += --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-javanano
89  $(proto_java_srcjar): $(HOST_OUT_EXECUTABLES)/protoc-gen-javanano
90else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),stream)
91  $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javastream_out
92  $(proto_java_srcjar): PRIVATE_PROTOC_FLAGS += --plugin=$(HOST_OUT_EXECUTABLES)/protoc-gen-javastream
93  $(proto_java_srcjar): $(HOST_OUT_EXECUTABLES)/protoc-gen-javastream
94else
95  $(proto_java_srcjar): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --java_out
96endif
97$(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)
98$(proto_java_srcjar) : $(proto_sources_fullpath) $(PROTOC) $(SOONG_ZIP)
99	$(call transform-proto-to-java)
100
101#TODO: protoc should output the dependencies introduced by imports.
102
103ALL_MODULES.$(my_register_name).PROTO_FILES := $(proto_sources_fullpath)
104endif # proto_sources
105
106#########################################
107## Java resources
108
109# Look for resource files in any specified directories.
110# Non-java and non-doc files will be picked up as resources
111# and included in the output jar file.
112java_resource_file_groups :=
113
114LOCAL_JAVA_RESOURCE_DIRS := $(strip $(LOCAL_JAVA_RESOURCE_DIRS))
115ifneq ($(LOCAL_JAVA_RESOURCE_DIRS),)
116  # This makes a list of words like
117  #     <dir1>::<file1>:<file2> <dir2>::<file1> <dir3>:
118  # where each of the files is relative to the directory it's grouped with.
119  # Directories that don't contain any resource files will result in groups
120  # that end with a colon, and they are stripped out in the next step.
121  java_resource_file_groups += \
122    $(foreach dir,$(LOCAL_JAVA_RESOURCE_DIRS), \
123	$(subst $(space),:,$(strip \
124		$(LOCAL_PATH)/$(dir): \
125	    $(patsubst ./%,%,$(sort $(shell cd $(LOCAL_PATH)/$(dir) && \
126		find . \
127		    -type d -a -name ".svn" -prune -o \
128		    -type f \
129			-a \! -name "*.java" \
130			-a \! -name "package.html" \
131			-a \! -name "overview.html" \
132			-a \! -name ".*.swp" \
133			-a \! -name ".DS_Store" \
134			-a \! -name "*~" \
135			-print \
136		    ))) \
137	)) \
138    )
139  java_resource_file_groups := $(filter-out %:,$(java_resource_file_groups))
140endif # LOCAL_JAVA_RESOURCE_DIRS
141
142ifneq ($(LOCAL_JAVA_RESOURCE_FILES),)
143  # Converts LOCAL_JAVA_RESOURCE_FILES := <file> to $(dir $(file))::$(notdir $(file))
144  # and LOCAL_JAVA_RESOURCE_FILES := <dir>:<file> to <dir>::<file>
145  java_resource_file_groups += $(strip $(foreach res,$(LOCAL_JAVA_RESOURCE_FILES), \
146    $(eval _file := $(call word-colon,2,$(res))) \
147    $(if $(_file), \
148      $(eval _base := $(call word-colon,1,$(res))), \
149      $(eval _base := $(dir $(res))) \
150        $(eval _file := $(notdir $(res)))) \
151    $(if $(filter /%, \
152      $(filter-out $(OUT_DIR)/%,$(_base) $(_file))), \
153        $(call pretty-error,LOCAL_JAVA_RESOURCE_FILES may not include absolute paths: $(_base) $(_file))) \
154    $(patsubst %/,%,$(_base))::$(_file)))
155
156endif # LOCAL_JAVA_RESOURCE_FILES
157
158ifdef java_resource_file_groups
159  # The full paths to all resources, used for dependencies.
160  java_resource_sources := \
161    $(foreach group,$(java_resource_file_groups), \
162	$(addprefix $(word 1,$(subst :,$(space),$(group)))/, \
163	    $(wordlist 2,9999,$(subst :,$(space),$(group))) \
164	) \
165    )
166  # The arguments to jar that will include these files in a jar file.
167  # Quote the file name to handle special characters (such as #) correctly.
168  extra_jar_args := \
169    $(foreach group,$(java_resource_file_groups), \
170	$(addprefix -C "$(word 1,$(subst :,$(space),$(group)))" , \
171	    $(foreach w, $(wordlist 2,9999,$(subst :,$(space),$(group))), "$(w)" ) \
172	) \
173    )
174  java_resource_file_groups :=
175else
176  java_resource_sources :=
177  extra_jar_args :=
178endif # java_resource_file_groups
179
180#####################################
181## Warn if there is unrecognized file in LOCAL_SRC_FILES.
182my_unknown_src_files := $(filter-out \
183  %.java %.aidl %.proto %.logtags, \
184  $(LOCAL_SRC_FILES) $(LOCAL_INTERMEDIATE_SOURCES) $(LOCAL_GENERATED_SOURCES))
185ifneq ($(my_unknown_src_files),)
186$(warning $(LOCAL_MODULE_MAKEFILE): $(LOCAL_MODULE): Unused source files: $(my_unknown_src_files))
187endif
188
189######################################
190## PRIVATE java vars
191# LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
192# but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
193# You have to set up the dependency in some other way.
194need_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))
195ifdef need_compile_java
196
197annotation_processor_flags :=
198annotation_processor_deps :=
199annotation_processor_jars :=
200
201# If error prone is enabled then add LOCAL_ERROR_PRONE_FLAGS to LOCAL_JAVACFLAGS
202ifeq ($(RUN_ERROR_PRONE),true)
203annotation_processor_jars += $(ERROR_PRONE_JARS)
204LOCAL_JAVACFLAGS += $(ERROR_PRONE_FLAGS)
205LOCAL_JAVACFLAGS += '-Xplugin:ErrorProne $(ERROR_PRONE_CHECKS) $(LOCAL_ERROR_PRONE_FLAGS)'
206endif
207
208ifdef LOCAL_ANNOTATION_PROCESSORS
209  annotation_processor_jars += $(call java-lib-files,$(LOCAL_ANNOTATION_PROCESSORS),true)
210
211  # b/25860419: annotation processors must be explicitly specified for grok
212  annotation_processor_flags += $(foreach class,$(LOCAL_ANNOTATION_PROCESSOR_CLASSES),-processor $(class))
213endif
214
215ifneq (,$(strip $(annotation_processor_jars)))
216annotation_processor_flags += -processorpath $(call normalize-path-list,$(annotation_processor_jars))
217annotation_processor_deps += $(annotation_processor_jars)
218endif
219
220full_static_java_libs := $(call java-lib-files,$(LOCAL_STATIC_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
221full_static_java_header_libs := $(call java-lib-header-files,$(LOCAL_STATIC_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
222
223$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
224$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_HEADER_LIBRARIES := $(full_static_java_header_libs)
225
226$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
227$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
228
229$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
230$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANNO_INTERMEDIATES_DIR := $(intermediates.COMMON)/anno
231$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
232$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_HAS_RS_SOURCES :=
233$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
234$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCE_LIST := $(java_source_list_file)
235
236$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
237
238# Sanity check class path vars.
239disallowed_deps := $(foreach sdk,$(TARGET_AVAILABLE_SDK_VERSIONS),$(call resolve-prebuilt-sdk-module,$(sdk)))
240disallowed_deps += $(foreach sdk,$(TARGET_AVAILABLE_SDK_VERSIONS),\
241  $(foreach sdk_lib,$(JAVA_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,$(sdk),$(sdk_lib))))
242bad_deps := $(filter $(disallowed_deps),$(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES))
243ifneq (,$(bad_deps))
244  $(call pretty-error,SDK modules should not be depended on directly. Please use LOCAL_SDK_VERSION for $(bad_deps))
245endif
246
247full_java_bootclasspath_libs :=
248empty_bootclasspath :=
249my_system_modules :=
250exported_sdk_libs_files :=
251my_exported_sdk_libs_file :=
252
253ifndef LOCAL_IS_HOST_MODULE
254  sdk_libs :=
255
256  # When an sdk lib name is listed in LOCAL_JAVA_LIBRARIES, move it to LOCAL_SDK_LIBRARIES, so that
257  # it is correctly redirected to the stubs library.
258  LOCAL_SDK_LIBRARIES += $(filter $(JAVA_SDK_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
259  LOCAL_JAVA_LIBRARIES := $(filter-out $(JAVA_SDK_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
260
261  ifeq ($(LOCAL_SDK_VERSION),)
262    ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
263      # No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
264      empty_bootclasspath := ""
265      # Most users of LOCAL_NO_STANDARD_LIBRARIES really mean no framework libs,
266      # and manually add back the core libs.  The ones that don't are in soong
267      # now, so just always assume that they want the default system modules
268      my_system_modules := $(DEFAULT_SYSTEM_MODULES)
269    else  # LOCAL_NO_STANDARD_LIBRARIES
270      full_java_bootclasspath_libs := $(call java-lib-header-files,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES))
271      LOCAL_JAVA_LIBRARIES := $(filter-out $(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES) $(TARGET_DEFAULT_JAVA_LIBRARIES),$(LOCAL_JAVA_LIBRARIES))
272      my_system_modules := $(DEFAULT_SYSTEM_MODULES)
273    endif  # LOCAL_NO_STANDARD_LIBRARIES
274
275    ifneq (,$(TARGET_BUILD_APPS_USE_PREBUILT_SDK))
276      sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,system_current,$(lib_name)))
277    else
278      # When SDK libraries are referenced from modules built without SDK, provide the all APIs to them
279      sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(lib_name))
280    endif
281  else
282    ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
283      $(call pretty-error,Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
284    endif
285    ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
286      $(call pretty-error,Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
287             Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
288    endif
289
290    ifneq (,$(TARGET_BUILD_APPS_USE_PREBUILT_SDK)$(filter-out %current,$(LOCAL_SDK_VERSION)))
291      # TARGET_BUILD_APPS mode or numbered SDK. Use prebuilt modules.
292      sdk_module := $(call resolve-prebuilt-sdk-module,$(LOCAL_SDK_VERSION))
293      sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(call resolve-prebuilt-sdk-module,$(LOCAL_SDK_VERSION),$(lib_name)))
294    else
295      # Note: the lib naming scheme must be kept in sync with build/soong/java/sdk_library.go.
296      sdk_lib_suffix = $(call pretty-error,sdk_lib_suffix was not set correctly)
297      ifeq (current,$(LOCAL_SDK_VERSION))
298        sdk_module := android_stubs_current
299        sdk_lib_suffix := .stubs
300      else ifeq (system_current,$(LOCAL_SDK_VERSION))
301        sdk_module := android_system_stubs_current
302        sdk_lib_suffix := .stubs.system
303      else ifeq (test_current,$(LOCAL_SDK_VERSION))
304        sdk_module := android_test_stubs_current
305        sdk_lib_suffix := .stubs.test
306      else ifeq (core_current,$(LOCAL_SDK_VERSION))
307        sdk_module := core.current.stubs
308        sdk_lib_suffix = $(call pretty-error,LOCAL_SDK_LIBRARIES not supported for LOCAL_SDK_VERSION = core_current)
309      endif
310      sdk_libs := $(foreach lib_name,$(LOCAL_SDK_LIBRARIES),$(lib_name)$(sdk_lib_suffix))
311    endif
312    full_java_bootclasspath_libs := $(call java-lib-header-files,$(sdk_module))
313  endif # LOCAL_SDK_VERSION
314
315  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
316    ifneq ($(LOCAL_MODULE),jacocoagent)
317      ifeq ($(EMMA_INSTRUMENT),true)
318        ifneq ($(EMMA_INSTRUMENT_STATIC),true)
319          # For instrumented build, if Jacoco is not being included statically
320          # in instrumented packages then include Jacoco classes into the
321          # bootclasspath.
322          full_java_bootclasspath_libs += $(call java-lib-header-files,jacocoagent)
323        endif # EMMA_INSTRUMENT_STATIC
324      endif # EMMA_INSTRUMENT
325    endif # LOCAL_MODULE == jacocoagent
326  endif # LOCAL_NO_STANDARD_LIBRARIES
327
328  # In order to compile lambda code javac requires various invokedynamic-
329  # related classes to be present. This change adds stubs needed for
330  # javac to compile lambdas.
331  ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
332    ifdef TARGET_BUILD_APPS_USE_PREBUILT_SDK
333      full_java_bootclasspath_libs += $(call java-lib-header-files,sdk-core-lambda-stubs)
334    else
335      full_java_bootclasspath_libs += $(call java-lib-header-files,core-lambda-stubs)
336    endif
337  endif
338  full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES) $(sdk_libs),$(LOCAL_IS_HOST_MODULE))
339  full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES) $(sdk_libs),$(LOCAL_IS_HOST_MODULE))
340  sdk_libs :=
341
342  # Files that contains the names of SDK libraries exported from dependencies. These will be re-exported.
343  # Note: No need to consider LOCAL_*_ANDROID_LIBRARIES and LOCAL_STATIC_JAVA_AAR_LIBRARIES. They are all appended to
344  # LOCAL_*_JAVA_LIBRARIES in java.mk
345  exported_sdk_libs_files := $(call exported-sdk-libs-files,$(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES))
346  # The file that contains the names of all SDK libraries that this module exports and re-exports
347  my_exported_sdk_libs_file := $(call local-intermediates-dir,COMMON)/exported-sdk-libs
348
349else # LOCAL_IS_HOST_MODULE
350
351  ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
352    ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
353      empty_bootclasspath := ""
354    else
355      full_java_bootclasspath_libs := $(call java-lib-header-files,$(addsuffix -hostdex,$(TARGET_DEFAULT_BOOTCLASSPATH_LIBRARIES)),true)
356    endif
357
358    my_system_modules := $(DEFAULT_SYSTEM_MODULES)
359    full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),true)
360    full_shared_java_header_libs := $(call java-lib-header-files,$(LOCAL_JAVA_LIBRARIES),true)
361  else # !USE_CORE_LIB_BOOTCLASSPATH
362    # Give host-side tools a version of OpenJDK's standard libraries
363    # close to what they're targeting. As of Dec 2017, AOSP is only
364    # bundling OpenJDK 8 and 9, so nothing < 8 is available.
365    #
366    # When building with OpenJDK 8, the following should have no
367    # effect since those jars would be available by default.
368    #
369    # When building with OpenJDK 9 but targeting a version < 1.8,
370    # putting them on the bootclasspath means that:
371    # a) code can't (accidentally) refer to OpenJDK 9 specific APIs
372    # b) references to existing APIs are not reinterpreted in an
373    #    OpenJDK 9-specific way, eg. calls to subclasses of
374    #    java.nio.Buffer as in http://b/70862583
375    ifeq ($(USE_HOST_BOOTSTRAP_JARS),true)
376      full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/jce.jar
377      full_java_bootclasspath_libs += $(ANDROID_JAVA8_HOME)/jre/lib/rt.jar
378    endif
379    full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
380      $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
381    full_shared_java_header_libs := $(full_shared_java_libs)
382  endif # USE_CORE_LIB_BOOTCLASSPATH
383endif # !LOCAL_IS_HOST_MODULE
384
385ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS) $(full_java_bootclasspath_libs)
386
387# Export the SDK libs. The sdk library names listed in LOCAL_SDK_LIBRARIES are first exported.
388# Then sdk library names exported from dependencies are all re-exported.
389$(my_exported_sdk_libs_file): PRIVATE_EXPORTED_SDK_LIBS_FILES := $(exported_sdk_libs_files)
390$(my_exported_sdk_libs_file): PRIVATE_SDK_LIBS := $(sort $(LOCAL_SDK_LIBRARIES))
391$(my_exported_sdk_libs_file): $(exported_sdk_libs_files)
392	@echo "Export SDK libs $@"
393	$(hide) mkdir -p $(dir $@) && rm -f $@ $@.temp
394	$(if $(PRIVATE_SDK_LIBS),\
395		echo $(PRIVATE_SDK_LIBS) | tr ' ' '\n' > $@.temp,\
396		touch $@.temp)
397	$(if $(PRIVATE_EXPORTED_SDK_LIBS_FILES),\
398		cat $(PRIVATE_EXPORTED_SDK_LIBS_FILES) >> $@.temp)
399	$(hide) cat $@.temp | sort -u > $@
400	$(hide) rm -f $@.temp
401
402ifdef empty_bootclasspath
403  ifdef full_java_bootclasspath_libs
404    $(call pretty-error,internal error: empty_bootclasspath and full_java_bootclasspath_libs should not both be set)
405  endif
406endif
407
408full_java_system_modules_deps :=
409my_system_modules_dir :=
410$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES :=
411ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.9)
412  $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_USE_SYSTEM_MODULES := true
413  ifdef my_system_modules
414    ifneq ($(my_system_modules),none)
415      ifndef SOONG_SYSTEM_MODULES_$(my_system_modules)
416        $(call pretty-error, Invalid system modules $(my_system_modules))
417      endif
418      full_java_system_modules_deps := $(SOONG_SYSTEM_MODULES_DEPS_$(my_system_modules))
419      my_system_modules_dir := $(SOONG_SYSTEM_MODULES_$(my_system_modules))
420    endif
421  endif
422endif
423
424$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := $(full_java_bootclasspath_libs)
425$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EMPTY_BOOTCLASSPATH := $(empty_bootclasspath)
426$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES := $(my_system_modules)
427$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES_DIR := $(my_system_modules_dir)
428$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SYSTEM_MODULES_LIBS := $(call java-lib-files,$(SOONG_SYSTEM_MODULES_LIBS_$(my_system_modules)))
429$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PATCH_MODULE := $(LOCAL_PATCH_MODULE)
430
431ifndef LOCAL_IS_HOST_MODULE
432# This is set by packages that are linking to other packages that export
433# shared libraries, allowing them to make use of the code in the linked apk.
434apk_libraries := $(sort $(LOCAL_APK_LIBRARIES) $(LOCAL_RES_LIBRARIES))
435ifneq ($(apk_libraries),)
436  link_apk_libraries := $(call app-lib-files,$(apk_libraries))
437  link_apk_header_libs := $(call app-lib-header-files,$(apk_libraries))
438
439  # link against the jar with full original names (before proguard processing).
440  full_shared_java_libs += $(link_apk_libraries)
441  full_shared_java_header_libs += $(link_apk_header_libs)
442endif
443
444# This is set by packages that contain instrumentation, allowing them to
445# link against the package they are instrumenting.  Currently only one such
446# package is allowed.
447LOCAL_INSTRUMENTATION_FOR := $(strip $(LOCAL_INSTRUMENTATION_FOR))
448ifdef LOCAL_INSTRUMENTATION_FOR
449  ifneq ($(words $(LOCAL_INSTRUMENTATION_FOR)),1)
450    $(error \
451        $(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
452  endif
453
454  link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
455      APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
456  # link against the jar with full original names (before proguard processing).
457  link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes-pre-proguard.jar
458  ifneq ($(TURBINE_ENABLED),false)
459    link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes-header.jar
460  else
461    link_instr_classes_header_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
462  endif
463  full_shared_java_libs += $(link_instr_classes_jar)
464  full_shared_java_header_libs += $(link_instr_classes_header_jar)
465endif  # LOCAL_INSTRUMENTATION_FOR
466endif  # LOCAL_IS_HOST_MODULE
467
468endif  # need_compile_java
469
470# We may want to add jar manifest or jar resource files even if there is no java code at all.
471$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
472jar_manifest_file :=
473ifneq ($(strip $(LOCAL_JAR_MANIFEST)),)
474jar_manifest_file := $(LOCAL_PATH)/$(LOCAL_JAR_MANIFEST)
475$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST := $(jar_manifest_file)
476else
477$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
478endif
479
480##########################################################
481
482full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
483full_java_header_libs := $(full_shared_java_header_libs) $(full_static_java_header_libs)
484
485$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_LIBRARIES := $(full_java_libs)
486$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ALL_JAVA_HEADER_LIBRARIES := $(full_java_header_libs)
487$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SHARED_JAVA_HEADER_LIBRARIES := $(full_shared_java_header_libs)
488
489ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \
490    $(ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR) $(LOCAL_INTERMEDIATE_SOURCE_DIR)
491
492
493##########################################################
494# Copy NOTICE files of transitive static dependencies
495# Don't do this in mm, since many of the targets won't exist.
496installed_static_library_notice_file_targets := \
497    $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
498      NOTICE-$(if $(LOCAL_IS_HOST_MODULE),HOST$(if $(my_host_cross),_CROSS,),TARGET)-JAVA_LIBRARIES-$(lib))
499
500$(notice_target): | $(installed_static_library_notice_file_targets)
501$(LOCAL_INSTALLED_MODULE): | $(notice_target)
502
503###########################################################
504# Verify that all libraries are safe to use
505###########################################################
506ifndef LOCAL_IS_HOST_MODULE
507ifeq ($(LOCAL_SDK_VERSION),system_current)
508my_link_type := java:system
509my_warn_types :=
510my_allowed_types := java:sdk java:system java:core
511else ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION)))
512my_link_type := java:system
513my_warn_types :=
514my_allowed_types := java:sdk java:system java:core
515else ifeq ($(LOCAL_SDK_VERSION),core_current)
516my_link_type := java:core
517my_warn_types :=
518my_allowed_types := java:core
519else ifneq ($(LOCAL_SDK_VERSION),)
520my_link_type := java:sdk
521my_warn_types :=
522my_allowed_types := java:sdk java:core
523else
524my_link_type := java:platform
525my_warn_types :=
526my_allowed_types := java:sdk java:system java:platform java:core
527endif
528
529my_link_deps := $(addprefix JAVA_LIBRARIES:,$(LOCAL_STATIC_JAVA_LIBRARIES) $(LOCAL_JAVA_LIBRARIES))
530my_link_deps += $(addprefix APPS:,$(apk_libraries))
531
532my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
533my_common := COMMON
534include $(BUILD_SYSTEM)/link_type.mk
535endif  # !LOCAL_IS_HOST_MODULE
536
537ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
538
539SOONG_CONV.$(LOCAL_MODULE).PROBLEMS := \
540    $(SOONG_CONV.$(LOCAL_MODULE).PROBLEMS) $(my_soong_problems)
541SOONG_CONV.$(LOCAL_MODULE).DEPS := \
542    $(SOONG_CONV.$(LOCAL_MODULE).DEPS) \
543    $(LOCAL_STATIC_JAVA_LIBRARIES) \
544    $(LOCAL_JAVA_LIBRARIES) \
545    $(LOCAL_JNI_SHARED_LIBRARIES)
546SOONG_CONV.$(LOCAL_MODULE).TYPE := java
547SOONG_CONV := $(SOONG_CONV) $(LOCAL_MODULE)
548
549endif
550