aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2016-03-16 12:03:09 -0700
committerIgor Murashkin <iam@google.com>2016-03-22 12:12:01 -0700
commit34a08fb10c189dc51d947902192d9735e02ca4bb (patch)
treed5da8b5f4f84ff38d79acb228d47c303942235d1
parent403a1a24e69c939f7c539559423d5df0bab94fe4 (diff)
downloadguice-34a08fb10c189dc51d947902192d9735e02ca4bb.tar.gz
build: Add support for building guice within the AOSP (host only).android-n-preview-2
Builds the no_aop variant only since Android doesn't support bytecode weaving. Bug: 27552463 Change-Id: I71b4f3b26b9307b36444cecc75d67de03be9cb23
-rw-r--r--Android.mk123
-rw-r--r--AndroidCallMunge.mk42
-rw-r--r--CleanSpec.mk57
3 files changed, 222 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 00000000..87ef47f9
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,123 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Build support for guice within the Android Open Source Project
+# See https://source.android.com/source/building.html for more information
+#
+
+###################################
+# Guice #
+###################################
+
+#
+# Builds the 'no_aop' flavor for Android.
+# -- see core/pom.xml NO_AOP rule.
+#
+guice_exclude_src_files := \
+ core/src/com/google/inject/spi/InterceptorBinding.java \
+ core/src/com/google/inject/internal/InterceptorBindingProcessor.java \
+ core/src/com/google/inject/internal/InterceptorStackCallback.java \
+ core/src/com/google/inject/internal/InterceptorStackCallback.java \
+ core/src/com/google/inject/internal/util/LineNumbers.java \
+ core/src/com/google/inject/internal/MethodAspect.java \
+ core/src/com/google/inject/internal/ProxyFactory.java
+
+guice_exclude_test_files := \
+ core/test/com/googlecode/guice/BytecodeGenTest.java \
+ core/test/com/google/inject/IntegrationTest.java \
+ core/test/com/google/inject/MethodInterceptionTest.java \
+ core/test/com/google/inject/internal/ProxyFactoryTest.java
+
+guice_munge_flags := \
+ -DNO_AOP
+#
+#
+#
+
+LOCAL_PATH := $(call my-dir)
+
+guice_src_files_raw := $(call all-java-files-under,core/src)
+guice_test_files_raw := $(call all-java-files-under,core/test)
+guice_src_files := $(filter-out $(guice_exclude_src_files),$(guice_src_files_raw))
+guice_test_files := $(filter-out $(guice_exclude_test_files),$(guice_test_files_raw))
+munge_host_jar := $(HOST_OUT)/framework/munge-host.jar
+munge_zip_location := lib/build/munge.jar
+
+#
+# Host-side Java build
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := # None. Everything is post-processed by munge. See below.
+LOCAL_MODULE := guice-host
+LOCAL_MODULE_TAGS := optional
+LOCAL_STATIC_JAVA_LIBRARIES := guavalib jsr330-host
+
+munge_src_arguments := $(guice_src_files)
+include $(LOCAL_PATH)/AndroidCallMunge.mk
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+
+#
+# Host-side Dalvik build
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := # None. Everything is post-processed by munge. See below.
+LOCAL_MODULE := guice-hostdex
+LOCAL_MODULE_TAGS := optional
+LOCAL_STATIC_JAVA_LIBRARIES := guava-hostdex jsr330-hostdex
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+munge_src_arguments := $(guice_src_files)
+include $(LOCAL_PATH)/AndroidCallMunge.mk
+include $(BUILD_HOST_DALVIK_JAVA_LIBRARY)
+
+###################################
+# Munge #
+###################################
+
+# This is required to post-process the guice source to strip out the AOP-specific code.
+# We build it from source (conveniently zipped inside of lib/build/munge.jar) instead
+# of relying on a prebuilt.
+
+munge_zipped_src_files_raw := $(filter %.java,$(shell unzip -Z1 "$(LOCAL_PATH)/$(munge_zip_location)"))
+munge_zipped_unsupported_files := MungeTask.java # Missing ant dependencies in Android.
+munge_zipped_src_files := $(filter-out $(munge_zipped_unsupported_files),$(munge_zipped_src_files_raw))
+
+#
+# We build munge from lib/build/munge.jar source code.
+#
+
+# (Munge) Host-side Java build
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := # None because we get everything by unzipping the munge jar first.
+LOCAL_MODULE := munge-host
+LOCAL_MODULE_TAGS := optional
+LOCAL_JAVA_LIBRARIES := junit
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+# Unzip munge and build it
+intermediates:= $(local-generated-sources-dir)
+GEN := $(addprefix $(intermediates)/, $(munge_zipped_src_files)) # List of all files that need to be patched.
+$(GEN) : PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN) : PRIVATE_INPUT_FILE := $(munge_zipped_src_files)
+$(GEN) : PRIVATE_ZIP_LOCATION := $(munge_zip_location)
+$(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
+$(GEN): $(intermediates)/%.java : $(LOCAL_PATH)/$(PRIVATE_ZIP_LOCATION)
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+
+# Rules for target, hostdex, etc., are omitted since munge is only used during the build.
+
+# TODO: Consider adding tests.
diff --git a/AndroidCallMunge.mk b/AndroidCallMunge.mk
new file mode 100644
index 00000000..404abf86
--- /dev/null
+++ b/AndroidCallMunge.mk
@@ -0,0 +1,42 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Build support for guice within the Android Open Source Project
+# See https://source.android.com/source/building.html for more information
+#
+
+# Factored-out implementation of calling munge to post-process guice java files.
+#
+# Arguments:
+# (Constant)
+# munge_host_jar = Path to munge-host.jar (built by munge-host rule)
+# munge_zip_location = Path to lib/build/munge.jar source archive
+# (Varying)
+# munge_src_arguments = List of files that need to be munged
+# guice_munge_flags = List of flags to pass to munge (e.g. guice_munge_flags := -DNO_AOP)
+#
+
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+# Run munge over every single java file.
+intermediates:= $(local-generated-sources-dir)
+GEN := $(addprefix $(intermediates)/, $(munge_src_arguments)) # List of all files that need to be munged.
+$(GEN) : PRIVATE_ZIP_LOCATION := $(munge_zip_location)
+$(GEN) : PRIVATE_HOST_JAR := $(munge_host_jar)
+$(GEN) : PRIVATE_MUNGE_FLAGS := $(guice_munge_flags)
+$(GEN) : PRIVATE_CUSTOM_TOOL = java -cp $(PRIVATE_HOST_JAR) Munge $(PRIVATE_MUNGE_FLAGS) $< > $@
+$(GEN): $(intermediates)/%.java : $(LOCAL_PATH)/%.java $(LOCAL_PATH)/$(munge_zip_location) $(munge_host_jar)
+ $(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644
index 00000000..56b1b86f
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,57 @@
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list. These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list. E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+
+# Clean up generated code from guice-hostdex
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/gen/JAVA_LIBRARIES/guice-hostdex_intermediates)/path/to/file.java
+# Clean up generated code from guice-host
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/gen/JAVA_LIBRARIES/guice-host_intermediates)/path/to/file.java
+
+# Clean up generated code from munge-host
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/gen/JAVA_LIBRARIES/munge-host_intermediates)/path/to/file.java
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************