Fix `git cl format` for metrics XML files on Windows

* Call `os.path.normpath()` prior to comparing file paths
* Run Python files with `vpython`
* Pass `shell=True` for Windows commands, so that the PATH variable is
  defined: https://stackoverflow.com/a/32799942
  * While here, clean up similar call sites to drop an unnecessary cast.

Fixed: 1081763
Change-Id: I8096b3ad14a4675036a579fab537af1d94f12725
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2203422
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Ilya Sherman <isherman@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 79ca988..01b5d57 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -4775,7 +4775,7 @@
         str(os.path.dirname(clang_format_tool)) + os.pathsep + env['PATH'])
     stdout = RunCommand(
         cmd, stdin=diff_output, cwd=top_dir, env=env,
-        shell=bool(sys.platform.startswith('win32')))
+        shell=sys.platform.startswith('win32'))
     if opts.diff:
       sys.stdout.write(stdout)
     if opts.dry_run and len(stdout) > 0:
@@ -4959,7 +4959,7 @@
       cmd.append('--dry-run')
     for gn_diff_file in gn_diff_files:
       gn_ret = subprocess2.call(cmd + [gn_diff_file],
-                                shell=bool(sys.platform.startswith('win')),
+                                shell=sys.platform.startswith('win'),
                                 cwd=top_dir)
       if opts.dry_run and gn_ret == 2:
         return_value = 2  # Not formatted.
@@ -4980,10 +4980,15 @@
   if not opts.presubmit:
     for xml_dir in GetDirtyMetricsDirs(diff_files):
       tool_dir = os.path.join(top_dir, xml_dir)
-      cmd = [os.path.join(tool_dir, 'pretty_print.py'), '--non-interactive']
+      pretty_print_tool = os.path.join(tool_dir, 'pretty_print.py')
+      cmd = ['vpython', pretty_print_tool, '--non-interactive']
       if opts.dry_run or opts.diff:
         cmd.append('--diff')
-      stdout = RunCommand(cmd, cwd=top_dir)
+      # TODO(isherman): Once this file runs only on Python 3.3+, drop the
+      # `shell` param and instead replace `'vpython'` with
+      # `shutil.which('frob')` above: https://stackoverflow.com/a/32799942
+      stdout = RunCommand(cmd, cwd=top_dir,
+                          shell=sys.platform.startswith('win32'))
       if opts.diff:
         sys.stdout.write(stdout)
       if opts.dry_run and stdout:
@@ -5002,7 +5007,8 @@
     os.path.join('tools', 'metrics', 'ukm'),
   ]
   for xml_dir in metrics_xml_dirs:
-    if any(file.startswith(xml_dir) for file in xml_diff_files):
+    if any(
+        os.path.normpath(file).startswith(xml_dir) for file in xml_diff_files):
       yield xml_dir