Improve performance of skia_compile_processors.

Previously, we would instantiate skslc twice, and clang-format once, for
each fragment processor. We now batch all the work into a single
invocation of each tool--skslc is called once with a worklist file, and
clang-format is asked to clean all the generated files at once. This
will improve build times very substantially on Windows, and should
provide a small benefit on Mac/Linux as well.

Change-Id: I97ac1f22bf19298dfac1c02e1a28a106cfc8491d
Bug: skia:10919
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334420
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/gn/compile_processors.py b/gn/compile_processors.py
index 8c47cba..3e6cd45 100755
--- a/gn/compile_processors.py
+++ b/gn/compile_processors.py
@@ -8,6 +8,7 @@
 import os
 import subprocess
 import sys
+import tempfile
 
 skslc = sys.argv[1]
 clangFormat = sys.argv[2]
@@ -15,25 +16,41 @@
 processors = sys.argv[4:]
 
 exeSuffix = '.exe' if sys.platform.startswith('win') else '';
+targets = []
+worklist = tempfile.NamedTemporaryFile(suffix='.worklist')
 
+# Fetch clang-format if it's not present already.
+if not os.path.isfile(clangFormat + exeSuffix):
+    subprocess.check_call([sys.executable, fetchClangFormat]);
+
+# Build a worklist of all the fragment processors that we want to compile.
 for p in processors:
-    try:
-        if not os.path.isfile(clangFormat + exeSuffix):
-            subprocess.check_call([sys.executable, fetchClangFormat]);
+    noExt, _ = os.path.splitext(p)
+    head, tail = os.path.split(noExt)
+    targetDir = os.path.join(head, "generated")
+    if not os.path.isdir(targetDir):
+        os.mkdir(targetDir)
+    target = os.path.join(targetDir, tail)
+    targets.append(target + ".h")
+    targets.append(target + ".cpp")
 
-        noExt, _ = os.path.splitext(p)
-        head, tail = os.path.split(noExt)
-        targetDir = os.path.join(head, "generated")
-        if not os.path.isdir(targetDir):
-            os.mkdir(targetDir)
-        target = os.path.join(targetDir, tail)
-        subprocess.check_output([skslc, p, target + ".h"])
-        subprocess.check_call(clangFormat + " --sort-includes=false -i \"" +
-                              target + ".h\"", shell=True)
-        subprocess.check_output([skslc, p, target + ".cpp"])
-        subprocess.check_call(clangFormat + " --sort-includes=false -i \"" +
-                              target + ".cpp\"", shell=True)
-    except subprocess.CalledProcessError as err:
-        print("### Error compiling " + p + ":")
-        print(err.output)
-        exit(1)
+    worklist.write(p + "\n")
+    worklist.write(target + ".h\n\n")
+    worklist.write(p + "\n")
+    worklist.write(target + ".cpp\n\n")
+
+# Invoke skslc, passing in the worklist.
+worklist.close()
+try:
+    output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT)
+except subprocess.CalledProcessError as err:
+    print("### skslc error:\n")
+    print("\n".join(err.output.splitlines()))
+
+# Invoke clang-format on every generated target.
+try:
+    output = subprocess.check_output([clangFormat, "--sort-includes=false", "-i"] + targets,
+                                     stderr=subprocess.STDOUT)
+except subprocess.CalledProcessError as err:
+    print("### clang-format error:\n")
+    print("\n".join(err.output.splitlines()))