cros_setup_toolchain: install compiler-rt for armv7a-cros-linux-gnueabihf

The armv7a-cros-linux-gnueabi is actually the same with armv7a-cros-linux-gnueabihf with
different names for ChromeOS. So armv7a-cros-linux-gnueabi/compiler-rt and
armv7a-cros-linux-gnueabihf/compiler-rt produce the same contents.
To avoid file installation conflict, we did not install anything for
armv7a-cros-linux-gnueabihf/compiler-rt. This makes the compier-rt is
missing in standalone toolchain.
This CL copies the content of armv7a-cros-linux-gnueabi/compiler-rt when
creating standalone armv7a-cros-linux-gnueabihf toolchain.

BUG=chromium:833969
TEST=compiler-rt is installed into  armv7a-cros-linux-gnueabihf

Change-Id: I4f123582b1aa5ff9f7f5cd710911dbb588d98644
Reviewed-on: https://chromium-review.googlesource.com/1033188
Commit-Ready: Yunlian Jiang <yunlian@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 0a8e991..80836df 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -919,7 +919,32 @@
     if pkg == 'ex_go':
       continue
 
-    atom = GetPortagePackage(target, pkg)
+    # Use armv7a-cros-linux-gnueabi/compiler-rt for
+    # armv7a-cros-linux-gnueabihf/compiler-rt.
+    # Currently the armv7a-cros-linux-gnueabi is actually
+    # the same as armv7a-cros-linux-gnueabihf with different names.
+    # Because of that, for compiler-rt, it generates the same binary in
+    # the same location. To avoid the installation conflict, we do not
+    # install anything for 'armv7a-cros-linux-gnueabihf'. This would cause
+    # problem if other people try to use standalone armv7a-cros-linux-gnueabihf
+    # toolchain.
+    if 'compiler-rt' in pkg and 'armv7a-cros-linux-gnueabi' in target:
+      atom = GetPortagePackage(target, pkg)
+      cat, pn = atom.split('/')
+      ver = GetInstalledPackageVersions(atom, root=root)[0]
+      # pylint: disable=E1101
+      dblink = portage.dblink(cat, pn + '-' + ver, myroot=root,
+                              settings=portage.settings)
+      contents = dblink.getcontents()
+      if not contents:
+        if 'hf' in target:
+          new_target = 'armv7a-cros-linux-gnueabi'
+        else:
+          new_target = 'armv7a-cros-linux-gnueabihf'
+        atom = GetPortagePackage(new_target, pkg)
+    else:
+      atom = GetPortagePackage(target, pkg)
+
     cat, pn = atom.split('/')
     ver = GetInstalledPackageVersions(atom, root=root)[0]
     logging.info('packaging %s-%s', atom, ver)