Merge "Improve installclean to catch more installed files"
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/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