gclient: Don't use buildspecs to checkout chrome starting with m90.

This changes legacy release builders to checkout chrome via the standard
chromium flow rather than using buildspecs on chrome versions 90 and
above. This means the legacy builders will instead fetch
chromium/src.git directly at the specified release tag, then recurse
through that top-level DEPS file to checkout the remainder of the tree.
This is now the standard checkout flow while buildspecs are mostly
unsupported at this time.

This also modernizes gclient.py with several fixes/improvements:
- The .gclient file format of '$URL@refs/tags/12.34.5.6' has been
  replaced with '$URL@12.34.5.6' as the former doesn't appear to work
  with gclient while the latter does.
- Stop specifying the specific deps_file to use and let gclient pick the
  right default.
- Stop specifying a second solution for the src-internal repo. That repo
  is now a direct child of chromium/src's top-level DEPS file.
- Some refactoring of various methods now that _GetGclientURLs() no
  longer returns multiple URLs.
- Specify the correct 'checkout_(google|src)_internal' gclient vars when
  fetching an internal checkout, as the internal bits are only checked
  out when those two vars are true.

BUG=chromium:1170480
TEST=unittest

Change-Id: I030da3355e3093b8107aed6ffb8d55815e84f9f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2653783
Reviewed-by: Dhanya Ganesh <dhanyaganesh@chromium.org>
Reviewed-by: George Engelbrecht <engeg@google.com>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Tested-by: Ben Pastene <bpastene@chromium.org>
diff --git a/lib/gclient.py b/lib/gclient.py
index 4b89e2d..81f7198 100644
--- a/lib/gclient.py
+++ b/lib/gclient.py
@@ -118,37 +118,39 @@
   """Get the URLs and deps_file values to use in gclient file.
 
   See WriteConfigFile below.
-  """
-  results = []
 
+  Returns:
+    Tuple of (name, url, deps_file).
+  """
   if rev is None or git.IsSHA1(rev) or rev == 'HEAD':
     # Regular chromium checkout; src may float to origin/master or be pinned.
     url = constants.CHROMIUM_GOB_URL
 
     if rev:
       url += ('@' + rev)
-    results.append(('src', url, '.DEPS.git'))
-    if internal:
-      results.append(
-          ('src-internal', constants.CHROME_INTERNAL_GOB_URL, '.DEPS.git'))
-  elif internal:
-    # Internal buildspec: check out the buildspec repo and set deps_file to
-    # the path to the desired release spec.
-    site_params = config_lib.GetSiteParams()
-    url = site_params.INTERNAL_GOB_URL + '/chrome/tools/buildspec.git'
-
-    # Chromium switched to DEPS at version 45.0.2432.3.
-    deps_file = '.DEPS.git' if BuildspecUsesDepsGit(rev) else 'DEPS'
-
-    results.append(('CHROME_DEPS', url, 'releases/%s/%s' % (rev, deps_file)))
+    return 'src', url, None
   else:
-    # External buildspec: use the main chromium src repository, pinned to the
-    # release tag, with deps_file set to .DEPS.git (which is created by
-    # publish_deps.py).
-    url = constants.CHROMIUM_GOB_URL + '@refs/tags/' + rev
-    results.append(('src', url, '.DEPS.git'))
+    try:
+      major = int(rev.split('.')[0])
+    except ValueError:
+      major = None
+    # Starting with m90, start using the normal gclient fetch process rather
+    # than buildspecs. But keep using buildspecs for older versions for safety.
+    if major and major < 90 and internal:
+      # Internal buildspec: check out the buildspec repo and set deps_file to
+      # the path to the desired release spec.
+      site_params = config_lib.GetSiteParams()
+      url = site_params.INTERNAL_GOB_URL + '/chrome/tools/buildspec.git'
 
-  return results
+      # Chromium switched to DEPS at version 45.0.2432.3.
+      deps_file = '.DEPS.git' if BuildspecUsesDepsGit(rev) else 'DEPS'
+
+      return 'CHROME_DEPS', url, 'releases/%s/%s' % (rev, deps_file)
+    else:
+      # Normal gclient fetch process: use the main chromium src repository,
+      # pinned to the release tag.
+      url = constants.CHROMIUM_GOB_URL + '@' + rev
+      return 'src', url, None
 
 
 def _GetGclientSolutions(internal, rev, template, managed):
@@ -156,27 +158,22 @@
 
   See WriteConfigFile below.
   """
-  urls = _GetGclientURLs(internal, rev)
+  name, url, deps_file = _GetGclientURLs(internal, rev)
   solutions = LoadGclientFile(template) if template is not None else []
-  for (name, url, deps_file) in urls:
-    solution = _FindOrAddSolution(solutions, name)
-    # Always override 'url' and 'deps_file' of a solution as we need to specify
-    # the revision information.
-    solution['url'] = url
-    if deps_file:
-      solution['deps_file'] = deps_file
-
-      # TODO(engeg@): Remove this ugly hack once we get an acceptable build.
-      #               See crbug.com/1044411 for more information. We landed
-      #               this custom dep here: crrev.com/i/3304125.
-      if deps_file == 'releases/51.0.2701.0/DEPS':
-        solution['deps_file'] = 'releases/51.0.2701.0/DEPS_crbug_1044411'
-
-    # Use 'custom_deps' and 'custom_vars' of a solution when specified by the
-    # template gclient file.
-    solution.setdefault('custom_deps', {})
-    solution.setdefault('custom_vars', {})
-    solution.setdefault('managed', managed)
+  solution = _FindOrAddSolution(solutions, name)
+  # Always override 'url' and 'deps_file' of a solution as we need to specify
+  # the revision information.
+  solution['url'] = url
+  if deps_file:
+    solution['deps_file'] = deps_file
+  # Use 'custom_deps' and 'custom_vars' of a solution when specified by the
+  # template gclient file.
+  solution.setdefault('custom_deps', {})
+  solution.setdefault('custom_vars', {})
+  if internal:
+    solution['custom_vars'].setdefault('checkout_src_internal', True)
+    solution['custom_vars'].setdefault('checkout_google_internal', True)
+  solution.setdefault('managed', managed)
 
   return solutions
 
diff --git a/lib/gclient_unittest.py b/lib/gclient_unittest.py
index 2c6c658..d37aeeb 100644
--- a/lib/gclient_unittest.py
+++ b/lib/gclient_unittest.py
@@ -43,7 +43,6 @@
     gclient.WriteConfigFile('gclient', self._TEST_CWD, False, None)
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git'}]
@@ -57,7 +56,6 @@
                             git_cache_dir='/exists')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git'}]
@@ -71,7 +69,6 @@
                             git_cache_dir='/doesnotexist')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git'}]
@@ -85,7 +82,6 @@
                             use_cache=False)
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git'}]
@@ -96,17 +92,11 @@
     """Test WriteConfigFile with chrome checkout and no revision."""
     gclient.WriteConfigFile('gclient', self._TEST_CWD, True, None)
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'managed': True,
   'name': 'src',
-  'url': 'https://chromium.googlesource.com/chromium/src.git'},
- {'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
-  'managed': True,
-  'name': 'src-internal',
-  'url': 'https://chrome-internal.googlesource.com/chrome/src-internal.git'}]
+  'url': 'https://chromium.googlesource.com/chromium/src.git'}]
 target_os = ['chromeos']
 cache_dir = '/b/git-cache'
 """)
@@ -117,7 +107,6 @@
                             '7becbe4afb42b3301d42149d7d1cade017f150ff')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git@7becbe4afb42b3301d42149d7d1cade017f150ff'}]
@@ -130,17 +119,11 @@
     gclient.WriteConfigFile('gclient', self._TEST_CWD, True,
                             '7becbe4afb42b3301d42149d7d1cade017f150ff')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'managed': True,
   'name': 'src',
-  'url': 'https://chromium.googlesource.com/chromium/src.git@7becbe4afb42b3301d42149d7d1cade017f150ff'},
- {'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
-  'managed': True,
-  'name': 'src-internal',
-  'url': 'https://chrome-internal.googlesource.com/chrome/src-internal.git'}]
+  'url': 'https://chromium.googlesource.com/chromium/src.git@7becbe4afb42b3301d42149d7d1cade017f150ff'}]
 target_os = ['chromeos']
 cache_dir = '/b/git-cache'
 """)
@@ -150,7 +133,6 @@
     gclient.WriteConfigFile('gclient', self._TEST_CWD, False, 'HEAD')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git@HEAD'}]
@@ -162,17 +144,11 @@
     """Test WriteConfigFile with chrome checkout at a given git revision."""
     gclient.WriteConfigFile('gclient', self._TEST_CWD, True, 'HEAD')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'managed': True,
   'name': 'src',
-  'url': 'https://chromium.googlesource.com/chromium/src.git@HEAD'},
- {'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
-  'managed': True,
-  'name': 'src-internal',
-  'url': 'https://chrome-internal.googlesource.com/chrome/src-internal.git'}]
+  'url': 'https://chromium.googlesource.com/chromium/src.git@HEAD'}]
 target_os = ['chromeos']
 cache_dir = '/b/git-cache'
 """)
@@ -183,17 +159,11 @@
                             '7becbe4afb42b3301d42149d7d1cade017f150ff',
                             managed=False)
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'managed': False,
   'name': 'src',
-  'url': 'https://chromium.googlesource.com/chromium/src.git@7becbe4afb42b3301d42149d7d1cade017f150ff'},
- {'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
-  'managed': False,
-  'name': 'src-internal',
-  'url': 'https://chrome-internal.googlesource.com/chrome/src-internal.git'}]
+  'url': 'https://chromium.googlesource.com/chromium/src.git@7becbe4afb42b3301d42149d7d1cade017f150ff'}]
 target_os = ['chromeos']
 cache_dir = '/b/git-cache'
 """)
@@ -202,7 +172,8 @@
     """Test WriteConfigFile with chrome checkout at a given release tag."""
     gclient.WriteConfigFile('gclient', self._TEST_CWD, True, '45.0.2431.1')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
-  'custom_vars': {},
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'deps_file': 'releases/45.0.2431.1/DEPS',
   'managed': True,
   'name': 'CHROME_DEPS',
@@ -216,10 +187,9 @@
     gclient.WriteConfigFile('gclient', self._TEST_CWD, False, '41.0.2270.0')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
   'custom_vars': {},
-  'deps_file': '.DEPS.git',
   'managed': True,
   'name': 'src',
-  'url': 'https://chromium.googlesource.com/chromium/src.git@refs/tags/41.0.2270.0'}]
+  'url': 'https://chromium.googlesource.com/chromium/src.git@41.0.2270.0'}]
 target_os = ['chromeos']
 cache_dir = '/b/git-cache'
 """)
@@ -228,7 +198,8 @@
     """Test WriteConfigFile with chrome checkout at a given release tag."""
     gclient.WriteConfigFile('gclient', self._TEST_CWD, True, '41.0.2270.0')
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
-  'custom_vars': {},
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'deps_file': 'releases/41.0.2270.0/.DEPS.git',
   'managed': True,
   'name': 'CHROME_DEPS',
@@ -264,19 +235,40 @@
                             '7becbe4afb42b3301d42149d7d1cade017f150ff',
                             template=template_path)
     self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {'dep1': '1'},
-  'custom_vars': {'var1': 'test1', 'var2': 'test2'},
-  'deps_file': '.DEPS.git',
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True,
+                  'var1': 'test1',
+                  'var2': 'test2'},
   'managed': True,
   'name': 'src',
   'url': 'https://chromium.googlesource.com/chromium/src.git@7becbe4afb42b3301d42149d7d1cade017f150ff'},
  {'custom_deps': {'dep2': '2', 'dep3': '3'}, 'name': 'no-vars'},
- {'custom_vars': {'var3': 'a', 'var4': 'b'}, 'name': 'no-deps'},
- {'custom_deps': {},
-  'custom_vars': {},
-  'deps_file': '.DEPS.git',
+ {'custom_vars': {'var3': 'a', 'var4': 'b'}, 'name': 'no-deps'}]
+target_os = ['chromeos']
+cache_dir = '/b/git-cache'
+""")
+
+  def testChromeSpecWithReleaseTagAfter90(self):
+    """Test WriteConfigFile with chrome checkout at a given release tag."""
+    gclient.WriteConfigFile('gclient', self._TEST_CWD, True, '91.0.2431.1')
+    self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
+  'custom_vars': {'checkout_google_internal': True,
+                  'checkout_src_internal': True},
   'managed': True,
-  'name': 'src-internal',
-  'url': 'https://chrome-internal.googlesource.com/chrome/src-internal.git'}]
+  'name': 'src',
+  'url': 'https://chromium.googlesource.com/chromium/src.git@91.0.2431.1'}]
+target_os = ['chromeos']
+cache_dir = '/b/git-cache'
+""")
+
+  def testChromeSpecWithReleaseTagPublicAfter90(self):
+    """Test WriteConfigFile with chrome checkout at a given release tag."""
+    gclient.WriteConfigFile('gclient', self._TEST_CWD, False, '91.0.2431.1')
+    self._AssertGclientConfigSpec("""solutions = [{'custom_deps': {},
+  'custom_vars': {},
+  'managed': True,
+  'name': 'src',
+  'url': 'https://chromium.googlesource.com/chromium/src.git@91.0.2431.1'}]
 target_os = ['chromeos']
 cache_dir = '/b/git-cache'
 """)