Merge "Fix init rc installation in vendor when LOCAL_MODULE_PATH is set"
diff --git a/core/cleanbuild.mk b/core/cleanbuild.mk
index 76f4613..22b9664 100644
--- a/core/cleanbuild.mk
+++ b/core/cleanbuild.mk
@@ -194,22 +194,33 @@
 # installclean logic
 #
 
-# The files/dirs to delete during an installclean.  This includes the
-# non-common APPS directory, which may contain the wrong resources.
+# The files/dirs to delete during an installclean.
 #
-# Deletes all of the files that change between different build types,
-# like "make user" vs. "make sdk".  This lets you work with different
-# build types without having to do a full clean each time.  E.g.:
+# Deletes all of the installed files -- the intent is to remove files
+# that may no longer be installed, either because the user previously
+# installed them, or they were previously installed by default but no
+# longer are.
 #
-#     $ make -j8 all
-#     $ make installclean
-#     $ make -j8 user
-#     $ make installclean
-#     $ make -j8 sdk
+# This is faster than a full clean, since we're not deleting the
+# intermediates. Instead of recompiling, we can just copy the results.
 #
+# Host bin, frameworks, and lib* are intentionally omitted, since
+# otherwise we'd have to rebuild any generated files created with those
+# tools.
 installclean_files := \
 	$(HOST_OUT)/obj/NOTICE_FILES \
+	$(HOST_OUT)/obj/PACKAGING \
+	$(HOST_OUT)/coverage \
+	$(HOST_OUT)/cts \
+	$(HOST_OUT)/nativetest* \
 	$(HOST_OUT)/sdk \
+	$(HOST_OUT)/sdk_addon \
+	$(HOST_OUT)/testcases \
+	$(HOST_OUT)/vts \
+	$(HOST_CROSS_OUT)/bin \
+	$(HOST_CROSS_OUT)/coverage \
+	$(HOST_CROSS_OUT)/lib* \
+	$(HOST_CROSS_OUT)/nativetest* \
 	$(PRODUCT_OUT)/*.img \
 	$(PRODUCT_OUT)/*.ini \
 	$(PRODUCT_OUT)/*.txt \
@@ -226,7 +237,14 @@
 	$(PRODUCT_OUT)/system_other \
 	$(PRODUCT_OUT)/vendor \
 	$(PRODUCT_OUT)/oem \
-	$(PRODUCT_OUT)/obj/FAKE
+	$(PRODUCT_OUT)/obj/FAKE \
+	$(PRODUCT_OUT)/breakpad \
+	$(PRODUCT_OUT)/cache \
+	$(PRODUCT_OUT)/coverage \
+	$(PRODUCT_OUT)/installer \
+	$(PRODUCT_OUT)/odm \
+	$(PRODUCT_OUT)/sysloader \
+	$(PRODUCT_OUT)/testcases \
 
 # The files/dirs to delete during a dataclean, which removes any files
 # in the staging and emulator data partitions.
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index bae38c5..614a7ca 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -164,6 +164,7 @@
 LOCAL_PICKUP_FILES:=
 LOCAL_POST_INSTALL_CMD:=
 LOCAL_POST_LINK_CMD:=
+LOCAL_PREBUILT_COVERAGE_ARCHIVE:=
 LOCAL_PREBUILT_EXECUTABLES:=
 LOCAL_PREBUILT_JAVA_LIBRARIES:=
 LOCAL_PREBUILT_JNI_LIBS:=
diff --git a/core/main.mk b/core/main.mk
index cca0d21..dff0163 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -1078,15 +1078,6 @@
 # Phony target to run all java compilations that use javac instead of jack.
 .PHONY: javac-check
 
-# To catch more build breakage, check build tests modules in eng and userdebug builds.
-ifneq ($(ANDROID_NO_TEST_CHECK),true)
-ifneq ($(TARGET_BUILD_PDK),true)
-ifneq ($(filter eng userdebug,$(TARGET_BUILD_VARIANT)),)
-droidcore : target-tests host-tests
-endif
-endif
-endif
-
 ifneq (,$(filter samplecode, $(MAKECMDGOALS)))
 .PHONY: samplecode
 sample_MODULES := $(sort $(call get-tagged-modules,samples))
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 10512ff..997f971 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -174,6 +174,19 @@
 endif  # my_strip_module not true
 
 ifeq ($(NATIVE_COVERAGE),true)
+ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE)))
+  $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir))
+  ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true)
+    ifdef LOCAL_IS_HOST_MODULE
+      my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
+    else
+      my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
+    endif
+    my_coverage_path := $(my_coverage_path)/$(basename $(my_installed_module_stem)).gcnodir
+    $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path)))
+    $(LOCAL_BUILT_MODULE): $(my_coverage_path)
+  endif
+else
 # Coverage information is needed when static lib is a dependency of another
 # coverage-enabled module.
 ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
@@ -186,6 +199,7 @@
 	$(transform-o-to-static-lib)
 endif
 endif
+endif
 
 ifeq ($(LOCAL_MODULE_CLASS),APPS)
 PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
diff --git a/core/shared_library_internal.mk b/core/shared_library_internal.mk
index 6b914c9..1ea4cb8 100644
--- a/core/shared_library_internal.mk
+++ b/core/shared_library_internal.mk
@@ -96,6 +96,7 @@
 
 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS := $(strip $(LOCAL_GCNO_FILES))
 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(strip $(built_whole_gcno_libraries)) $(strip $(built_static_gcno_libraries))
+$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_INTERMEDIATES_DIR := $(intermediates)
 $(intermediates)/$(GCNO_ARCHIVE) : $(LOCAL_GCNO_FILES) $(built_whole_gcno_libraries) $(built_static_gcno_libraries)
 	$(transform-o-to-static-lib)
 
diff --git a/core/soong_config.mk b/core/soong_config.mk
index ad2f204..c038a32 100644
--- a/core/soong_config.mk
+++ b/core/soong_config.mk
@@ -43,6 +43,9 @@
 	echo '    "ClangTidy": $(if $(filter 1 true,$(WITH_TIDY)),true,false),'; \
 	echo '    "TidyChecks": "$(WITH_TIDY_CHECKS)",'; \
 	echo ''; \
+	echo '    "NativeCoverage": $(if $(filter true,$(NATIVE_COVERAGE)),true,false),'; \
+	echo '    "CoveragePaths": [$(if $(COVERAGE_PATHS),"$(subst $(space),"$(comma)",$(subst $(comma),$(space),$(COVERAGE_PATHS)))")],'; \
+	echo ''; \
 	echo '    "DeviceName": "$(TARGET_DEVICE)",'; \
 	echo '    "DeviceArch": "$(TARGET_ARCH)",'; \
 	echo '    "DeviceArchVariant": "$(TARGET_ARCH_VARIANT)",'; \
diff --git a/core/static_library_internal.mk b/core/static_library_internal.mk
index 6133ea2..6b4d22f 100644
--- a/core/static_library_internal.mk
+++ b/core/static_library_internal.mk
@@ -39,6 +39,7 @@
 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES := $(strip $(built_whole_gcno_libraries))
 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix)
 $(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
+$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_INTERMEDIATES_DIR := $(intermediates)
 $(intermediates)/$(GCNO_ARCHIVE) : $(LOCAL_GCNO_FILES) $(built_whole_gcno_libraries)
 	$(transform-o-to-static-lib)
 endif
diff --git a/envsetup.sh b/envsetup.sh
index 710b28f..b239441 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -260,6 +260,12 @@
     unset ANDROID_HOST_OUT
     export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
 
+    unset ANDROID_HOST_OUT_TESTCASES
+    export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES)
+
+    unset ANDROID_TARGET_OUT_TESTCASES
+    export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES)
+
     # needed for building linux on MacOS
     # TODO: fix the path
     #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py
index 433a010..1edf5b2 100644
--- a/tools/releasetools/blockimgdiff.py
+++ b/tools/releasetools/blockimgdiff.py
@@ -635,7 +635,7 @@
     stash_map = {}
 
     # Create the map between a stash and its def/use points. For example, for a
-    # given stash of (raw_id, sr), stashes[raw_id] = (sr, def_cmd, use_cmd).
+    # given stash of (raw_id, sr), stash_map[raw_id] = (sr, def_cmd, use_cmd).
     for xf in self.transfers:
       # Command xf defines (stores) all the stashes in stash_before.
       for stash_raw_id, sr in xf.stash_before:
@@ -672,20 +672,10 @@
         # Check the post-command stashed_blocks.
         stashed_blocks_after = stashed_blocks
         if self.version == 2:
-          assert stash_raw_id not in stashes
-          if free_stash_ids:
-            sid = heapq.heappop(free_stash_ids)
-          else:
-            sid = next_stash_id
-            next_stash_id += 1
-          stashes[stash_raw_id] = sid
           stashed_blocks_after += sr.size()
         else:
           sh = self.HashBlocks(self.src, sr)
-          if sh in stashes:
-            stashes[sh] += 1
-          else:
-            stashes[sh] = 1
+          if sh not in stashes:
             stashed_blocks_after += sr.size()
 
         if stashed_blocks_after > max_allowed:
@@ -695,6 +685,20 @@
           replaced_cmds.append(use_cmd)
           print("%10d  %9s  %s" % (sr.size(), "explicit", use_cmd))
         else:
+          # Update the stashes map.
+          if self.version == 2:
+            assert stash_raw_id not in stashes
+            if free_stash_ids:
+              sid = heapq.heappop(free_stash_ids)
+            else:
+              sid = next_stash_id
+              next_stash_id += 1
+            stashes[stash_raw_id] = sid
+          else:
+            if sh in stashes:
+              stashes[sh] += 1
+            else:
+              stashes[sh] = 1
           stashed_blocks = stashed_blocks_after
 
       # "move" and "diff" may introduce implicit stashes in BBOTA v3. Prior to