1#
2# Copyright (C) 2008 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$(call record-module-type,HOST_JAVA_LIBRARY)
18
19#
20# Standard rules for building a host java library.
21#
22
23#######################################
24include $(BUILD_SYSTEM)/host_java_library_common.mk
25#######################################
26
27# Enable emma instrumentation only if the module asks so.
28ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
29ifneq (true,$(EMMA_INSTRUMENT))
30LOCAL_EMMA_INSTRUMENT :=
31endif
32endif
33
34full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar
35full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
36full_classes_jar := $(intermediates.COMMON)/classes.jar
37java_source_list_file := $(intermediates.COMMON)/java-source-list
38full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar
39full_classes_combined_jar := $(intermediates.COMMON)/classes-combined.jar
40
41LOCAL_INTERMEDIATE_TARGETS += \
42    $(full_classes_compiled_jar) \
43    $(full_classes_jarjar_jar) \
44    $(java_source_list_file) \
45    $(full_classes_combined_jar)
46
47#######################################
48include $(BUILD_SYSTEM)/base_rules.mk
49#######################################
50
51java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) \
52                $(filter %.java,$(LOCAL_GENERATED_SOURCES))
53all_java_sources := $(java_sources)
54
55ALL_MODULES.$(my_register_name).SRCS := $(ALL_MODULES.$(my_register_name).SRCS) $(all_java_sources)
56
57include $(BUILD_SYSTEM)/java_common.mk
58
59# The layers file allows you to enforce a layering between java packages.
60# Run build/make/tools/java-layers.py for more details.
61layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
62
63# List of dependencies for anything that needs all java sources in place
64java_sources_deps := \
65    $(java_sources) \
66    $(java_resource_sources) \
67    $(LOCAL_SRCJARS) \
68    $(LOCAL_ADDITIONAL_DEPENDENCIES)
69
70$(java_source_list_file): $(java_sources_deps)
71	$(write-java-source-list)
72
73# TODO(b/143658984): goma can't handle the --system argument to javac.
74#$(full_classes_compiled_jar): .KATI_NINJA_POOL := $(GOMA_POOL)
75$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
76$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
77$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES :=
78$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES :=
79$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES :=
80$(full_classes_compiled_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
81$(full_classes_compiled_jar): PRIVATE_SRCJAR_LIST_FILE := $(intermediates.COMMON)/srcjar-list
82$(full_classes_compiled_jar): PRIVATE_SRCJAR_INTERMEDIATES_DIR := $(intermediates.COMMON)/srcjars
83$(full_classes_compiled_jar): \
84    $(java_source_list_file) \
85    $(java_sources_deps) \
86    $(full_java_libs) \
87    $(full_java_bootclasspath_libs) \
88    $(annotation_processor_deps) \
89    $(NORMALIZE_PATH) \
90    $(ZIPTIME) \
91    $(JAR_ARGS) \
92    $(ZIPSYNC) \
93    $(SOONG_ZIP) \
94    | $(SOONG_JAVAC_WRAPPER)
95	$(transform-host-java-to-package)
96	$(remove-timestamps-from-package)
97
98javac-check : $(full_classes_compiled_jar)
99javac-check-$(LOCAL_MODULE) : $(full_classes_compiled_jar)
100.PHONY: javac-check-$(LOCAL_MODULE)
101
102$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
103$(full_classes_combined_jar): $(full_classes_compiled_jar) \
104                              $(jar_manifest_file) \
105                              $(full_static_java_libs) | $(MERGE_ZIPS)
106	$(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
107            $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
108	$(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
109            $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
110            $@ $< $(PRIVATE_STATIC_JAVA_LIBRARIES)
111
112# Run jarjar if necessary, otherwise just copy the file.
113ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
114$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
115$(full_classes_jarjar_jar): $(full_classes_combined_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
116	$(call transform-jarjar)
117else
118full_classes_jarjar_jar := $(full_classes_combined_jar)
119endif
120
121
122#######################################
123LOCAL_FULL_CLASSES_PRE_JACOCO_JAR := $(full_classes_jarjar_jar)
124
125include $(BUILD_SYSTEM)/jacoco.mk
126#######################################
127
128$(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(LOCAL_BUILT_MODULE)))
129$(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(full_classes_jar)))
130
131ifeq ($(TURBINE_ENABLED),false)
132$(eval $(call copy-one-file,$(LOCAL_FULL_CLASSES_JACOCO_JAR),$(full_classes_header_jar)))
133endif
134