rust_uprev: Remove flip_mirror_in_ebuild

Previously, we temporarily switched on RESTRICT="mirror" for
an ebuild before updating the manifest. This allows us to fetch
distfiles from their original locations (rather than the default,
which is to require them to be fetched from mirrors). We don't
actually need this, so this change removes the code that does
this.

BUG=None
TEST=unit tests, also tested on rust-1.60.0 uprev

Change-Id: I5f29ffad83a5826dbe523db4657d9ea17c43bcff
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/3594132
Commit-Queue: Bob Haarman <inglorion@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Bob Haarman <inglorion@chromium.org>
diff --git a/rust_tools/rust_uprev.py b/rust_tools/rust_uprev.py
index 49df717..7e17044 100755
--- a/rust_tools/rust_uprev.py
+++ b/rust_tools/rust_uprev.py
@@ -360,27 +360,6 @@
                new_bootstrap_version)
 
 
-def flip_mirror_in_ebuild(ebuild_file: Path, add: bool) -> None:
-  restrict_re = re.compile(
-      r'(?P<before>RESTRICT=")(?P<values>"[^"]*"|.*)(?P<after>")')
-  with open(ebuild_file, encoding='utf-8') as f:
-    contents = f.read()
-  m = restrict_re.search(contents)
-  assert m, 'failed to find RESTRICT variable in Rust ebuild'
-  values = m.group('values')
-  if add:
-    if 'mirror' in values:
-      return
-    values += ' mirror'
-  else:
-    if 'mirror' not in values:
-      return
-    values = values.replace(' mirror', '')
-  new_contents = restrict_re.sub(r'\g<before>%s\g<after>' % values, contents)
-  with open(ebuild_file, 'w', encoding='utf-8') as f:
-    f.write(new_contents)
-
-
 def ebuild_actions(package: str,
                    actions: List[str],
                    sudo: bool = False) -> None:
@@ -482,11 +461,7 @@
 def update_manifest(ebuild_file: os.PathLike) -> None:
   """Updates the MANIFEST for the ebuild at the given path."""
   ebuild = Path(ebuild_file)
-  logging.info('Added "mirror" to RESTRICT to %s', ebuild.name)
-  flip_mirror_in_ebuild(ebuild, add=True)
   ebuild_actions(ebuild.parent.name, ['manifest'])
-  logging.info('Removed "mirror" to RESTRICT from %s', ebuild.name)
-  flip_mirror_in_ebuild(ebuild, add=False)
 
 
 def update_rust_packages(rust_version: RustVersion, add: bool) -> None:
diff --git a/rust_tools/rust_uprev_test.py b/rust_tools/rust_uprev_test.py
index 90f59e4..2e6e871 100755
--- a/rust_tools/rust_uprev_test.py
+++ b/rust_tools/rust_uprev_test.py
@@ -234,48 +234,11 @@
 class UpdateManifestTest(unittest.TestCase):
   """Tests for update_manifest step in rust_uprev"""
 
-  # pylint: disable=protected-access
-  def _run_test_flip_mirror(self, before, after, add, expect_write):
-    mock_open = mock.mock_open(read_data=f'RESTRICT="{before}"')
-    with mock.patch('builtins.open', mock_open):
-      rust_uprev.flip_mirror_in_ebuild('', add=add)
-    if expect_write:
-      mock_open.return_value.__enter__().write.assert_called_once_with(
-          f'RESTRICT="{after}"')
-
-  def test_add_mirror_in_ebuild(self):
-    self._run_test_flip_mirror(before='variable1 variable2',
-                               after='variable1 variable2 mirror',
-                               add=True,
-                               expect_write=True)
-
-  def test_remove_mirror_in_ebuild(self):
-    self._run_test_flip_mirror(before='variable1 variable2 mirror',
-                               after='variable1 variable2',
-                               add=False,
-                               expect_write=True)
-
-  def test_add_mirror_when_exists(self):
-    self._run_test_flip_mirror(before='variable1 variable2 mirror',
-                               after='variable1 variable2 mirror',
-                               add=True,
-                               expect_write=False)
-
-  def test_remove_mirror_when_not_exists(self):
-    self._run_test_flip_mirror(before='variable1 variable2',
-                               after='variable1 variable2',
-                               add=False,
-                               expect_write=False)
-
-  @mock.patch.object(rust_uprev, 'flip_mirror_in_ebuild')
   @mock.patch.object(rust_uprev, 'ebuild_actions')
-  def test_update_manifest(self, mock_run, mock_flip):
+  def test_update_manifest(self, mock_run):
     ebuild_file = Path('/path/to/rust/rust-1.1.1.ebuild')
     rust_uprev.update_manifest(ebuild_file)
     mock_run.assert_called_once_with('rust', ['manifest'])
-    mock_flip.assert_has_calls(
-        [mock.call(ebuild_file, add=True),
-         mock.call(ebuild_file, add=False)])
 
 
 class UpdateBootstrapEbuildTest(unittest.TestCase):