[cros_update_firmware] Clean portage metadata cache before emerge the board's firmware package

BUG=b:122467913,b:122583794
TEST=build pacakges, modify chromeos-config/yaml/config.yaml, run cros_update_firmware passes
Change-Id: Ia25688adb83caebef9d8cd835707b324889fb488
Reviewed-on: https://chromium-review.googlesource.com/1428419
Commit-Ready: Ned Nguyen <nednguyen@google.com>
Tested-by: Ned Nguyen <nednguyen@google.com>
Reviewed-by: Ned Nguyen <nednguyen@google.com>
Reviewed-by: YH Lin <yueherngl@chromium.org>
diff --git a/contrib/cros_update_firmware b/contrib/cros_update_firmware
index a8eaa44..efc6048 100755
--- a/contrib/cros_update_firmware
+++ b/contrib/cros_update_firmware
@@ -84,7 +84,9 @@
        || result[i]=$?
   done
 
-  base="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private/chromeos-base"
+  overlay="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private"
+  metadata="${overlay}/metadata"
+  base="${overlay}/chromeos-base"
   ebuild="${base}/chromeos-firmware-${board}/chromeos-firmware-${board}-9999.ebuild"
   srcuris="${base}/chromeos-firmware-${board}/files/srcuris"
   yaml_config="/build/${board}/usr/share/chromeos-config/yaml/config.yaml"
@@ -92,6 +94,12 @@
   "emerge-${board}" ${cfg_bsp_baseboard_pkg} "${cfg_bsp_pkg}" chromeos-config
   cros_config_host -c "${yaml_config}" get-firmware-uris > "${srcuris}"
   touch "${ebuild}"
+  # clean metadata cache to make sure SRC_URI is fetched from ${srcuris}
+  # instead from portage cache which maybe out of sync
+  # Note: this workaround is needed because we break the SRC_URI API contract
+  # which is supposed to be a static (see
+  # https://devmanual.gentoo.org/general-concepts/portage-cache/index.html)
+  rm -rf "${metadata}/cache" "${metadata}/md5-cache"
   "ebuild-${board}" "${ebuild}" manifest
   "emerge-${board}" "chromeos-firmware-${board}"