From 5613f356635e810dcc1e3849011bec5764095963 Mon Sep 17 00:00:00 2001
From: Andras Becsi <andras.becsi@digia.com>
Date: Wed, 12 Mar 2014 14:20:37 +0100
Subject: [PATCH] Improve sanity checking of the parsed DEPS submodules

This is in preparation of updating to the new stable branch 1750
(Chromium version 33.0.1750.x)
Move the sanityCheckModules function to version_resolver.py and
check if the parsed svn refs exist in the remote git repository.
If they do not exist fall back to the git shasum we parsed from
the .DEPS.git file.
This patch also removes the unused parseFile function.

Change-Id: Ie0c11fdd9326ee87e9dcc670c0a7c26f9a498fd5
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
---
 tools/scripts/git_submodule.py    | 43 +++++++------------------------
 tools/scripts/version_resolver.py | 33 +++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/tools/scripts/git_submodule.py b/tools/scripts/git_submodule.py
index 6d2fbd1eb..a364ef650 100644
--- a/tools/scripts/git_submodule.py
+++ b/tools/scripts/git_submodule.py
@@ -85,6 +85,9 @@ class DEPSParser:
                 submodule = Submodule(subdir, repo)
                 submodule.os = os
                 submodule.shasum = shasum
+                if not submodule.matchesOS():
+                    print '-- skipping ' + submodule.path + ' for this operating system. --'
+                    continue
                 if not submodule.shasum:
                     # We need to parse the svn branch and revision number.
                     ref = repo
@@ -116,24 +119,6 @@ class DEPSParser:
                 submodules.append(submodule)
         return submodules
 
-    def sanityCheckModules(self, submodules):
-        submodule_dict = {}
-        for submodule in submodules:
-            if not submodule.matchesOS():
-                print '-- skipping ' + submodule.path + ' for this operating system. --'
-                continue
-            if submodule.path in submodule_dict:
-                prev_module = submodule_dict[submodule.path]
-                # We might have to create our own DEPS file if different platforms use different branches,
-                # but for now it should be safe to select the latest revision from the requirements.
-                if submodule.shasum or prev_module.revision >= submodule.revision:
-                    continue
-                if prev_module.ref != submodule.ref:
-                    sys.exit('ERROR: branch mismatch for ' + submodule.path + '(' + prev_module.ref + ' vs ' + submodule.ref + ')')
-                print('Duplicate submodule ' + submodule.path + '. Using latest revison ' + str(submodule.revision) + '.')
-            submodule_dict[submodule.path] = submodule
-        return list(submodule_dict.values())
-
     def parse(self, deps_content):
         exec(deps_content, self.global_scope, self.local_scope)
 
@@ -141,19 +126,7 @@ class DEPSParser:
         submodules.extend(self.createSubmodulesFromScope(self.local_scope['deps'], 'all'))
         for os_dep in self.local_scope['deps_os']:
             submodules.extend(self.createSubmodulesFromScope(self.local_scope['deps_os'][os_dep], os_dep))
-
-        return self.sanityCheckModules(submodules)
-
-    def parseFile(self, deps_file_name):
-        currentDir = os.getcwd()
-        if not os.path.isfile(deps_file_name):
-            return []
-        deps_file = open(deps_file_name)
-        deps_content = deps_file.read().decode('utf-8')
-        deps_file.close()
-        return self.parse(deps_content)
-
-
+        return submodules
 
 class Submodule:
     def __init__(self, path='', url='', shasum='', os=[], ref=''):
@@ -186,9 +159,11 @@ class Submodule:
         error = 0
         if self.ref:
             # Fetch the ref we parsed from the DEPS file.
-            val = subprocessCall(['git', 'fetch', 'origin', self.ref])
-            if val != 0:
-                sys.exit("Could not fetch branch from upstream " + self.ref)
+            error = subprocessCall(['git', 'fetch', 'origin', self.ref])
+            if error != 0:
+                print('ERROR: Could not fetch from upstream branch ' + self.ref)
+                return error
+
             error = subprocessCall(['git', 'checkout', 'FETCH_HEAD']);
 
             search_string = ''
diff --git a/tools/scripts/version_resolver.py b/tools/scripts/version_resolver.py
index 94ba9e1ab..b52b8f501 100644
--- a/tools/scripts/version_resolver.py
+++ b/tools/scripts/version_resolver.py
@@ -42,6 +42,7 @@
 #############################################################################
 
 import os
+import subprocess
 import sys
 import json
 import urllib2
@@ -73,6 +74,36 @@ def readReleaseChannels():
             channels[os].append({ 'channel': ver['channel'], 'version': ver['version'], 'branch': ver['true_branch'] })
     return channels
 
+def sanityCheckModules(submodules):
+    submodule_dict = {}
+    sys.stdout.write('\nverifying submodule refs.')
+    for submodule in submodules:
+        sys.stdout.flush()
+        if submodule.path in submodule_dict:
+            prev_module = submodule_dict[submodule.path]
+            # We might have to create our own DEPS file if different platforms use different branches,
+            # but for now it should be safe to select the latest revision from the requirements.
+            if submodule.shasum or prev_module.revision >= submodule.revision:
+                continue
+            if prev_module.ref != submodule.ref:
+                # Ignore for Android which might lag behind.
+                if submodule.os == 'android':
+                    continue
+                sys.exit('ERROR: branch mismatch for ' + submodule.path + '(' + prev_module.ref + ' vs ' + submodule.ref + ')')
+            print('Duplicate submodule ' + submodule.path + '. Using latest revison ' + str(submodule.revision) + '.')
+        if submodule.ref:
+            sys.stdout.write('.')
+            result = subprocess.check_output(['git', 'ls-remote', submodule.url, submodule.ref])
+            # Fallback to git shasum if the parsed remote ref does not exist in the git repository.
+            if submodule.ref not in result:
+                submodule.ref = submodule.revision = ''
+                if not submodule.shasum:
+                    sys.exit('\nERROR: No valid remote found!')
+            sys.stdout.flush()
+        submodule_dict[submodule.path] = submodule
+    print('done.\n')
+    return list(submodule_dict.values())
+
 def readSubmodules():
     response = urllib2.urlopen(base_deps_url + chromium_version + '/DEPS')
     svn_deps = response.read().strip()
@@ -103,4 +134,4 @@ def readSubmodules():
                 # We use the git shasum as fallback.
                 module.shasum = git.shasum
 
-    return list(submodule_dict.values())
+    return sanityCheckModules(submodule_dict.values())
-- 
GitLab