Merge "Do not apply GLOBAL_CFLAGS_NO_OVERRIDE to host *.S"
diff --git a/core/definitions.mk b/core/definitions.mk
index 325f90f..66859cd 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -654,25 +654,36 @@
 # $(1): library name
 # $(2): Non-empty if IS_HOST_MODULE
 define _java-lib-full-classes.jar
-$(call _java-lib-dir,$(1),$(2))/classes$(COMMON_JAVA_PACKAGE_SUFFIX)
+$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
 endef
 
+# Get the jar files (you can pass to "javac -classpath") of static or shared
+# Java libraries that you want to link against.
 # $(1): library name list
 # $(2): Non-empty if IS_HOST_MODULE
 define java-lib-files
 $(foreach lib,$(1),$(call _java-lib-full-classes.jar,$(lib),$(2)))
 endef
 
-# $(1): library name
-# $(2): Non-empty if IS_HOST_MODULE
-define _java-lib-full-dep
-$(call _java-lib-dir,$(1),$(2))/$(if $(2),javalib,classes)$(COMMON_JAVA_PACKAGE_SUFFIX)
-endef
-
+# Get the dependency files (you can put on the right side of "|" of a build rule)
+# of the Java libraries.
 # $(1): library name list
 # $(2): Non-empty if IS_HOST_MODULE
+# Historically for target Java libraries we used a different file (javalib.jar)
+# as the dependency.
+# Now we can use classes.jar as dependency, so java-lib-deps is the same
+# as java-lib-files.
 define java-lib-deps
-$(foreach lib,$(1),$(call _java-lib-full-dep,$(lib),$(2)))
+$(call java-lib-files,$(1),$(2))
+endef
+
+# Get the jar files (you can pass to "javac -classpath") of host dalvik Java libraries.
+# You can also use them as dependency files.
+# A host dalvik Java library is different from a host Java library in that
+# the java lib file is classes.jar, not javalib.jar.
+# $(1): library name list
+define host-dex-java-lib-files
+$(foreach lib,$(1),$(call _java-lib-dir,$(lib),true)/classes.jar)
 endef
 
 ###########################################################
@@ -693,16 +704,10 @@
 $(foreach lib,$(1),$(call _jack-lib-full-classes,$(lib),$(2)))
 endef
 
-# $(1): library name
-# $(2): Non-empty if IS_HOST_MODULE
-define _jack-lib-full-dep
-$(call _jack-lib-full-classes,$(1),$(2))
-endef
-
 # $(1): library name list
 # $(2): Non-empty if IS_HOST_MODULE
 define jack-lib-deps
-$(foreach lib,$(1),$(call _jack-lib-full-dep,$(lib),$(2)))
+$(call jack-lib-files,$(1),$(2))
 endef
 
 ###########################################################
diff --git a/core/dumpvar.mk b/core/dumpvar.mk
index cfb031f..36fd08a 100644
--- a/core/dumpvar.mk
+++ b/core/dumpvar.mk
@@ -1,3 +1,35 @@
+
+# List of variables we want to print in the build banner.
+print_build_config_vars := \
+  PLATFORM_VERSION_CODENAME \
+  PLATFORM_VERSION \
+  TARGET_PRODUCT \
+  TARGET_BUILD_VARIANT \
+  TARGET_BUILD_TYPE \
+  TARGET_BUILD_APPS \
+  TARGET_ARCH \
+  TARGET_ARCH_VARIANT \
+  TARGET_CPU_VARIANT \
+  TARGET_2ND_ARCH \
+  TARGET_2ND_ARCH_VARIANT \
+  TARGET_2ND_CPU_VARIANT \
+  HOST_ARCH \
+  HOST_2ND_ARCH \
+  HOST_OS \
+  HOST_OS_EXTRA \
+  HOST_CROSS_OS \
+  HOST_CROSS_ARCH \
+  HOST_CROSS_2ND_ARCH \
+  HOST_BUILD_TYPE \
+  BUILD_ID \
+  OUT_DIR
+
+ifeq ($(TARGET_BUILD_PDK),true)
+print_build_config_vars += \
+  TARGET_BUILD_PDK \
+  PDK_FUSION_PLATFORM_ZIP
+endif
+
 # ---------------------------------------------------------------
 # the setpath shell function in envsetup.sh uses this to figure out
 # what to add to the path given the config we have chosen.
@@ -59,38 +91,37 @@
 PRINT_BUILD_CONFIG:=
 endif
 
-endif # CALLED_FROM_SETUP
-
-
-ifneq ($(PRINT_BUILD_CONFIG),)
-HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
-$(info ============================================)
-$(info   PLATFORM_VERSION_CODENAME=$(PLATFORM_VERSION_CODENAME))
-$(info   PLATFORM_VERSION=$(PLATFORM_VERSION))
-$(info   TARGET_PRODUCT=$(TARGET_PRODUCT))
-$(info   TARGET_BUILD_VARIANT=$(TARGET_BUILD_VARIANT))
-$(info   TARGET_BUILD_TYPE=$(TARGET_BUILD_TYPE))
-$(info   TARGET_BUILD_APPS=$(TARGET_BUILD_APPS))
-$(info   TARGET_ARCH=$(TARGET_ARCH))
-$(info   TARGET_ARCH_VARIANT=$(TARGET_ARCH_VARIANT))
-$(info   TARGET_CPU_VARIANT=$(TARGET_CPU_VARIANT))
-$(info   TARGET_2ND_ARCH=$(TARGET_2ND_ARCH))
-$(info   TARGET_2ND_ARCH_VARIANT=$(TARGET_2ND_ARCH_VARIANT))
-$(info   TARGET_2ND_CPU_VARIANT=$(TARGET_2ND_CPU_VARIANT))
-$(info   HOST_ARCH=$(HOST_ARCH))
-$(info   HOST_2ND_ARCH=$(HOST_2ND_ARCH))
-$(info   HOST_OS=$(HOST_OS))
-$(info   HOST_OS_EXTRA=$(HOST_OS_EXTRA))
-$(info   HOST_CROSS_OS=$(HOST_CROSS_OS))
-$(info   HOST_CROSS_ARCH=$(HOST_CROSS_ARCH))
-$(info   HOST_CROSS_2ND_ARCH=$(HOST_CROSS_2ND_ARCH))
-$(info   HOST_BUILD_TYPE=$(HOST_BUILD_TYPE))
-$(info   BUILD_ID=$(BUILD_ID))
-$(info   OUT_DIR=$(OUT_DIR))
-ifeq ($(TARGET_BUILD_PDK),true)
-$(info   TARGET_BUILD_PDK=$(TARGET_BUILD_PDK))
-$(info   PDK_FUSION_PLATFORM_ZIP=$(PDK_FUSION_PLATFORM_ZIP))
+ifneq ($(filter report_config,$(DUMP_MANY_VARS)),)
+# Construct the shell commands that print the config banner.
+report_config_sh := echo '============================================';
+report_config_sh += $(foreach v,$(print_build_config_vars),echo '$v=$($(v))';)
+report_config_sh += echo '============================================';
 endif
 
+# Dump mulitple variables to "<var>=<value>" pairs, one per line.
+# The output may be executed as bash script.
+# Input variables:
+#   DUMP_MANY_VARS: the list of variable names.
+#   DUMP_VAR_PREFIX: an optional prefix of the variable name added to the output.
+#   DUMP_MANY_ABS_VARS: the list of abs variable names.
+#   DUMP_ABS_VAR_PREFIX: an optional prefix of the abs variable name added to the output.
+.PHONY: dump-many-vars
+dump-many-vars :
+	@$(foreach v, $(filter-out report_config, $(DUMP_MANY_VARS)),\
+	  echo "$(DUMP_VAR_PREFIX)$(v)='$($(v))'";)
+ifneq ($(filter report_config, $(DUMP_MANY_VARS)),)
+	@# Construct a special variable for report_config.
+	@# Escape \` to defer the execution of report_config_sh to preserve the line breaks.
+	@echo "$(DUMP_VAR_PREFIX)report_config=\`$(report_config_sh)\`"
+endif
+	@$(foreach v, $(sort $(DUMP_MANY_ABS_VARS)),\
+	  echo "$(DUMP_ABS_VAR_PREFIX)$(v)='$(PWD)/$($(v))'";)
+
+endif # CALLED_FROM_SETUP
+
+ifneq ($(PRINT_BUILD_CONFIG),)
+$(info ============================================)
+$(foreach v, $(print_build_config_vars),\
+  $(info $v=$($(v))))
 $(info ============================================)
 endif
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 4456809..e8fa6a7 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -54,6 +54,8 @@
   HOST_OS := darwin
 endif
 
+HOST_OS_EXTRA:=$(shell python -c "import platform; print(platform.platform())")
+
 # BUILD_OS is the real host doing the build.
 BUILD_OS := $(HOST_OS)
 
diff --git a/core/host_java_library.mk b/core/host_java_library.mk
index fb69f63..9a13439 100644
--- a/core/host_java_library.mk
+++ b/core/host_java_library.mk
@@ -30,13 +30,15 @@
 endif
 
 full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar
+full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
 emma_intermediates_dir := $(intermediates.COMMON)/emma_out
 # emma is hardcoded to use the leaf name of its input for the output file --
 # only the output directory can be changed
-full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(notdir $(full_classes_compiled_jar))
+full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(notdir $(full_classes_jarjar_jar))
 
 LOCAL_INTERMEDIATE_TARGETS += \
     $(full_classes_compiled_jar) \
+    $(full_classes_jarjar_jar) \
     $(full_classes_emma_jar)
 
 #######################################
@@ -49,30 +51,6 @@
 
 include $(BUILD_SYSTEM)/java_common.mk
 
-ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
-$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
-$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
-ifdef LOCAL_EMMA_COVERAGE_FILTER
-$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER)
-else
-# by default, avoid applying emma instrumentation onto emma classes itself,
-# otherwise there will be exceptions thrown
-$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.*
-endif
-# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
-# $(full_classes_emma_jar)
-$(full_classes_emma_jar) : $(full_classes_compiled_jar) | $(EMMA_JAR)
-	$(transform-classes.jar-to-emma)
-
-$(built_javalib_jar) : $(full_classes_emma_jar)
-	@echo Copying: $@
-	$(hide) $(ACP) -fp $< $@
-
-else # LOCAL_EMMA_INSTRUMENT
-# Directly build into $(built_javalib_jar).
-full_classes_compiled_jar := $(built_javalib_jar)
-endif # LOCAL_EMMA_INSTRUMENT
-
 # The layers file allows you to enforce a layering between java packages.
 # Run build/tools/java-layers.py for more details.
 layers_file := $(addprefix $(LOCAL_PATH)/, $(LOCAL_JAVA_LAYERS_FILE))
@@ -90,3 +68,41 @@
         $(proto_java_sources_file_stamp) \
         $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-host-java-to-package)
+
+# Run jarjar if necessary, otherwise just copy the file.
+ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
+$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
+$(full_classes_jarjar_jar): $(full_classes_compiled_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
+	@echo JarJar: $@
+	$(hide) java -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
+else
+$(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(ACP)
+	@echo Copying: $@
+	$(hide) $(ACP) -fp $< $@
+endif
+
+ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
+$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
+$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
+ifdef LOCAL_EMMA_COVERAGE_FILTER
+$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER)
+else
+# by default, avoid applying emma instrumentation onto emma classes itself,
+# otherwise there will be exceptions thrown
+$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.*
+endif
+# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
+# $(full_classes_emma_jar)
+$(full_classes_emma_jar) : $(full_classes_jarjar_jar) | $(EMMA_JAR)
+	$(transform-classes.jar-to-emma)
+
+$(built_javalib_jar) : $(full_classes_emma_jar)
+	@echo Copying: $@
+	$(hide) $(ACP) -fp $< $@
+
+else # LOCAL_EMMA_INSTRUMENT
+$(built_javalib_jar): $(full_classes_jarjar_jar) | $(ACP)
+	@echo Copying: $@
+	$(hide) $(ACP) -fp $< $@
+endif # LOCAL_EMMA_INSTRUMENT
+
diff --git a/core/java_common.mk b/core/java_common.mk
index 3f0ac64..21cea67 100644
--- a/core/java_common.mk
+++ b/core/java_common.mk
@@ -175,14 +175,13 @@
 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
 my_bootclasspath := ""
 else
-my_bootclasspath := $(call java-lib-files,core-oj-hostdex,$(LOCAL_IS_HOST_MODULE)):$(call java-lib-files,core-libart-hostdex,$(LOCAL_IS_HOST_MODULE))
+my_bootclasspath := $(call normalize-path-list,$(call host-dex-java-lib-files,core-oj-hostdex core-libart-hostdex))
 endif
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(my_bootclasspath)
 
-full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
-full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE)) \
-    $(full_shared_java_libs)
-else
+full_shared_java_libs := $(call host-dex-java-lib-files,$(LOCAL_JAVA_LIBRARIES))
+full_java_lib_deps := $(full_shared_java_libs)
+else # !USE_CORE_LIB_BOOTCLASSPATH
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH :=
 
 full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
diff --git a/core/product.mk b/core/product.mk
index 4d35704..7043cff 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -23,14 +23,21 @@
 # and the .mk suffix) of the product makefile, "<product_name>:" can be
 # omitted.
 
+# Search for AndroidProducts.mks in the given dir.
+# $(1): the path to the dir
+define _search-android-products-files-in-dir
+$(sort $(shell test -d $(1) && find -L $(1) \
+  -maxdepth 6 \
+  -name .git -prune \
+  -o -name AndroidProducts.mk -print))
+endef
+
 #
 # Returns the list of all AndroidProducts.mk files.
 # $(call ) isn't necessary.
 #
 define _find-android-products-files
-$(sort $(shell test -d device && find -L device -maxdepth 6 -name AndroidProducts.mk)) \
-  $(sort $(shell test -d vendor && find -L vendor -maxdepth 6 -name AndroidProducts.mk)) \
-  $(sort $(shell test -d product && find -L product -maxdepth 6 -name AndroidProducts.mk)) \
+$(foreach d, device vendor product,$(call _search-android-products-files-in-dir,$(d))) \
   $(SRC_TARGET_DIR)/product/AndroidProducts.mk
 endef
 
diff --git a/envsetup.sh b/envsetup.sh
index 9489d21..2aac383 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -37,9 +37,62 @@
     echo $A
 }
 
+# Get all the build variables needed by this script in a single call to the build system.
+function build_build_var_cache()
+{
+    T=$(gettop)
+    # Grep out the variable names from the script.
+    cached_vars=`cat $T/build/envsetup.sh | tr '()' '  ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
+    cached_abs_vars=`cat $T/build/envsetup.sh | tr '()' '  ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`
+    # Call the build system to dump the "<val>=<value>" pairs as a shell script.
+    build_dicts_script=`\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
+                        command make --no-print-directory -f build/core/config.mk \
+                        dump-many-vars \
+                        DUMP_MANY_VARS="$cached_vars" \
+                        DUMP_MANY_ABS_VARS="$cached_abs_vars" \
+                        DUMP_VAR_PREFIX="var_cache_" \
+                        DUMP_ABS_VAR_PREFIX="abs_var_cache_"`
+    local ret=$?
+    if [ $ret -ne 0 ]
+    then
+        unset build_dicts_script
+        return $ret
+    fi
+    # Excute the script to store the "<val>=<value>" pairs as shell variables.
+    eval "$build_dicts_script"
+    unset build_dicts_script
+    ret=$?
+    if [ $ret -ne 0 ]
+    then
+        return $ret
+    fi
+    BUILD_VAR_CACHE_READY="true"
+}
+
+# Delete the build cache, so that we can still call into the build system
+# to get build variables not listed in this script.
+function destroy_build_var_cache()
+{
+    unset BUILD_VAR_CACHE_READY
+    for v in $cached_vars; do
+      unset var_cache_$v
+    done
+    unset cached_vars
+    for v in $cached_abs_vars; do
+      unset abs_var_cache_$v
+    done
+    unset cached_abs_vars
+}
+
 # Get the value of a build variable as an absolute path.
 function get_abs_build_var()
 {
+    if [ "$BUILD_VAR_CACHE_READY" = "true" ]
+    then
+        eval echo \"\${abs_var_cache_$1}\"
+    return
+    fi
+
     T=$(gettop)
     if [ ! "$T" ]; then
         echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
@@ -52,6 +105,12 @@
 # Get the exact value of a build variable.
 function get_build_var()
 {
+    if [ "$BUILD_VAR_CACHE_READY" = "true" ]
+    then
+        eval echo \"\${var_cache_$1}\"
+    return
+    fi
+
     T=$(gettop)
     if [ ! "$T" ]; then
         echo "Couldn't locate the top of the tree.  Try setting TOP." >&2
@@ -321,7 +380,9 @@
         fi
     done
 
+    build_build_var_cache
     set_stuff_for_environment
+    destroy_build_var_cache
 }
 
 #
@@ -338,6 +399,7 @@
         default_value=aosp_arm
     fi
 
+    export TARGET_BUILD_APPS=
     export TARGET_PRODUCT=
     local ANSWER
     while [ -z "$TARGET_PRODUCT" ]
@@ -365,7 +427,9 @@
         fi
     done
 
+    build_build_var_cache
     set_stuff_for_environment
+    destroy_build_var_cache
 }
 
 function choosevariant()
@@ -428,8 +492,10 @@
     choosevariant $3
 
     echo
+    build_build_var_cache
     set_stuff_for_environment
     printconfig
+    destroy_build_var_cache
 }
 
 # Clear this variable.  It will be built up again when the vendorsetup.sh
@@ -511,16 +577,6 @@
 
     export TARGET_BUILD_APPS=
 
-    local product=$(echo -n $selection | sed -e "s/-.*$//")
-    check_product $product
-    if [ $? -ne 0 ]
-    then
-        echo
-        echo "** Don't have a product spec for: '$product'"
-        echo "** Do you have the right repo manifest?"
-        product=
-    fi
-
     local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
     check_variant $variant
     if [ $? -ne 0 ]
@@ -531,6 +587,18 @@
         variant=
     fi
 
+    local product=$(echo -n $selection | sed -e "s/-.*$//")
+    TARGET_PRODUCT=$product \
+    TARGET_BUILD_VARIANT=$variant \
+    build_build_var_cache
+    if [ $? -ne 0 ]
+    then
+        echo
+        echo "** Don't have a product spec for: '$product'"
+        echo "** Do you have the right repo manifest?"
+        product=
+    fi
+
     if [ -z "$product" -o -z "$variant" ]
     then
         echo
@@ -545,6 +613,7 @@
 
     set_stuff_for_environment
     printconfig
+    destroy_build_var_cache
 }
 
 # Tab completion for lunch.
@@ -607,8 +676,10 @@
     export TARGET_BUILD_TYPE=release
     export TARGET_BUILD_APPS=$apps
 
+    build_build_var_cache
     set_stuff_for_environment
     printconfig
+    destroy_build_var_cache
 }
 
 function gettop
@@ -878,18 +949,18 @@
         append='$'
         shift
     elif [ "$1" = "--help" -o "$1" = "-h" ]; then
-		echo "usage: qpid [[--exact] <process name|pid>"
-		return 255
-	fi
+        echo "usage: qpid [[--exact] <process name|pid>"
+        return 255
+    fi
 
     local EXE="$1"
     if [ "$EXE" ] ; then
-		qpid | \grep "$prepend$EXE$append"
-	else
-		adb shell ps \
-			| tr -d '\r' \
-			| sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
-	fi
+        qpid | \grep "$prepend$EXE$append"
+    else
+        adb shell ps \
+            | tr -d '\r' \
+            | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
+    fi
 }
 
 function pid()
@@ -910,7 +981,7 @@
         echo "$PID"
     else
         echo "usage: pid [--exact] <process name>"
-		return 255
+        return 255
     fi
 }
 
@@ -923,25 +994,25 @@
 
 function coredump_setup()
 {
-	echo "Getting root...";
-	adb root;
-	adb wait-for-device;
+    echo "Getting root...";
+    adb root;
+    adb wait-for-device;
 
-	echo "Remounting root partition read-write...";
-	adb shell mount -w -o remount -t rootfs rootfs;
-	sleep 1;
-	adb wait-for-device;
-	adb shell mkdir -p /cores;
-	adb shell mount -t tmpfs tmpfs /cores;
-	adb shell chmod 0777 /cores;
+    echo "Remounting root partition read-write...";
+    adb shell mount -w -o remount -t rootfs rootfs;
+    sleep 1;
+    adb wait-for-device;
+    adb shell mkdir -p /cores;
+    adb shell mount -t tmpfs tmpfs /cores;
+    adb shell chmod 0777 /cores;
 
-	echo "Granting SELinux permission to dump in /cores...";
-	adb shell restorecon -R /cores;
+    echo "Granting SELinux permission to dump in /cores...";
+    adb shell restorecon -R /cores;
 
-	echo "Set core pattern.";
-	adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
+    echo "Set core pattern.";
+    adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
 
-	echo "Done."
+    echo "Done."
 }
 
 # coredump_enable - enable core dumps for the specified process
@@ -952,13 +1023,13 @@
 
 function coredump_enable()
 {
-	local PID=$1;
-	if [ -z "$PID" ]; then
-		printf "Expecting a PID!\n";
-		return;
-	fi;
-	echo "Setting core limit for $PID to infinite...";
-	adb shell prlimit $PID 4 -1 -1
+    local PID=$1;
+    if [ -z "$PID" ]; then
+        printf "Expecting a PID!\n";
+        return;
+    fi;
+    echo "Setting core limit for $PID to infinite...";
+    adb shell prlimit $PID 4 -1 -1
 }
 
 # core - send SIGV and pull the core for process
@@ -969,28 +1040,28 @@
 
 function core()
 {
-	local PID=$1;
+    local PID=$1;
 
-	if [ -z "$PID" ]; then
-		printf "Expecting a PID!\n";
-		return;
-	fi;
+    if [ -z "$PID" ]; then
+        printf "Expecting a PID!\n";
+        return;
+    fi;
 
-	local CORENAME=core.$PID;
-	local COREPATH=/cores/$CORENAME;
-	local SIG=SEGV;
+    local CORENAME=core.$PID;
+    local COREPATH=/cores/$CORENAME;
+    local SIG=SEGV;
 
-	coredump_enable $1;
+    coredump_enable $1;
 
-	local done=0;
-	while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
-		printf "\tSending SIG%s to %d...\n" $SIG $PID;
-		adb shell kill -$SIG $PID;
-		sleep 1;
-	done;
+    local done=0;
+    while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
+        printf "\tSending SIG%s to %d...\n" $SIG $PID;
+        adb shell kill -$SIG $PID;
+        sleep 1;
+    done;
 
-	adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
-	echo "Done: core is under $COREPATH on device.";
+    adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
+    echo "Done: core is under $COREPATH on device.";
 }
 
 # systemstack - dump the current stack trace of all threads in the system process
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index f51920a..8923a05 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -1424,7 +1424,8 @@
   if oem_props is not None and len(oem_props) > 0:
     if OPTIONS.oem_source is None:
       raise common.ExternalError("OEM source required for this build")
-    script.Mount("/oem", recovery_mount_options)
+    if not OPTIONS.oem_no_mount:
+      script.Mount("/oem", recovery_mount_options)
     oem_dict = common.LoadDictionaryFromLines(
         open(OPTIONS.oem_source).readlines())