1# -*- mode: makefile -*- 2# Copyright (C) 2007 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# 17# Definitions for building the Java library and associated tests. 18# 19 20# 21# Common definitions for host and target. 22# 23 24# libcore is divided into modules. 25# 26# The structure of each module is: 27# 28# src/ 29# main/ # To be shipped on every device. 30# java/ # Java source for library code. 31# native/ # C++ source for library code. 32# resources/ # Support files. 33# test/ # Built only on demand, for testing. 34# java/ # Java source for tests. 35# native/ # C++ source for tests (rare). 36# resources/ # Support files. 37# 38# All subdirectories are optional (hence the "2> /dev/null"s below). 39 40define all-test-java-files-under 41$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && (find $(dir)/src/test/java -name "*.java" 2> /dev/null) | grep -v -f java_tests_blacklist))) 42endef 43 44define all-core-resource-dirs 45$(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/{java,resources} 2> /dev/null) 46endef 47 48# The Java files and their associated resources. 49core_resource_dirs := \ 50 luni/src/main/java \ 51 ojluni/src/main/resources/ 52test_resource_dirs := $(filter-out ojluni/%,$(call all-core-resource-dirs,test)) 53test_src_files := $(call all-test-java-files-under,dalvik dalvik/test-rules dom harmony-tests json luni xml) 54ojtest_src_files := $(call all-test-java-files-under,ojluni) 55ojtest_resource_dirs := $(filter ojluni/%,$(call all-core-resource-dirs,test)) 56 57ifeq ($(EMMA_INSTRUMENT),true) 58ifneq ($(EMMA_INSTRUMENT_STATIC),true) 59 nojcore_src_files += $(call all-java-files-under, ../external/emma/core ../external/emma/pregenerated) 60 core_resource_dirs += ../external/emma/core/res ../external/emma/pregenerated/res 61endif 62endif 63 64local_javac_flags=-encoding UTF-8 65#local_javac_flags+=-Xlint:all -Xlint:-serial,-deprecation,-unchecked 66local_javac_flags+=-Xmaxwarns 9999999 67 68# For user / userdebug builds, strip the local variable table and the local variable 69# type table. This has no bearing on stack traces, but will leave less information 70# available via JDWP. 71# 72# TODO: Should this be conditioned on a PRODUCT_ flag or should we just turn this 73# on for all builds. Also, name of the flag TBD. 74ifneq (,$(PRODUCT_MINIMIZE_JAVA_DEBUG_INFO)) 75ifneq (,$(filter userdebug user,$(TARGET_BUILD_VARIANT))) 76local_javac_flags+= -g:source,lines 77local_jack_flags+= -D jack.dex.debug.vars=false -D jack.dex.debug.vars.synthetic=false 78endif 79endif 80 81# 82# ICU4J related rules. 83# 84# We compile android_icu4j along with core-libart because we're implementing parts of core-libart 85# in terms of android_icu4j. 86android_icu4j_root := ../external/icu/android_icu4j/ 87android_icu4j_src_files := $(call all-java-files-under,$(android_icu4j_root)/src/main/java) 88android_icu4j_resource_dirs := $(android_icu4j_root)/resources 89 90# 91# Build jaif-annotated source files for ojluni target . 92# 93ojluni_annotate_dir := $(call intermediates-dir-for,JAVA_LIBRARIES,core-oj,,COMMON)/annotated 94ojluni_annotate_target := $(ojluni_annotate_dir)/timestamp 95ojluni_annotate_jaif := $(LOCAL_PATH)/annotations/ojluni.jaif 96ojluni_annotate_input := $(annotated_ojluni_files) 97ojluni_annotate_output := $(patsubst $(LOCAL_PATH)/ojluni/src/main/java/%, $(ojluni_annotate_dir)/%, $(ojluni_annotate_input)) 98 99$(ojluni_annotate_target): PRIVATE_ANNOTATE_TARGET := $(ojluni_annotate_target) 100$(ojluni_annotate_target): PRIVATE_ANNOTATE_DIR := $(ojluni_annotate_dir) 101$(ojluni_annotate_target): PRIVATE_ANNOTATE_JAIF := $(ojluni_annotate_jaif) 102$(ojluni_annotate_target): PRIVATE_ANNOTATE_INPUT := $(ojluni_annotate_input) 103$(ojluni_annotate_target): PRIVATE_ANNOTATE_GENERATE_CMD := $(LOCAL_PATH)/annotations/generate_annotated_java_files.py 104$(ojluni_annotate_target): PRIVATE_ANNOTATE_GENERATE_OUTPUT := $(LOCAL_PATH)/annotated_java_files.bp 105$(ojluni_annotate_target): PRIVATE_INSERT_ANNOTATIONS_TO_SOURCE := external/annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source 106 107# Diff output of _ojluni_annotate_generate_cmd with what we have, and if generate annotated source. 108$(ojluni_annotate_target): $(ojluni_annotate_input) $(ojluni_annotate_jaif) 109 rm -rf $(PRIVATE_ANNOTATE_DIR) 110 mkdir -p $(PRIVATE_ANNOTATE_DIR) 111 $(PRIVATE_ANNOTATE_GENERATE_CMD) $(PRIVATE_ANNOTATE_JAIF) > $(PRIVATE_ANNOTATE_DIR)/annotated_java_files.bp.tmp 112 diff -u $(PRIVATE_ANNOTATE_GENERATE_OUTPUT) $(PRIVATE_ANNOTATE_DIR)/annotated_java_files.bp.tmp || \ 113 (echo -e "********************" >&2; \ 114 echo -e "annotated_java_files.bp needs regenerating. Please run:" >&2; \ 115 echo -e "libcore/annotations/generate_annotated_java_files.py libcore/annotations/ojluni.jaif > libcore/annotated_java_files.bp" >&2; \ 116 echo -e "********************" >&2; exit 1) 117 rm $(PRIVATE_ANNOTATE_DIR)/annotated_java_files.bp.tmp 118 $(PRIVATE_INSERT_ANNOTATIONS_TO_SOURCE) -d $(PRIVATE_ANNOTATE_DIR) $(PRIVATE_ANNOTATE_JAIF) $(PRIVATE_ANNOTATE_INPUT) 119 touch $@ 120$(ojluni_annotate_target): .KATI_IMPLICIT_OUTPUTS := $(ojluni_annotate_output) 121 122ojluni_annotate_dir:= 123ojluni_annotate_target:= 124ojluni_annotate_jaif:= 125ojluni_annotate_input:= 126ojluni_annotate_output:= 127 128# 129# Build for the target (device). 130# 131ifeq ($(LIBCORE_SKIP_TESTS),) 132# Build a library just containing files from luni/src/test/filesystems for use in tests. 133include $(CLEAR_VARS) 134LOCAL_SRC_FILES := $(call all-java-files-under, luni/src/test/filesystems/src) 135LOCAL_JAVA_RESOURCE_DIRS := luni/src/test/filesystems/resources 136LOCAL_NO_STANDARD_LIBRARIES := true 137LOCAL_MODULE := filesystemstest 138LOCAL_JAVA_LIBRARIES := core-oj core-libart 139LOCAL_DEX_PREOPT := false 140LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 141include $(BUILD_JAVA_LIBRARY) 142 143filesystemstest_jar := $(intermediates)/$(LOCAL_MODULE).jar 144$(filesystemstest_jar): $(LOCAL_BUILT_MODULE) 145 $(call copy-file-to-target) 146 147# Build a library just containing files from luni/src/test/parameter_metadata for use in tests. 148include $(CLEAR_VARS) 149LOCAL_SRC_FILES := $(call all-java-files-under, luni/src/test/parameter_metadata/src) 150LOCAL_NO_STANDARD_LIBRARIES := true 151LOCAL_MODULE := parameter-metadata-test 152LOCAL_JAVA_LIBRARIES := core-oj core-libart 153LOCAL_DEX_PREOPT := false 154LOCAL_JAVACFLAGS := -parameters 155LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 156include $(BUILD_JAVA_LIBRARY) 157 158parameter_metadata_test_jar := $(intermediates)/$(LOCAL_MODULE).jar 159$(parameter_metadata_test_jar): $(LOCAL_BUILT_MODULE) 160 $(call copy-file-to-target) 161 162endif 163 164ifeq ($(LIBCORE_SKIP_TESTS),) 165# Make the core-tests library. 166include $(CLEAR_VARS) 167LOCAL_SRC_FILES := $(test_src_files) 168LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs) 169# Include individual dex.jar files (jars containing resources and a classes.dex) so that they 170# be loaded by tests using ClassLoaders but are not in the main classes.dex. 171LOCAL_JAVA_RESOURCE_FILES := $(filesystemstest_jar) $(parameter_metadata_test_jar) 172LOCAL_NO_STANDARD_LIBRARIES := true 173LOCAL_JAVA_LIBRARIES := core-oj core-libart okhttp bouncycastle 174LOCAL_STATIC_JAVA_LIBRARIES := \ 175 archive-patcher \ 176 core-test-rules \ 177 core-tests-support \ 178 junit-params \ 179 mockftpserver \ 180 mockito-target \ 181 mockwebserver \ 182 nist-pkix-tests \ 183 slf4j-jdk14 \ 184 sqlite-jdbc \ 185 tzdata-testing 186LOCAL_JAVACFLAGS := $(local_javac_flags) 187LOCAL_JACK_FLAGS := $(local_jack_flags) 188LOCAL_ERROR_PRONE_FLAGS := \ 189 -Xep:TryFailThrowable:ERROR \ 190 -Xep:ComparisonOutOfRange:ERROR \ 191 -Xep:MissingOverride:OFF 192LOCAL_MODULE := core-tests 193include $(BUILD_STATIC_JAVA_LIBRARY) 194endif 195 196# Make the core-ojtests library. 197ifeq ($(LIBCORE_SKIP_TESTS),) 198 include $(CLEAR_VARS) 199 LOCAL_JAVA_RESOURCE_DIRS := $(ojtest_resource_dirs) 200 LOCAL_NO_STANDARD_LIBRARIES := true 201 LOCAL_JAVA_LIBRARIES := core-oj core-libart okhttp bouncycastle 202 LOCAL_STATIC_JAVA_LIBRARIES := testng 203 LOCAL_JAVACFLAGS := $(local_javac_flags) 204 LOCAL_JACK_FLAGS := $(local_jack_flags) 205 LOCAL_DX_FLAGS := --core-library 206 LOCAL_MODULE_TAGS := optional 207 LOCAL_MODULE := core-ojtests 208 # jack bug workaround: int[] java.util.stream.StatefulTestOp.-getjava-util-stream-StreamShapeSwitchesValues() is a private synthetic method in an interface which causes a hard verifier error 209 LOCAL_DEX_PREOPT := false # disable AOT preverification which breaks the build. it will still throw VerifyError at runtime. 210 LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 211 include $(BUILD_JAVA_LIBRARY) 212endif 213 214# Make the core-ojtests-public library. Excludes any private API tests. 215ifeq ($(LIBCORE_SKIP_TESTS),) 216 include $(CLEAR_VARS) 217 # Filter out the following: 218 # 1.) DeserializeMethodTest and SerializedLambdaTest, because they depends on stub classes 219 # and won't actually run, and 220 # 2.) util/stream/boot*. Those directories contain classes in the package java.util.stream; 221 # excluding them means we don't need LOCAL_PATCH_MODULE := java.base 222 LOCAL_SRC_FILES := $(filter-out %/DeserializeMethodTest.java %/SerializedLambdaTest.java ojluni/src/test/java/util/stream/boot%,$(ojtest_src_files)) 223 # Include source code as part of JAR 224 LOCAL_JAVA_RESOURCE_DIRS := ojluni/src/test/dist $(ojtest_resource_dirs) 225 LOCAL_NO_STANDARD_LIBRARIES := true 226 LOCAL_JAVA_LIBRARIES := \ 227 bouncycastle \ 228 core-libart \ 229 core-oj \ 230 okhttp \ 231 testng 232 LOCAL_JAVACFLAGS := $(local_javac_flags) 233 LOCAL_JACK_FLAGS := $(local_jack_flags) 234 LOCAL_DX_FLAGS := --core-library 235 LOCAL_MODULE_TAGS := optional 236 LOCAL_MODULE := core-ojtests-public 237 # jack bug workaround: int[] java.util.stream.StatefulTestOp.-getjava-util-stream-StreamShapeSwitchesValues() is a private synthetic method in an interface which causes a hard verifier error 238 LOCAL_DEX_PREOPT := false # disable AOT preverification which breaks the build. it will still throw VerifyError at runtime. 239 LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 240 include $(BUILD_JAVA_LIBRARY) 241endif 242 243# 244# Build for the host. 245# 246 247ifeq ($(HOST_OS),linux) 248 249# Make the core-tests-hostdex library. 250ifeq ($(LIBCORE_SKIP_TESTS),) 251 include $(CLEAR_VARS) 252 LOCAL_SRC_FILES := $(test_src_files) 253 LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs) 254 LOCAL_NO_STANDARD_LIBRARIES := true 255 LOCAL_JAVA_LIBRARIES := \ 256 bouncycastle-hostdex \ 257 core-libart-hostdex \ 258 core-oj-hostdex \ 259 core-tests-support-hostdex \ 260 junit-hostdex \ 261 mockito-api-hostdex \ 262 okhttp-hostdex 263 LOCAL_STATIC_JAVA_LIBRARIES := \ 264 archive-patcher-hostdex \ 265 core-test-rules-hostdex \ 266 junit-params-hostdex \ 267 mockftpserver-hostdex \ 268 mockwebserver-host \ 269 nist-pkix-tests-host \ 270 slf4j-jdk14-hostdex \ 271 sqlite-jdbc-host \ 272 tzdata-testing-hostdex 273 LOCAL_JAVACFLAGS := $(local_javac_flags) 274 LOCAL_MODULE_TAGS := optional 275 LOCAL_MODULE := core-tests-hostdex 276 LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 277 include $(BUILD_HOST_DALVIK_JAVA_LIBRARY) 278endif 279 280# Make the core-ojtests-hostdex library. 281ifeq ($(LIBCORE_SKIP_TESTS),) 282 include $(CLEAR_VARS) 283 LOCAL_SRC_FILES := $(ojtest_src_files) 284 LOCAL_NO_STANDARD_LIBRARIES := true 285 LOCAL_JAVA_LIBRARIES := \ 286 bouncycastle-hostdex \ 287 core-libart-hostdex \ 288 core-oj-hostdex \ 289 okhttp-hostdex 290 LOCAL_STATIC_JAVA_LIBRARIES := testng-hostdex 291 LOCAL_JAVACFLAGS := $(local_javac_flags) 292 LOCAL_DX_FLAGS := --core-library 293 LOCAL_MODULE_TAGS := optional 294 LOCAL_MODULE := core-ojtests-hostdex 295 # ojluni/src/test/java/util/stream/{bootlib,boottest} 296 # contains tests that are in packages from java.base; 297 # By default, OpenJDK 9's javac will only compile such 298 # code if it's declared to also be in java.base at 299 # compile time. 300 # 301 # For now, we use --patch-module to put all sources 302 # and dependencies from this make target into java.base; 303 # other source directories in this make target are in 304 # packages not from java.base; if this becomes a proble 305 # in future, this could be addressed eg. by splitting 306 # boot{lib,test} out into a separate make target, 307 # deleting those tests or moving them to a different 308 # package. 309 LOCAL_PATCH_MODULE := java.base 310 LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 311 include $(BUILD_HOST_DALVIK_JAVA_LIBRARY) 312endif 313 314endif # HOST_OS == linux 315 316# 317# Local droiddoc for faster libcore testing 318# 319# 320# Run with: 321# mm -j32 libcore-docs 322# 323# Main output: 324# ../out/target/common/docs/libcore/reference/packages.html 325# 326# All text for proofreading (or running tools over): 327# ../out/target/common/docs/libcore-proofread.txt 328# 329# TODO list of missing javadoc, etc: 330# ../out/target/common/docs/libcore-docs-todo.html 331# 332# Rerun: 333# rm -rf ../out/target/common/docs/libcore-timestamp && mm -j32 libcore-docs 334# 335include $(CLEAR_VARS) 336 337# for shared defintion of libcore_to_document 338include $(LOCAL_PATH)/Docs.mk 339 340# The libcore_to_document paths are relative to $(TOPDIR). We are in libcore so we must prepend 341# ../ to make LOCAL_SRC_FILES relative to $(LOCAL_PATH). 342LOCAL_SRC_FILES := $(addprefix ../, $(libcore_to_document)) 343LOCAL_INTERMEDIATE_SOURCES := \ 344 $(patsubst $(TARGET_OUT_COMMON_INTERMEDIATES)/%,%,$(libcore_to_document_generated)) 345LOCAL_ADDITIONAL_DEPENDENCIES := $(libcore_to_document_generated) 346# rerun doc generation without recompiling the java 347LOCAL_JAVACFLAGS := $(local_javac_flags) 348LOCAL_MODULE_CLASS:=JAVA_LIBRARIES 349 350LOCAL_MODULE := libcore 351 352LOCAL_DROIDDOC_OPTIONS := \ 353 -offlinemode \ 354 -title "libcore" \ 355 -proofread $(OUT_DOCS)/$(LOCAL_MODULE)-proofread.txt \ 356 -todo ../$(LOCAL_MODULE)-docs-todo.html \ 357 -knowntags ./libcore/known_oj_tags.txt \ 358 -hdf android.whichdoc offline 359 360LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR:=external/doclava/res/assets/templates-sdk 361 362include $(BUILD_DROIDDOC) 363 364# For unbundled build we'll use the prebuilt jar from prebuilts/sdk. 365ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) 366 367# Generate the stub source files for core.current.stubs 368# ===================================================== 369include $(CLEAR_VARS) 370 371LOCAL_SRC_FILES := $(addprefix ../, $(libcore_to_document)) 372LOCAL_GENERATED_SOURCES := $(libcore_to_document_generated) 373 374LOCAL_MODULE_CLASS := JAVA_LIBRARIES 375 376LOCAL_DROIDDOC_OPTIONS:= \ 377 -stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/core.current.stubs_intermediates/src \ 378 -nodocs \ 379 380LOCAL_UNINSTALLABLE_MODULE := true 381LOCAL_NO_STANDARD_LIBRARIES := true 382LOCAL_MODULE := core-current-stubs-gen 383 384include $(BUILD_DROIDDOC) 385 386# Remember the target that will trigger the code generation. 387core_current_gen_stamp := $(full_target) 388 389# Build the core.current.stubs library 390# ==================================== 391include $(CLEAR_VARS) 392 393LOCAL_MODULE := core.current.stubs 394 395LOCAL_SOURCE_FILES_ALL_GENERATED := true 396 397# Make sure to run droiddoc first to generate the stub source files. 398LOCAL_ADDITIONAL_DEPENDENCIES := $(core_current_gen_stamp) 399core_current_gen_stamp := 400 401# Because javac refuses to compile these stubs with --system=none, ( http://b/72206056#comment31 ), 402# just patch them into java.base at compile time. 403LOCAL_PATCH_MODULE := java.base 404LOCAL_NO_STANDARD_LIBRARIES := true 405LOCAL_ERROR_PRONE_FLAGS := -Xep:MissingOverride:OFF 406include $(BUILD_STATIC_JAVA_LIBRARY) 407 408# Archive a copy of the classes.jar in SDK build. 409$(call dist-for-goals,sdk win_sdk,$(full_classes_jar):core.current.stubs.jar) 410 411endif # not TARGET_BUILD_APPS not TARGET_BUILD_PDK=true 412