bisect tool: Symbolic link re-generated bad item to original one

This patch modifies the way to genearte bad item while pass level
bisection. Rather than directly overwrite the old object, we generate it
to a tmp file and symblic link it to original one to satisfy building
tool.

BUG=chromium:878954
TEST=Ran test successfully with Android compiler wrapper.

Change-Id: If152742e0a2088e9d8c2456bf046cede938d88d3
Reviewed-on: https://chromium-review.googlesource.com/1220016
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: Caroline Tice <cmtice@chromium.org>
diff --git a/binary_search_tool/android/cleanup.sh b/binary_search_tool/android/cleanup.sh
index c89c337..759b3ed 100755
--- a/binary_search_tool/android/cleanup.sh
+++ b/binary_search_tool/android/cleanup.sh
@@ -9,3 +9,7 @@
 #
 
 rm android/common.sh
+# Remove build command script if pass_bisect enabled
+rm -f android/cmd_script.sh
+# Remove tmp IR file used for ir_diff in pass beisction
+rm -f /tmp/bisection_bad_item.o
diff --git a/binary_search_tool/android/generate_cmd.sh b/binary_search_tool/android/generate_cmd.sh
index 7db3e7e..78a39b1 100755
--- a/binary_search_tool/android/generate_cmd.sh
+++ b/binary_search_tool/android/generate_cmd.sh
@@ -1,4 +1,4 @@
-#!/bin/bash -u
+#!/bin/bash -eu
 
 # Copyright 2018 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
@@ -28,14 +28,22 @@
 
 result=$(egrep -m 1 -- "${item}" ${populate_log})
 
+# Re-generate bad item to tmp directory location
+tmp_ir='/tmp/bisection_bad_item.o'
+result=$(sed "s|$item|-o $tmp_ir |g" <<< ${result})
+
 # Remove `:` after cd command
-result=$(sed 's/cd\:/cd/g' <<< ${result})
+result=$(sed 's|cd:|cd|g' <<< ${result})
 
 # Add environment variable which helps pass level bisection
-result=$(sed 's/ \-o / $LIMIT_FLAGS \-o /g' <<< ${result})
+result=$(sed 's| -o | $LIMIT_FLAGS -o |g' <<< ${result})
 
 output+=${result}
 
+# Symbolic link generated bad item to original object
+output+="\nln -f $tmp_ir $abs_path"
+output+="\ntouch $abs_path"
+
 echo -e "${output}" > android/cmd_script.sh
 
 chmod u+x android/cmd_script.sh