2017-06-29 14:03:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2017 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-11-18 17:04:33 +00:00
|
|
|
import tempfile
|
2017-06-29 14:03:38 +00:00
|
|
|
|
|
|
|
skslc = sys.argv[1]
|
2017-07-27 20:02:37 +00:00
|
|
|
clangFormat = sys.argv[2]
|
2020-06-11 23:57:22 +00:00
|
|
|
fetchClangFormat = sys.argv[3]
|
|
|
|
processors = sys.argv[4:]
|
|
|
|
|
|
|
|
exeSuffix = '.exe' if sys.platform.startswith('win') else '';
|
2020-11-18 17:04:33 +00:00
|
|
|
targets = []
|
2020-11-18 18:58:19 +00:00
|
|
|
worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False)
|
2020-06-11 23:57:22 +00:00
|
|
|
|
2020-11-12 16:04:38 +00:00
|
|
|
# Fetch clang-format if it's not present already.
|
|
|
|
if not os.path.isfile(clangFormat + exeSuffix):
|
|
|
|
subprocess.check_call([sys.executable, fetchClangFormat]);
|
|
|
|
|
2020-11-18 17:04:33 +00:00
|
|
|
# Build a worklist of all the fragment processors that we want to compile.
|
2017-06-29 14:03:38 +00:00
|
|
|
for p in processors:
|
2020-11-12 16:04:38 +00:00
|
|
|
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)
|
2020-11-18 17:04:33 +00:00
|
|
|
targets.append(target + ".h")
|
|
|
|
targets.append(target + ".cpp")
|
|
|
|
|
|
|
|
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()
|
2020-11-12 16:04:38 +00:00
|
|
|
try:
|
2020-11-18 17:04:33 +00:00
|
|
|
output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT)
|
2020-11-12 16:04:38 +00:00
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
print("### skslc error:\n")
|
|
|
|
print("\n".join(err.output.splitlines()))
|
|
|
|
|
2020-11-18 18:58:19 +00:00
|
|
|
os.remove(worklist.name)
|
|
|
|
|
2020-11-12 16:04:38 +00:00
|
|
|
# Invoke clang-format on every generated target.
|
|
|
|
try:
|
2020-11-18 17:04:33 +00:00
|
|
|
output = subprocess.check_output([clangFormat, "--sort-includes=false", "-i"] + targets,
|
|
|
|
stderr=subprocess.STDOUT)
|
2020-11-12 16:04:38 +00:00
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
print("### clang-format error:\n")
|
|
|
|
print("\n".join(err.output.splitlines()))
|