bisect-kit: Fix localbuild symlink bug

There are times when the symlink created must point to a path inside the
chromeos chroot instead of to a path in the chromeos root checkout.
This patch removes asserts that were triggered when they shouldn't have
as well as creating the correct symlinks.

BUG=b:181066424
TEST=# switch_cros_localbuild.py

Change-Id: I0b7cd30eb393d137df6657d04c65c66161e5aaeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/bisect-kit/+/2811865
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Auto-Submit: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Kuang-che Wu <kcwu@chromium.org>
diff --git a/bisect_kit/cros_util.py b/bisect_kit/cros_util.py
index d490c22..f3510f1 100644
--- a/bisect_kit/cros_util.py
+++ b/bisect_kit/cros_util.py
@@ -1134,7 +1134,6 @@
 
   # Handle relative path.
   if '://' not in image_path and not os.path.isabs(image_path):
-    assert os.path.exists(os.path.join(chromeos_root, image_path))
     image_path = os.path.join(chromeos_root_inside_chroot, image_path)
 
   args = [
diff --git a/switch_cros_localbuild.py b/switch_cros_localbuild.py
index 0ecd89d..1d32801 100755
--- a/switch_cros_localbuild.py
+++ b/switch_cros_localbuild.py
@@ -187,14 +187,21 @@
   image_path = os.path.join(image_folder, cros_util.test_image_filename)
 
   # If the given version is already built, reuse it.
-  if not os.path.exists(os.path.join(chromeos_root, image_path)):
+  chromeos_root_image_folder = os.path.join(chromeos_root, image_folder)
+  chromeos_root_image_path = os.path.join(chromeos_root, image_path)
+  if not os.path.exists(chromeos_root_image_path):
     _build_packages(opts)
     built_image_folder = cros_util.build_image(chromeos_root, opts.board)
     image_name = os.path.basename(
         os.path.join(chromeos_root, built_image_folder))
-    os.symlink(image_name, os.path.join(chromeos_root, image_folder))
+    os.makedirs(os.path.dirname(chromeos_root_image_folder), exist_ok=True)
+    if os.path.exists(chromeos_root_image_folder):
+      os.unlink(chromeos_root_image_folder)
+    # Create a relative symlink, so the condition actually only comes in here if
+    # the image folder is actually missing.
+    os.symlink(os.path.join('../../..', built_image_folder),
+               chromeos_root_image_folder)
 
-  assert os.path.exists(os.path.join(chromeos_root, image_path))
   return image_path