Remove midl.py dependency on output location

midl.py currently does some path munging that is better handled by midl.gni.
It has knowledge of 'third_party' and 'win_build_output' and these should be
an argument to the script provided by the build system instead of knowledge
intrinsic to midl.py.

This changes moves that logic to midl.gni. midl.gni produces the same default
path that midl.py previously generated (so net result is a no-op).
browser_switcher/bho is the only consumer that had custom logic that needed
to explicitly specify the output location. Additionally, this enables
other IDL producers to specify a non-standard place to persist the IDLs if
they so desire.

Details:
midl.py/gni facilitate IDL compilation. Nominally, one would run midl as part
of the build process and be done with it. However, to support cross-platform
compilation, IDL generation is done on Windows clients and persisted in the
source tree. This way platforms that can't run midl directly can still
produce a Windows build.

For a given IDL, in the source tree |somewhere|, the standard location for
the checked in midl outputs is third_party\win_build_output\midl\|somewhere|.
midl.py knew how to get from the IDL built outputs (in |gen|) to the standard
location. Now midl.gni has that knowledge, additionally some other location,
other than the standard location may be used, if necessary.

Bug: 976936
Change-Id: Ibd448c8d59cc59e19c26beb8235c6f581182061e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1666483
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Julian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Commit-Queue: Scott Sheehan <ssheehan@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#672109}
diff --git a/build/toolchain/win/midl.gni b/build/toolchain/win/midl.gni
index 1fccf15f..41c97c81 100644
--- a/build/toolchain/win/midl.gni
+++ b/build/toolchain/win/midl.gni
@@ -21,6 +21,10 @@
 #   out_dir (optional)
 #       Directory to write the generated files to. Defaults to target_gen_dir.
 #
+#   generated_dir (optional)
+#       Directory where generated files were previously persisted.
+#       Defaults to third_party\win_build_output\midl\|out_dir|.
+#
 #   dynamic_guid (optional)
 #       If the GUID is not constant across builds, the current GUID.
 #
@@ -42,6 +46,14 @@
     out_dir = target_gen_dir
   }
 
+  if (defined(invoker.generated_dir)) {
+    generated_dir = rebase_path(invoker.generated_dir)
+  } else {
+    # midl.py expects 'gen' to be replaced with 'midl'.
+    generated_dir = rebase_path("//third_party/win_build_output") + "/midl/" +
+                    rebase_path(rebase_path(out_dir, root_build_dir), "gen")
+  }
+
   if (defined(invoker.dynamic_guid)) {
     dynamic_guid = invoker.dynamic_guid
   } else {
@@ -99,6 +111,7 @@
 
     args = [
       win_tool_arch,
+      generated_dir,
       rebase_path(out_dir, root_build_dir),
       dynamic_guid,
       type_library_file,
diff --git a/build/toolchain/win/midl.py b/build/toolchain/win/midl.py
index badd287..ab04546 100644
--- a/build/toolchain/win/midl.py
+++ b/build/toolchain/win/midl.py
@@ -153,12 +153,10 @@
   overwrite_cls_guid_tlb(tlb_file, dynamic_guid)
 
 
-def main(arch, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, idl, *flags):
+def main(arch, gendir, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, idl,
+         *flags):
   # Copy checked-in outputs to final location.
-  THIS_DIR = os.path.abspath(os.path.dirname(__file__))
-  source = os.path.join(THIS_DIR, '..', '..', '..',
-      'third_party', 'win_build_output',
-      re.sub(r'(^[^/]+/)?gen/', 'midl/', outdir))
+  source = gendir
   if os.path.isdir(os.path.join(source, os.path.basename(idl))):
     source = os.path.join(source, os.path.basename(idl))
   source = os.path.join(source, arch.split('.')[1])  # Append 'x86' or 'x64'.
diff --git a/chrome/browser/browser_switcher/bho/BUILD.gn b/chrome/browser/browser_switcher/bho/BUILD.gn
index b3ee523a..f81f61e 100644
--- a/chrome/browser/browser_switcher/bho/BUILD.gn
+++ b/chrome/browser/browser_switcher/bho/BUILD.gn
@@ -103,4 +103,8 @@
   sources = [
     "ie_bho_idl.idl",
   ]
+
+  # We have a custom output directory (that excludes the toolchain details).
+  generated_dir =
+      "//third_party/win_build_output/midl/chrome/browser/browser_switcher/bho"
 }