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:
|
2021-11-30 18:59:12 +00:00
|
|
|
output = subprocess.check_output([
|
|
|
|
skslc, worklist.name], stderr=subprocess.STDOUT).decode('utf-8')
|
2021-01-12 19:05:05 +00:00
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
if err.returncode != 1:
|
|
|
|
print("### " + input + " skslc error:\n")
|
2021-11-30 18:59:12 +00:00
|
|
|
print("\n".join(err.output.decode('utf-8').splitlines()))
|
2021-01-12 19:05:05 +00:00
|
|
|
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):
|
2021-08-27 15:21:12 +00:00
|
|
|
return ext if (ext == '.frag' or ext == '.vert') 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 = []
|
2021-07-09 19:39:25 +00:00
|
|
|
worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False, mode='w')
|
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)
|
|
|
|
|
2021-07-01 17:54:20 +00:00
|
|
|
if 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:
|
2022-01-25 04:56:00 +00:00
|
|
|
sys.exit("### Expected one of: --glsl --metal --spirv --skvm --stage --dsl, 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)
|
2021-07-09 19:39:25 +00:00
|
|
|
worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False, mode='w')
|
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)
|