Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2017 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | import os |
| 9 | import subprocess |
| 10 | import sys |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 11 | import tempfile |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 12 | |
| 13 | skslc = sys.argv[1] |
Ethan Nicholas | b9f6afb | 2017-07-27 16:02:37 -0400 | [diff] [blame] | 14 | clangFormat = sys.argv[2] |
John Stiles | 796e702 | 2020-06-11 19:57:22 -0400 | [diff] [blame] | 15 | fetchClangFormat = sys.argv[3] |
| 16 | processors = sys.argv[4:] |
| 17 | |
| 18 | exeSuffix = '.exe' if sys.platform.startswith('win') else ''; |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 19 | targets = [] |
John Stiles | 57adba0 | 2020-11-18 13:58:19 -0500 | [diff] [blame] | 20 | worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False) |
John Stiles | 796e702 | 2020-06-11 19:57:22 -0400 | [diff] [blame] | 21 | |
John Stiles | ba06e1a | 2020-11-12 11:04:38 -0500 | [diff] [blame] | 22 | # Fetch clang-format if it's not present already. |
| 23 | if not os.path.isfile(clangFormat + exeSuffix): |
| 24 | subprocess.check_call([sys.executable, fetchClangFormat]); |
| 25 | |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 26 | # Build a worklist of all the fragment processors that we want to compile. |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 27 | for p in processors: |
John Stiles | ba06e1a | 2020-11-12 11:04:38 -0500 | [diff] [blame] | 28 | noExt, _ = os.path.splitext(p) |
| 29 | head, tail = os.path.split(noExt) |
| 30 | targetDir = os.path.join(head, "generated") |
| 31 | if not os.path.isdir(targetDir): |
| 32 | os.mkdir(targetDir) |
| 33 | target = os.path.join(targetDir, tail) |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 34 | targets.append(target + ".h") |
| 35 | targets.append(target + ".cpp") |
John Stiles | 796e702 | 2020-06-11 19:57:22 -0400 | [diff] [blame] | 36 | |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 37 | worklist.write(p + "\n") |
| 38 | worklist.write(target + ".h\n\n") |
| 39 | worklist.write(p + "\n") |
| 40 | worklist.write(target + ".cpp\n\n") |
| 41 | |
| 42 | # Invoke skslc, passing in the worklist. |
| 43 | worklist.close() |
John Stiles | ba06e1a | 2020-11-12 11:04:38 -0500 | [diff] [blame] | 44 | try: |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 45 | output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT) |
John Stiles | ba06e1a | 2020-11-12 11:04:38 -0500 | [diff] [blame] | 46 | except subprocess.CalledProcessError as err: |
| 47 | print("### skslc error:\n") |
| 48 | print("\n".join(err.output.splitlines())) |
| 49 | |
John Stiles | 57adba0 | 2020-11-18 13:58:19 -0500 | [diff] [blame] | 50 | os.remove(worklist.name) |
| 51 | |
John Stiles | ba06e1a | 2020-11-12 11:04:38 -0500 | [diff] [blame] | 52 | # Invoke clang-format on every generated target. |
| 53 | try: |
Brian Osman | 7b23905 | 2020-11-18 17:04:33 +0000 | [diff] [blame] | 54 | output = subprocess.check_output([clangFormat, "--sort-includes=false", "-i"] + targets, |
| 55 | stderr=subprocess.STDOUT) |
John Stiles | ba06e1a | 2020-11-12 11:04:38 -0500 | [diff] [blame] | 56 | except subprocess.CalledProcessError as err: |
| 57 | print("### clang-format error:\n") |
| 58 | print("\n".join(err.output.splitlines())) |