1# Copyright (C) 2016 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16#
17# Build support for guice within the Android Open Source Project
18# See https://source.android.com/source/building.html for more information
19#
20
21###################################
22#           Guice                 #
23###################################
24
25#
26# Builds the 'no_aop' flavor for Android.
27# -- see core/pom.xml NO_AOP rule.
28#
29guice_exclude_src_files := \
30  core/src/com/google/inject/spi/InterceptorBinding.java \
31  core/src/com/google/inject/internal/InterceptorBindingProcessor.java \
32  core/src/com/google/inject/internal/InterceptorStackCallback.java \
33  core/src/com/google/inject/internal/InterceptorStackCallback.java \
34  core/src/com/google/inject/internal/util/LineNumbers.java \
35  core/src/com/google/inject/internal/MethodAspect.java \
36  core/src/com/google/inject/internal/ProxyFactory.java
37
38guice_exclude_test_files := \
39  core/test/com/googlecode/guice/BytecodeGenTest.java \
40  core/test/com/google/inject/IntegrationTest.java \
41  core/test/com/google/inject/MethodInterceptionTest.java \
42  core/test/com/google/inject/internal/ProxyFactoryTest.java
43
44guice_munge_flags := \
45  -DNO_AOP
46#
47#
48#
49
50LOCAL_PATH := $(call my-dir)
51
52guice_src_files_raw := $(call all-java-files-under,core/src)
53guice_test_files_raw := $(call all-java-files-under,core/test)
54guice_src_files := $(filter-out $(guice_exclude_src_files),$(guice_src_files_raw))
55guice_test_files := $(filter-out $(guice_exclude_test_files),$(guice_test_files_raw))
56munge_host_jar := $(HOST_OUT)/framework/munge-host.jar
57munge_zip_location := lib/build/munge.jar
58
59#
60# Target-side Dalvik build
61include $(CLEAR_VARS)
62LOCAL_SRC_FILES := # None. Everything is post-processed by munge. See below.
63LOCAL_MODULE := guice
64LOCAL_STATIC_JAVA_LIBRARIES := guava jsr330
65LOCAL_MODULE_CLASS := JAVA_LIBRARIES
66munge_src_arguments := $(guice_src_files)
67include $(LOCAL_PATH)/AndroidCallMunge.mk
68include $(BUILD_STATIC_JAVA_LIBRARY)
69
70
71#
72# Host-side Java build
73include $(CLEAR_VARS)
74LOCAL_SRC_FILES := # None. Everything is post-processed by munge. See below.
75LOCAL_MODULE := guice-host
76LOCAL_STATIC_JAVA_LIBRARIES := guavalib jsr330-host
77
78munge_src_arguments := $(guice_src_files)
79include $(LOCAL_PATH)/AndroidCallMunge.mk
80include $(BUILD_HOST_JAVA_LIBRARY)
81
82
83#
84# Host-side Dalvik build
85include $(CLEAR_VARS)
86LOCAL_SRC_FILES := # None. Everything is post-processed by munge. See below.
87LOCAL_MODULE := guice-hostdex
88LOCAL_STATIC_JAVA_LIBRARIES := guava-hostdex jsr330-hostdex
89LOCAL_MODULE_CLASS := JAVA_LIBRARIES
90munge_src_arguments := $(guice_src_files)
91include $(LOCAL_PATH)/AndroidCallMunge.mk
92include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
93
94###################################
95#           Munge                 #
96###################################
97
98# This is required to post-process the guice source to strip out the AOP-specific code.
99# We build it from source (conveniently zipped inside of lib/build/munge.jar) instead
100# of relying on a prebuilt.
101
102munge_zipped_src_files_raw := $(filter %.java,$(shell unzip -Z1 "$(LOCAL_PATH)/$(munge_zip_location)"))
103munge_zipped_unsupported_files := MungeTask.java # Missing ant dependencies in Android.
104munge_zipped_src_files := $(filter-out $(munge_zipped_unsupported_files),$(munge_zipped_src_files_raw))
105
106#
107# We build munge from lib/build/munge.jar source code.
108#
109
110# (Munge) Host-side Java build
111include $(CLEAR_VARS)
112LOCAL_SRC_FILES := # None because we get everything by unzipping the munge jar first.
113LOCAL_MODULE := munge-host
114LOCAL_JAVA_LIBRARIES := junit
115LOCAL_MODULE_CLASS := JAVA_LIBRARIES
116# Unzip munge and build it
117intermediates:= $(local-generated-sources-dir)
118GEN := $(addprefix $(intermediates)/, $(munge_zipped_src_files)) # List of all files that need to be patched.
119$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
120$(GEN) : PRIVATE_INPUT_FILE := $(munge_zipped_src_files)
121$(GEN) : PRIVATE_ZIP_LOCATION := $(munge_zip_location)
122$(GEN) : PRIVATE_CUSTOM_TOOL = unzip -p "$(PRIVATE_PATH)/$(PRIVATE_ZIP_LOCATION)" $(shell echo $@ | awk -F / "{if (NF>1) {print \$$NF}}")  >$@ ## unzip -p munge.jar Filename.java > intermediates/Filename.java
123$(GEN): $(intermediates)/%.java : $(LOCAL_PATH)/$(PRIVATE_ZIP_LOCATION)
124	$(transform-generated-source)
125LOCAL_GENERATED_SOURCES += $(GEN)
126
127include $(BUILD_HOST_JAVA_LIBRARY)
128
129
130# Rules for target, hostdex, etc., are omitted since munge is only used during the build.
131
132# TODO: Consider adding tests.
133