Get midl.exe to use clang-cl instead of cl

When midl.py is finished its work it invokes midl.exe to ensure that the
results are the same. midl.exe defaults to invoking cl.exe, and we want
to consistently use clang-cl.exe.

This change uses /cpp_cmd to specify the clang-cl compiler. It then uses
/cpp_opt to specify -Wno-nonportable-include-path because some of the
SDK .idl files include files using different case from the file on disk.
Typical warnings look like this:

  include\10.0.19041.0\um\unknwn.idl(28,10): warning:
  non-portable path to file '"Unknwnbase.Idl"'; specified path differs
  in case from file name on disk [-Wnonportable-include-path]
  #include "unknwnbase.idl"
           ^~~~~~~~~~~~~~~~
           "Unknwnbase.Idl"

When you use /cpp_opt then you are also responsible for specifying -E
and -nologo and for passing along all of the /D commands, so this change
does that as well.

Bug: 1097510
Change-Id: Iece8ae7395d9afb05652d0a40f333721b3207a9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261267
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781638}
GitOrigin-RevId: 7407ad20ed2ffc6f9ef71ab4da6bc1f709804899
diff --git a/win/midl.gni b/win/midl.gni
index ee7dc47..72e79eb 100644
--- a/win/midl.gni
+++ b/win/midl.gni
@@ -123,6 +123,8 @@
       dlldata_file,
       interface_identifier_file,
       proxy_file,
+      rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang-cl.exe",
+                  root_build_dir),
       "{{source}}",
       "/char",
       "signed",
diff --git a/win/midl.py b/win/midl.py
index 827121a..5483173 100644
--- a/win/midl.py
+++ b/win/midl.py
@@ -173,8 +173,8 @@
   overwrite_cls_guid_tlb(tlb_file, dynamic_guid)
 
 
-def main(arch, gendir, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, idl,
-         *flags):
+def main(arch, gendir, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, clang,
+         idl, *flags):
   # Copy checked-in outputs to final location.
   source = gendir
   if os.path.isdir(os.path.join(source, os.path.basename(idl))):
@@ -192,16 +192,6 @@
   if sys.platform != 'win32':
     return 0
 
-  # Skip the verification step on Windows 7 to avoid issues running the
-  # compiler.
-  ver = sys.getwindowsversion()
-  # Impossible version number, but just in case...
-  if ver.major < 6:
-    return 0
-  # Check for before Windows 8.
-  if ver.major == 6 and ver.minor < 2:
-    return 0;
-
   # On Windows, run midl.exe on the input and check that its outputs are
   # identical to the checked-in outputs (after possibly replacing their main
   # class guid).
@@ -214,6 +204,10 @@
   env_pairs = open(arch).read()[:-2].split('\0')
   env_dict = dict([item.split('=', 1) for item in env_pairs])
 
+  # Extract the /D options and send them to the preprocessor.
+  preprocessor_options = '-E -nologo -Wno-nonportable-include-path'
+  preprocessor_options += ''.join(
+      [' ' + flag for flag in flags if flag.startswith('/D')])
   args = ['midl', '/nologo'] + list(flags) + [
       '/out', tmp_dir,
       '/tlb', tlb,
@@ -221,6 +215,8 @@
       '/dlldata', dlldata,
       '/iid', iid,
       '/proxy', proxy,
+      '/cpp_cmd', clang,
+      '/cpp_opt', preprocessor_options,
       idl]
   try:
     popen = subprocess.Popen(args, shell=True, env=env_dict,