blob: 8c47cbacab78ec83e637e03979ca80fd49b24371 [file] [log] [blame]
Ethan Nicholas762466e2017-06-29 10:03:38 -04001#!/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
8import os
9import subprocess
10import sys
11
12skslc = sys.argv[1]
Ethan Nicholasb9f6afb2017-07-27 16:02:37 -040013clangFormat = sys.argv[2]
John Stiles796e7022020-06-11 19:57:22 -040014fetchClangFormat = sys.argv[3]
15processors = sys.argv[4:]
16
17exeSuffix = '.exe' if sys.platform.startswith('win') else '';
18
Ethan Nicholas762466e2017-06-29 10:03:38 -040019for p in processors:
Ethan Nicholas9fb036f2017-07-05 16:19:09 -040020 try:
John Stiles796e7022020-06-11 19:57:22 -040021 if not os.path.isfile(clangFormat + exeSuffix):
22 subprocess.check_call([sys.executable, fetchClangFormat]);
23
Ethan Nicholas21a9b562019-04-10 12:06:19 -040024 noExt, _ = os.path.splitext(p)
25 head, tail = os.path.split(noExt)
26 targetDir = os.path.join(head, "generated")
John Stiles796e7022020-06-11 19:57:22 -040027 if not os.path.isdir(targetDir):
Ethan Nicholas21a9b562019-04-10 12:06:19 -040028 os.mkdir(targetDir)
29 target = os.path.join(targetDir, tail)
30 subprocess.check_output([skslc, p, target + ".h"])
Ethan Nicholasb9f6afb2017-07-27 16:02:37 -040031 subprocess.check_call(clangFormat + " --sort-includes=false -i \"" +
Ethan Nicholas21a9b562019-04-10 12:06:19 -040032 target + ".h\"", shell=True)
33 subprocess.check_output([skslc, p, target + ".cpp"])
Ethan Nicholasb9f6afb2017-07-27 16:02:37 -040034 subprocess.check_call(clangFormat + " --sort-includes=false -i \"" +
Ethan Nicholas21a9b562019-04-10 12:06:19 -040035 target + ".cpp\"", shell=True)
Ethan Nicholas9fb036f2017-07-05 16:19:09 -040036 except subprocess.CalledProcessError as err:
37 print("### Error compiling " + p + ":")
38 print(err.output)
39 exit(1)