Update CLI header diff generator to allow a gen dir.

Update the CLI script for header diff generation in order to allow
providing an output folder. This allows us to run the gen and compare
the values when the old script would have removed the temp folder.

Change-Id: Ic263bd5d29740a0a0403941b37019ce04972f06f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/298175
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/third_party/webgpu-headers/cli b/third_party/webgpu-headers/cli
index a7b7c28..27f436f 100755
--- a/third_party/webgpu-headers/cli
+++ b/third_party/webgpu-headers/cli
@@ -12,6 +12,15 @@
 import subprocess
 import sys
 import tempfile
+from contextlib import contextmanager
+
+@contextmanager
+def get_folder(path=None):
+    if path:
+        yield path
+    else:
+        with tempfile.TemporaryDirectory() as temp_file:
+            yield temp_file
 
 # Third party dependencies necessary for Dawn to generate its version of the header.
 THIRD_PARTY_DIR = os.path.join('third_party')
@@ -138,18 +147,19 @@
 
 def main(args):
     parser = argparse.ArgumentParser()
+    parser.add_argument('--outdir', default=None)
     parser.add_argument('action', choices=('gen', 'check'))
     options = parser.parse_args()
 
     if options.action == 'gen':
-        with tempfile.TemporaryDirectory() as temp_dir:
+        with get_folder(options.outdir) as temp_dir:
             _gen_header_diff(temp_dir, THIRD_PARTY_DIR)
         return 0
 
     if options.action == 'check':
         if not _check_deps():
             return 0
-        with tempfile.TemporaryDirectory() as temp_dir:
+        with get_folder(options.outdir) as temp_dir:
             _gen_header_diff(temp_dir, temp_dir)
 
             with open(os.path.join(temp_dir, GENERATED_DIFF), 'r') as temp_file, \