Force autoroller to fail if any dep is missing

Force auto roll of chromium third_party into WebRTC to fail if any one
of required chromium-specific dependencies is missing in chromium
third_party repo of after checking it into WebRTC repo.

Also try to fix some flakes in autoroller.

Bug: webrtc:8366
Change-Id: I781cd4d4a4a230fb126cc32d8147310f70ab8b91
Reviewed-on: https://webrtc-review.googlesource.com/77722
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23340}
diff --git a/tools_webrtc/autoroller/roll_deps.py b/tools_webrtc/autoroller/roll_deps.py
index fd5db0a..bd1032c 100755
--- a/tools_webrtc/autoroller/roll_deps.py
+++ b/tools_webrtc/autoroller/roll_deps.py
@@ -434,11 +434,26 @@
 
   deps_to_checkout = _LoadThirdPartyDepsAndFiles(third_party_deps_file)
   # Update existing chromium third_party checkout to new rev.
-  _RunCommand(['git', 'fetch', 'origin', new_rev], working_dir=source_dir)
+  _RunCommand(['git', 'fetch', 'origin'], working_dir=source_dir)
+  _RunCommand(['git', 'checkout', new_rev], working_dir=source_dir)
   # Checkout chromium repo into dest dir basing on source checkout.
   _RunCommand(
       ['git', '--git-dir', '%s/.git' % source_dir, 'checkout',
        new_rev] + deps_to_checkout, working_dir=dest_dir)
+  # Ensure all chromium dependencies are presented
+  deps_set = set(deps_to_checkout)
+  stdout, _ = _RunCommand(['git', 'ls-tree', '--name-only', 'HEAD'],
+                          working_dir=source_dir)
+  if not deps_set.issubset(set(stdout.split('\n'))):
+    raise RollError('Missed required chromium dependencies in chromium '
+                    'third_party repo: %s' % json.dumps(
+        list(deps_set.difference(set(stdout.split('\n'))))))
+  stdout, _ = _RunCommand(['git', 'ls-tree', '--name-only', 'HEAD'],
+                          working_dir=dest_dir)
+  if not deps_set.issubset(set(stdout.split('\n'))):
+    raise RollError('Missed required chromium dependencies after checking in '
+                    'chromium third_party repo: %s' % json.dumps(
+        list(deps_set.difference(set(stdout.split('\n'))))))
 
 
 def _IsTreeClean():