rust_uprev: emerge arm-none-eabi-gcc & do it in parallel

arm-none-eabi-gcc isn't mentioned in the list of RUSTC_TARGET_TRIPLES,
though it's necessary (we check for it in the ebuild)

While I'm in the area, if we're unconditionally emerge'ing all of these
anyway, do it in parallel. Doing so makes installation take 1/4 as long.

BUG=chromium:1136579, chromium:1112551
TEST=Ran the script

Change-Id: I49063487b2e2b2c83e2ef30dd8f8904b13c59f38
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2462927
Reviewed-by: Tiancong Wang <tcwang@google.com>
Tested-by: George Burgess <gbiv@chromium.org>
diff --git a/rust_tools/rust_uprev.py b/rust_tools/rust_uprev.py
index 1d29556..4fdae60 100755
--- a/rust_tools/rust_uprev.py
+++ b/rust_tools/rust_uprev.py
@@ -594,12 +594,23 @@
   m = target_triples_re.search(contents)
   assert m, 'RUST_TARGET_TRIPLES not found in rust ebuild'
   target_triples = m.group(1).strip().split('\n')
+
+  compiler_targets_to_install = [
+      target.strip() for target in target_triples if 'cros-' in target
+  ]
   for target in target_triples:
     if 'cros-' not in target:
       continue
     target = target.strip()
-    logging.info('Emerging cross compiler %s', target)
-    subprocess.check_call(['sudo', 'emerge', '-G', f'cross-{target}/gcc'])
+
+  # We also always need arm-none-eabi, though it's not mentioned in
+  # RUSTC_TARGET_TRIPLES.
+  compiler_targets_to_install.append('arm-none-eabi')
+
+  logging.info('Emerging cross compilers %s', compiler_targets_to_install)
+  subprocess.check_call(
+      ['sudo', 'emerge', '-j', '-G'] +
+      [f'cross-{target}/gcc' for target in compiler_targets_to_install])
 
 
 def create_new_commit(rust_version: RustVersion) -> None:
diff --git a/rust_tools/rust_uprev_test.py b/rust_tools/rust_uprev_test.py
index d13ce91..fc50600 100755
--- a/rust_tools/rust_uprev_test.py
+++ b/rust_tools/rust_uprev_test.py
@@ -436,8 +436,9 @@
   def test_build_cross_compiler(self, mock_call, mock_output):
     mock_output.return_value = f'rust-{self.new_version}.ebuild'
     cros_targets = [
-        'x86_64-cros-linux-gnu', 'armv7a-cros-linux-gnueabihf',
-        'aarch64-cros-linux-gnu'
+        'x86_64-cros-linux-gnu',
+        'armv7a-cros-linux-gnueabihf',
+        'aarch64-cros-linux-gnu',
     ]
     all_triples = ['x86_64-pc-linux-gnu'] + cros_targets
     rust_ebuild = 'RUSTC_TARGET_TRIPLES=(' + '\n\t'.join(all_triples) + ')'
@@ -445,11 +446,9 @@
     with mock.patch('builtins.open', mock_open):
       rust_uprev.build_cross_compiler()
 
-    emerge_calls = [
-        mock.call(['sudo', 'emerge', '-G', f'cross-{x}/gcc'])
-        for x in cros_targets
-    ]
-    mock_call.assert_has_calls(emerge_calls)
+    mock_call.assert_called_once_with(
+        ['sudo', 'emerge', '-j', '-G'] +
+        [f'cross-{x}/gcc' for x in cros_targets + ['arm-none-eabi']])
 
 
 if __name__ == '__main__':