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 |
| 11 | |
| 12 | skslc = sys.argv[1] |
Ethan Nicholas | b9f6afb | 2017-07-27 16:02:37 -0400 | [diff] [blame] | 13 | clangFormat = sys.argv[2] |
John Stiles | 796e702 | 2020-06-11 19:57:22 -0400 | [diff] [blame] | 14 | fetchClangFormat = sys.argv[3] |
| 15 | processors = sys.argv[4:] |
| 16 | |
| 17 | exeSuffix = '.exe' if sys.platform.startswith('win') else ''; |
| 18 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 19 | for p in processors: |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 20 | print("Recompiling " + p + "...") |
| 21 | try: |
John Stiles | 796e702 | 2020-06-11 19:57:22 -0400 | [diff] [blame] | 22 | if not os.path.isfile(clangFormat + exeSuffix): |
| 23 | subprocess.check_call([sys.executable, fetchClangFormat]); |
| 24 | |
Ethan Nicholas | 21a9b56 | 2019-04-10 12:06:19 -0400 | [diff] [blame] | 25 | noExt, _ = os.path.splitext(p) |
| 26 | head, tail = os.path.split(noExt) |
| 27 | targetDir = os.path.join(head, "generated") |
John Stiles | 796e702 | 2020-06-11 19:57:22 -0400 | [diff] [blame] | 28 | if not os.path.isdir(targetDir): |
Ethan Nicholas | 21a9b56 | 2019-04-10 12:06:19 -0400 | [diff] [blame] | 29 | os.mkdir(targetDir) |
| 30 | target = os.path.join(targetDir, tail) |
| 31 | subprocess.check_output([skslc, p, target + ".h"]) |
Ethan Nicholas | b9f6afb | 2017-07-27 16:02:37 -0400 | [diff] [blame] | 32 | subprocess.check_call(clangFormat + " --sort-includes=false -i \"" + |
Ethan Nicholas | 21a9b56 | 2019-04-10 12:06:19 -0400 | [diff] [blame] | 33 | target + ".h\"", shell=True) |
| 34 | subprocess.check_output([skslc, p, target + ".cpp"]) |
Ethan Nicholas | b9f6afb | 2017-07-27 16:02:37 -0400 | [diff] [blame] | 35 | subprocess.check_call(clangFormat + " --sort-includes=false -i \"" + |
Ethan Nicholas | 21a9b56 | 2019-04-10 12:06:19 -0400 | [diff] [blame] | 36 | target + ".cpp\"", shell=True) |
Ethan Nicholas | 9fb036f | 2017-07-05 16:19:09 -0400 | [diff] [blame] | 37 | except subprocess.CalledProcessError as err: |
| 38 | print("### Error compiling " + p + ":") |
| 39 | print(err.output) |
| 40 | exit(1) |