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
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-11-18 17:04:33 +00:00
|
|
|
import tempfile
|
2020-09-14 14:21:44 +00:00
|
|
|
|
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]
|
|
|
|
inputs = sys.argv[4:]
|
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
|
|
|
|
|
|
|
# Convert the list of command-line inputs into a worklist file sfor skslc.
|
2020-09-14 14:21:44 +00:00
|
|
|
for input in 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)
|
|
|
|
targetDir = os.path.join(head, "golden")
|
|
|
|
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")
|
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")
|
2020-09-14 20:46:40 +00:00
|
|
|
else:
|
2020-12-22 16:28:59 +00:00
|
|
|
sys.exit("### Expected one of: --fp --glsl --metal --spirv --skvm, got " + lang)
|
2020-11-11 22:29:28 +00:00
|
|
|
|
2020-11-18 17:04:33 +00:00
|
|
|
# Invoke skslc, passing in the worklist.
|
|
|
|
worklist.close()
|
2020-11-11 22:29:28 +00:00
|
|
|
try:
|
2020-11-18 17:04:33 +00:00
|
|
|
output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT)
|
2020-11-11 22:29:28 +00:00
|
|
|
except subprocess.CalledProcessError as err:
|
2020-11-19 23:54:33 +00:00
|
|
|
if err.returncode != 1:
|
|
|
|
print("### 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
|
2020-11-11 22:29:28 +00:00
|
|
|
|
2020-11-18 18:58:19 +00:00
|
|
|
os.remove(worklist.name)
|
|
|
|
|
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.
|
|
|
|
if lang == "--fp":
|
|
|
|
for target in targets:
|
|
|
|
cppFile = open(target + '.cpp', 'r')
|
|
|
|
hFile = open(target + '.h', 'r')
|
|
|
|
if cppFile.readline().startswith("### Compilation failed"):
|
|
|
|
# The CPP had a compilation failure. Clear the header file.
|
|
|
|
hFile.close()
|
|
|
|
makeEmptyFile(target + '.h')
|
|
|
|
elif hFile.readline().startswith("### Compilation failed"):
|
|
|
|
# The header had a compilation failure. Clear the CPP file.
|
|
|
|
cppFile.close()
|
|
|
|
makeEmptyFile(target + '.cpp')
|