Add Windows support to coverage.py.

With these fixes, coverage.py successfully generated coverage reports on
Windows for various browser_tests and interactive_ui_tests. I also tried
for unit_tests, but couldn't generate a coverage-enabled build--the
linker fails with OOM errors. The build machine has 64GB RAM, which
seems like it should be plenty. So it seems there is more work to be
done to fully enable coverage builds on Windows, perhaps already tracked
by http://crbug.com/846918? Building browser_tests also OOM'ed, but
finally succeeded after I set is_component_build to true.

gn gen D:\cr\src\out\coverage --root=D:\cr\src "--args=is_debug = false
is_component_build = true enable_nacl = false use_clang_coverage = true
 dcheck_always_on = true" --ide=vs

Example usage:
python tools/code_coverage/coverage.py browser_tests -b
D:/cr/src/out/coverage -o D:/cr/src/out/report  -c
"D:/cr/src/out/coverage/browser_tests.exe --gtest_filter=
SyncFileSystemTest.AuthorizationTest" -f
chrome/browser/apps/platform_apps/api/sync_file_system/

Bug: 809150
Change-Id: Ie2419aad80fbc1cca5c5f15257536c96ee25d77f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2189255
Reviewed-by: Bruce Dawson <[email protected]>
Reviewed-by: Yuke Liao <[email protected]>
Commit-Queue: Brent McBride <[email protected]>
Cr-Commit-Position: refs/heads/master@{#767396}
diff --git a/tools/code_coverage/coverage.py b/tools/code_coverage/coverage.py
index 8b3b7a4..a4b8f88c 100755
--- a/tools/code_coverage/coverage.py
+++ b/tools/code_coverage/coverage.py
@@ -157,7 +157,11 @@
     LLVM_COV_PATH = os.path.join(llvm_bin_dir, 'llvm-cov')
     LLVM_PROFDATA_PATH = os.path.join(llvm_bin_dir, 'llvm-profdata')
   else:
-    update.UpdatePackage('coverage_tools')
+    update.UpdatePackage('coverage_tools', coverage_utils.GetHostPlatform())
+
+  if coverage_utils.GetHostPlatform() == 'win':
+    LLVM_COV_PATH += '.exe'
+    LLVM_PROFDATA_PATH += '.exe'
 
   coverage_tools_exist = (
       os.path.exists(LLVM_COV_PATH) and os.path.exists(LLVM_PROFDATA_PATH))
@@ -290,8 +294,11 @@
                 default value is derived based on CPUs availability.
   """
   logging.info('Building %s.', str(targets))
+  autoninja = 'autoninja'
+  if coverage_utils.GetHostPlatform() == 'win':
+    autoninja += '.bat'
 
-  subprocess_cmd = ['autoninja', '-C', BUILD_DIR]
+  subprocess_cmd = [autoninja, '-C', BUILD_DIR]
   if jobs_count is not None:
     subprocess_cmd.append('-j' + str(jobs_count))
 
@@ -690,8 +697,8 @@
     current_platform = coverage_utils.GetHostPlatform()
 
   assert current_platform in [
-      'linux', 'mac', 'chromeos', 'ios'
-  ], ('Coverage is only supported on linux, mac, chromeos and ios.')
+      'linux', 'mac', 'chromeos', 'ios', 'win'
+  ], ('Coverage is only supported on linux, mac, chromeos, ios and win.')
 
 
 def _GetBuildArgs():
@@ -944,7 +951,7 @@
   # Setup coverage binaries even when script is called with empty params. This
   # is used by coverage bot for initial setup.
   if len(sys.argv) == 1:
-    update.UpdatePackage('coverage_tools')
+    update.UpdatePackage('coverage_tools', coverage_utils.GetHostPlatform())
     print(__doc__)
     return
 
@@ -1019,8 +1026,9 @@
         'otool')
     if os.path.exists(hermetic_otool_path):
       otool_path = hermetic_otool_path
-  binary_paths.extend(
-      coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR, otool_path))
+  if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
+    binary_paths.extend(
+        coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR, otool_path))
 
   assert args.format == 'html' or args.format == 'text', (
       '%s is not a valid output format for "llvm-cov show". Only "text" and '