Pick right Chrome build for Chrome OS.

From DEPS file, parse the comment about platform and choose build only
if it's 'all' or 'chromeos'. This check will help to avoid all Android
or iOS builds.

BUG=chromium:389304
TEST=Added unit test

Change-Id: I88466ba7fa52bacbdbc152be3b6c7bb636464cbe
Reviewed-on: https://chromium-review.googlesource.com/208982
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Dharani Govindan <dharani@chromium.org>
Commit-Queue: Dharani Govindan <dharani@chromium.org>
Tested-by: Dharani Govindan <dharani@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/210103
diff --git a/scripts/cros_mark_chrome_as_stable.py b/scripts/cros_mark_chrome_as_stable.py
index db7878f..36fbbea 100644
--- a/scripts/cros_mark_chrome_as_stable.py
+++ b/scripts/cros_mark_chrome_as_stable.py
@@ -119,6 +119,29 @@
   return _GetVersionContents(chrome_version_info)
 
 
+def CheckIfChromeRightForOS(url):
+  """Checks if DEPS is right for Chrome OS.
+
+  This function checks for a variable called 'buildspec_platforms' to
+  find out if its 'chromeos' or 'all'. If any of those values,
+  then it chooses that DEPS.
+
+  Args:
+    url: url where DEPS file present.
+
+  Returns:
+    True if DEPS is the right Chrome for Chrome OS.
+  """
+  deps_contents = cros_build_lib.RunCommand(['svn', 'cat', url],
+                                            redirect_stdout=True).output
+  platforms = re.search(r'buildspec_platforms.*\s.*\s', deps_contents).group()
+
+  if 'chromeos' in platforms or 'all' in platforms:
+    return True
+
+  return False
+
+
 def _GetLatestRelease(base_url, branch=None):
   """Gets the latest release version from the buildspec_url for the branch.
 
@@ -148,7 +171,8 @@
                                              error_code_ok=True,
                                              redirect_stdout=True).output
       if deps_check == 'DEPS\n':
-        return chrome_version.rstrip('/')
+        if CheckIfChromeRightForOS(deps_url):
+          return chrome_version.rstrip('/')
 
   return None
 
diff --git a/scripts/cros_mark_chrome_as_stable_unittest.py b/scripts/cros_mark_chrome_as_stable_unittest.py
index b54aed0..eeb2dbd 100755
--- a/scripts/cros_mark_chrome_as_stable_unittest.py
+++ b/scripts/cros_mark_chrome_as_stable_unittest.py
@@ -173,6 +173,27 @@
     self.mox.VerifyAll()
     self.assertEquals(version, '8.0.256.0')
 
+  def testCheckIfChromeRightForOS(self):
+    """Tests if we can find the chromeos build from our mock DEPS."""
+    ARBITRARY_URL = 'phthp://sores.chromium.org/tqs/7.0.224.1/DEPS'
+    test_data1 = "buildspec_platforms:\n    'chromeos,',\n"
+    test_data2 = "buildspec_platforms:\n    'android,',\n"
+    self.mox.StubOutWithMock(cros_build_lib, 'RunCommand')
+    cros_build_lib.RunCommand(
+        ['svn', 'cat', ARBITRARY_URL],
+        redirect_stdout=True).AndReturn(_StubCommandResult(test_data1))
+    cros_build_lib.RunCommand(
+        ['svn', 'cat', ARBITRARY_URL],
+        redirect_stdout=True).AndReturn(_StubCommandResult(test_data2))
+    self.mox.ReplayAll()
+    expected_deps = cros_mark_chrome_as_stable.CheckIfChromeRightForOS(
+        ARBITRARY_URL)
+    unexpected_deps = cros_mark_chrome_as_stable.CheckIfChromeRightForOS(
+        ARBITRARY_URL)
+    self.mox.VerifyAll()
+    self.assertTrue(expected_deps)
+    self.assertFalse(unexpected_deps)
+
   def testGetLatestRelease(self):
     """Tests if we can find the latest release from our mock url data."""
     ARBITRARY_URL = 'phthp://sores.chromium.org/tqs'
@@ -196,6 +217,12 @@
         error_code_ok=True, redirect_stdout=True).AndReturn(
           _StubCommandResult('DEPS\n'))
     self.mox.ReplayAll()
+    self.mox.StubOutWithMock(cros_mark_chrome_as_stable,
+                             'CheckIfChromeRightForOS')
+    cros_mark_chrome_as_stable.CheckIfChromeRightForOS(
+        ARBITRARY_URL + '/releases/7.0.224.2/DEPS').AndReturn(
+            _StubCommandResult('True'))
+    self.mox.ReplayAll()
     release = cros_mark_chrome_as_stable._GetLatestRelease(ARBITRARY_URL)
     self.mox.VerifyAll()
     self.assertEqual('7.0.224.2', release)
@@ -219,6 +246,12 @@
         error_code_ok=True, redirect_stdout=True).AndReturn(
           _StubCommandResult('DEPS\n'))
     self.mox.ReplayAll()
+    self.mox.StubOutWithMock(cros_mark_chrome_as_stable,
+                             'CheckIfChromeRightForOS')
+    cros_mark_chrome_as_stable.CheckIfChromeRightForOS(
+        ARBITRARY_URL + '/releases/8.0.224.2/DEPS').AndReturn(
+            _StubCommandResult(True))
+    self.mox.ReplayAll()
     release = cros_mark_chrome_as_stable._GetLatestRelease(ARBITRARY_URL,
                                                            '8.0.224')
     self.mox.VerifyAll()