2020-09-14 14:21:44 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2020 Google LLC
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import os
|
2021-01-27 19:05:15 +00:00
|
|
|
import shlex
|
2020-09-14 14:21:44 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-11-18 17:04:33 +00:00
|
|
|
import tempfile
|
2020-09-14 14:21:44 +00:00
|
|
|
|
2021-01-27 19:05:15 +00:00
|
|
|
batchCompile = True
|
|
|
|
|
2020-09-16 21:46:37 +00:00
|
|
|
skslc = sys.argv[1]
|
2020-09-24 20:42:09 +00:00
|
|
|
lang = sys.argv[2]
|
|
|
|
settings = sys.argv[3]
|
2021-01-27 19:05:15 +00:00
|
|
|
with open(sys.argv[4], 'r') as reader:
|
|
|
|
inputs = shlex.split(reader.read())
|
2021-01-12 19:05:05 +00:00
|
|
|
|
2021-01-22 16:54:30 +00:00
|
|
|
def pairwise(iterable):
|
|
|
|
# Iterate over an array pairwise (two elements at a time).
|
|
|
|
a = iter(iterable)
|
|
|
|
return zip(a, a)
|
|
|
|
|
2021-01-12 19:05:05 +00:00
|
|
|
def executeWorklist(input, worklist):
|
|
|
|
# Invoke skslc, passing in the worklist.
|
|
|
|
worklist.close()
|
|
|
|
try:
|
|
|
|
output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT)
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
if err.returncode != 1:
|
|
|
|
print("### " + input + " skslc error:\n")
|
|
|
|
print("\n".join(err.output.splitlines()))
|
|
|
|
sys.exit(err.returncode)
|
|
|
|
pass # Compile errors (exit code 1) are expected and normal in test code
|
|
|
|
|
|
|
|
# Delete the worklist file now that execution is complete.
|
|
|
|
os.remove(worklist.name)
|
2020-09-16 21:46:37 +00:00
|
|
|
|
2020-09-15 15:16:10 +00:00
|
|
|
def makeEmptyFile(path):
|
2020-09-14 20:46:40 +00:00
|
|
|
try:
|
2020-09-15 15:16:10 +00:00
|
|
|
open(path, 'wb').close()
|
2020-09-14 20:46:40 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2020-11-20 21:28:50 +00:00
|
|
|
def extensionForSpirvAsm(ext):
|
2020-11-23 20:14:35 +00:00
|
|
|
return ext if (ext == '.frag' or ext == '.vert' or ext == '.geom') else '.frag'
|
2020-11-20 21:28:50 +00:00
|
|
|
|
2020-09-16 21:46:37 +00:00
|
|
|
if settings != "--settings" and settings != "--nosettings":
|
2020-09-24 20:42:09 +00:00
|
|
|
sys.exit("### Expected --settings or --nosettings, got " + settings)
|
2020-09-14 14:21:44 +00:00
|
|
|
|
2020-11-11 22:29:28 +00:00
|
|
|
targets = []
|
2020-11-18 18:58:19 +00:00
|
|
|
worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False)
|
2020-11-11 22:29:28 +00:00
|
|
|
|
2021-01-22 16:54:30 +00:00
|
|
|
# The `inputs` array pairs off input files with their matching output directory, e.g.:
|
|
|
|
# //skia/tests/sksl/shared/test.sksl
|
|
|
|
# //skia/tests/sksl/shared/golden/
|
|
|
|
# //skia/tests/sksl/intrinsics/abs.sksl
|
|
|
|
# //skia/tests/sksl/intrinsics/golden/
|
|
|
|
# ... (etc) ...
|
|
|
|
# Here we loop over these inputs and convert them into a worklist file for skslc.
|
|
|
|
for input, targetDir in pairwise(inputs):
|
2020-11-20 21:28:50 +00:00
|
|
|
noExt, ext = os.path.splitext(input)
|
2020-09-14 20:46:40 +00:00
|
|
|
head, tail = os.path.split(noExt)
|
|
|
|
if not os.path.isdir(targetDir):
|
|
|
|
os.mkdir(targetDir)
|
2020-09-16 21:46:37 +00:00
|
|
|
|
2020-09-14 20:46:40 +00:00
|
|
|
target = os.path.join(targetDir, tail)
|
2020-09-16 21:46:37 +00:00
|
|
|
if settings == "--nosettings":
|
2020-09-21 21:09:52 +00:00
|
|
|
target += "StandaloneSettings"
|
2020-09-16 21:46:37 +00:00
|
|
|
|
2020-11-11 22:29:28 +00:00
|
|
|
targets.append(target)
|
|
|
|
|
2020-09-24 20:42:09 +00:00
|
|
|
if lang == "--fp":
|
2020-11-18 17:04:33 +00:00
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".cpp\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".h\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
2021-04-13 21:13:03 +00:00
|
|
|
elif lang == "--dslfp":
|
|
|
|
worklist.write(input + "\n")
|
2021-04-14 13:35:24 +00:00
|
|
|
worklist.write(target + ".dsl.cpp\n")
|
2021-04-13 21:13:03 +00:00
|
|
|
worklist.write(settings + "\n\n")
|
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".h\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
2020-09-24 20:42:09 +00:00
|
|
|
elif lang == "--glsl":
|
2020-11-18 17:04:33 +00:00
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".glsl\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
2020-09-25 17:35:58 +00:00
|
|
|
elif lang == "--metal":
|
2020-11-18 17:04:33 +00:00
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".metal\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
2020-11-20 21:28:50 +00:00
|
|
|
elif lang == "--spirv":
|
|
|
|
worklist.write(input + "\n")
|
2020-11-23 20:14:35 +00:00
|
|
|
worklist.write(target + ".asm" + extensionForSpirvAsm(ext) + "\n")
|
2020-11-20 21:28:50 +00:00
|
|
|
worklist.write(settings + "\n\n")
|
2020-12-22 16:28:59 +00:00
|
|
|
elif lang == "--skvm":
|
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".skvm\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
2021-02-08 18:49:53 +00:00
|
|
|
elif lang == "--stage":
|
|
|
|
worklist.write(input + "\n")
|
|
|
|
worklist.write(target + ".stage\n")
|
|
|
|
worklist.write(settings + "\n\n")
|
2020-09-14 20:46:40 +00:00
|
|
|
else:
|
2021-04-13 21:13:03 +00:00
|
|
|
sys.exit("### Expected one of: --fp --dslfp --glsl --metal --spirv --skvm --stage, got " +
|
|
|
|
lang)
|
2020-11-11 22:29:28 +00:00
|
|
|
|
2021-01-12 19:05:05 +00:00
|
|
|
# Compile items one at a time.
|
|
|
|
if not batchCompile:
|
|
|
|
executeWorklist(input, worklist)
|
|
|
|
worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False)
|
2020-11-11 22:29:28 +00:00
|
|
|
|
2021-01-12 19:05:05 +00:00
|
|
|
# Compile everything all in one go.
|
|
|
|
if batchCompile:
|
|
|
|
executeWorklist("", worklist)
|
|
|
|
else:
|
|
|
|
worklist.close()
|
|
|
|
os.remove(worklist.name)
|
2020-11-18 18:58:19 +00:00
|
|
|
|
2020-11-11 22:29:28 +00:00
|
|
|
# A special case cleanup pass, just for CPP and H files: if either one of these files starts with
|
|
|
|
# `### Compilation failed`, its sibling should be replaced by an empty file. This improves clarity
|
|
|
|
# during code review; a failure on either file means that success on the sibling is irrelevant.
|
2021-04-13 21:13:03 +00:00
|
|
|
if lang == "--fp" or lang == "--dslfp":
|
2021-04-14 13:35:24 +00:00
|
|
|
cppExtension = (".dsl.cpp" if lang == "--dslfp" else ".cpp")
|
2021-04-13 21:13:03 +00:00
|
|
|
hExtension = ".h"
|
|
|
|
|
2020-11-11 22:29:28 +00:00
|
|
|
for target in targets:
|
2021-04-13 21:13:03 +00:00
|
|
|
cppFile = open(target + cppExtension, 'r')
|
|
|
|
hFile = open(target + hExtension, 'r')
|
2020-11-11 22:29:28 +00:00
|
|
|
if cppFile.readline().startswith("### Compilation failed"):
|
|
|
|
# The CPP had a compilation failure. Clear the header file.
|
|
|
|
hFile.close()
|
2021-04-13 21:13:03 +00:00
|
|
|
makeEmptyFile(target + hExtension)
|
2020-11-11 22:29:28 +00:00
|
|
|
elif hFile.readline().startswith("### Compilation failed"):
|
|
|
|
# The header had a compilation failure. Clear the CPP file.
|
|
|
|
cppFile.close()
|
2021-04-13 21:13:03 +00:00
|
|
|
makeEmptyFile(target + cppExtension)
|