diff options
author | Igor Murashkin <iam@google.com> | 2016-03-23 11:36:10 -0700 |
---|---|---|
committer | Igor Murashkin <iam@google.com> | 2016-03-23 18:17:16 -0700 |
commit | cce31f6de8fea06821a8b57a9c0d2c687c8161f5 (patch) | |
tree | 5d078208b47b5a89c2c4ef5fc677b535f0faba74 | |
parent | 5f8083f0372e8f035fb040ae01d14d6ef15a897e (diff) | |
download | snakeyaml-cce31f6de8fea06821a8b57a9c0d2c687c8161f5.tar.gz |
build: Add support for building snakeyaml within the AOSP (host only).android-n-preview-2
Bug: 27552463
Change-Id: I53f799134d11eced40859bfb7e1f55a2bdacf229
-rw-r--r-- | Android.mk | 59 | ||||
-rw-r--r-- | CleanSpec.mk | 54 | ||||
-rwxr-xr-x | patch-android-src | 91 |
3 files changed, 204 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 00000000..e91fdb14 --- /dev/null +++ b/Android.mk @@ -0,0 +1,59 @@ +# 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 snakeyaml within the Android Open Source Project +# See https://source.android.com/source/building.html for more information +# + +LOCAL_PATH := $(call my-dir) + +# List of all files that need to be patched (see src/patches/android) +snakeyaml_need_patch_src_files := \ + src/main/java/org/yaml/snakeyaml/extensions/compactnotation/CompactConstructor.java \ + src/main/java/org/yaml/snakeyaml/constructor/Constructor.java \ + src/main/java/org/yaml/snakeyaml/introspector/PropertyUtils.java \ + src/main/java/org/yaml/snakeyaml/representer/Representer.java +# List of all files that are unsupported on android (see pom.xml) +snakeyaml_unsupported_android_src_files := \ + src/main/java/org/yaml/snakeyaml/introspector/MethodProperty.java +snakeyaml_src_files_unfiltered := $(call all-java-files-under, src/main) +# We omit the list of files that need to be patched because those are included by LOCAL_GENERATED_SOURCES instead. +snakeyaml_src_files := $(filter-out $(snakeyaml_need_patch_src_files) $(snakeyaml_unsupported_android_src_files),$(snakeyaml_src_files_unfiltered)) + +# Host-side Java build +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(snakeyaml_src_files_unfiltered) +LOCAL_MODULE := snakeyaml-host +include $(BUILD_HOST_JAVA_LIBRARY) + +# Host-side Dalvik build +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(snakeyaml_src_files) +LOCAL_MODULE := snakeyaml-hostdex +LOCAL_MODULE_CLASS := JAVA_LIBRARIES + +# Apply all of the Android patches in src/patches/android by running patch-android-src script on them. +intermediates:= $(local-generated-sources-dir) +GEN := $(addprefix $(intermediates)/, $(snakeyaml_need_patch_src_files)) # List of all files that need to be patched. +$(GEN) : PRIVATE_PATH := $(LOCAL_PATH) +$(GEN) : PRIVATE_CUSTOM_TOOL = $(PRIVATE_PATH)/patch-android-src $(PRIVATE_PATH)/ $< $@ +$(GEN): $(intermediates)/%.java : $(LOCAL_PATH)/%.java $(LOCAL_PATH)/patch-android-src + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + +include $(BUILD_HOST_DALVIK_JAVA_LIBRARY) + +# TODO: Consider adding tests. diff --git a/CleanSpec.mk b/CleanSpec.mk new file mode 100644 index 00000000..7ace389e --- /dev/null +++ b/CleanSpec.mk @@ -0,0 +1,54 @@ +# 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 snakeyaml-hostdex +# (When removing a file from $(snakeyaml_need_patch_src_files), +# make a rule similar to below to remove stale files from incremental builds). +# +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/gen/JAVA_LIBRARIES/snakeyaml-hostdex_intermediates)/path/to/RemovedFile.java +# ************************************************ +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST +# ************************************************ diff --git a/patch-android-src b/patch-android-src new file mode 100755 index 00000000..dacf1fcc --- /dev/null +++ b/patch-android-src @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +# 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. +# + +# Given a source file, for example Constructor.java, find the patch file for it and apply it. +# Patch is applied to a copy (as opposed to in-place), for example into a build artifact location. + +if [[ $# -lt 3 ]]; then + echo "Usage: $(basename $0) <src-file-prefix> <src-file> <dst-file>" + exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ANDROID_PATCHES_DIR="$DIR/src/patches/android" + +src_file_prefix="$1" +src_file="$2" +src_file_with_prefix="$2" +dst_file="$3" +dst_dir="$(dirname "$dst_file")" + +# Sanity checking + +if ! [[ -d $ANDROID_PATCHES_DIR ]]; then + echo "FATAL: Android patch directory $ANDROID_PATCHES_DIR does not exist." >&2 + exit 1 +fi + +if ! [[ $src_file == $src_file_prefix* ]]; then + echo "$src_file_prefix is not a valid prefix of $src_file" >&2 + exit 1 +fi + +if ! [[ -f $src_file ]]; then + echo "Source file $src_file does not exist." >&2 + exit 1 +fi + +# Remove the src file prefix, giving us the correct grep target for the .patch files. +src_file="${src_file#$src_file_prefix}" + +patch_file_src=$(grep --files-with-matches -R "diff --git a/$src_file" "$ANDROID_PATCHES_DIR") +if [[ $? -ne 0 ]]; then + echo "Error: Could not find a corresponding .patch file for $src_file" >&2 + exit 1 +fi + +# Parse the source file from the .patch file (assumes exactly one file diff per .patch file) +src_file_check=$(cat "$patch_file_src" | grep "diff --git a/" | sed -e "s:diff --git a\/::g" | sed -e "s: b\/.*::g") + + +if ! [[ -f $patch_file_src ]]; then + echo "Patch file $patch_file_src does not exist." >&2 + exit 1 +fi + +if ! cat "$patch_file_src" | grep "diff --git a/" > /dev/null; then + echo "File $patch_file_src is not a valid diff file" >&2 + exit 1 +fi + +if [[ $src_file != $src_file_check ]]; then + echo "Check-fail: $src_file was not same as found in patch file ($src_file_check)" >&2 + exit 1 +fi + +set -e + +# Copy the src file and then apply the patch to it. +mkdir -p "$dst_dir" +cp "$src_file_with_prefix" "$dst_file" +if ! [[ -f "$dst_file" ]]; then + echo "File "$dst_file" does not exist; patching will fail" >&2 + exit 1 +fi +cd "$dst_dir" +patch "$(basename "$dst_file")" "$patch_file_src" +echo "Successfully applied patch $patch_file_src into copy of file $dst_file" |