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-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
|
|
|
|
|
|
|
|
def compile(skslc, input, target, extension):
|
|
|
|
target += extension
|
|
|
|
try:
|
2020-09-16 21:46:37 +00:00
|
|
|
subprocess.check_output([skslc, input, target, settings], stderr=subprocess.STDOUT)
|
2020-09-14 20:46:40 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
except subprocess.CalledProcessError as err:
|
|
|
|
with open(target, 'wb') as dst:
|
|
|
|
dst.write("### Compilation failed:\n\n")
|
2020-09-15 14:54:58 +00:00
|
|
|
dst.write("\n".join(err.output.splitlines()))
|
|
|
|
dst.write("\n")
|
2020-09-14 20:46:40 +00:00
|
|
|
return False
|
|
|
|
|
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
|
|
|
|
|
|
|
for input in inputs:
|
2020-09-14 20:46:40 +00:00
|
|
|
noExt, ext = os.path.splitext(input)
|
|
|
|
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-09-24 20:42:09 +00:00
|
|
|
if lang == "--fp":
|
2020-09-14 20:46:40 +00:00
|
|
|
# First, compile the CPP. If we get an error, stop here.
|
|
|
|
if compile(skslc, input, target, ".cpp"):
|
|
|
|
# Next, compile the header.
|
|
|
|
if compile(skslc, input, target, ".h"):
|
|
|
|
# Both files built successfully.
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
# The header generated an error; this counts as an overall failure for this test.
|
2020-09-15 15:16:10 +00:00
|
|
|
# Blank out the passing CPP output since it's not relevant in a failure case.
|
|
|
|
makeEmptyFile(target + ".cpp")
|
2020-09-14 14:21:44 +00:00
|
|
|
else:
|
2020-09-15 15:16:10 +00:00
|
|
|
# The CPP generated an error. We didn't actually generate a header at all, but Ninja
|
|
|
|
# expects an output file to exist or it won't reach steady-state.
|
|
|
|
makeEmptyFile(target + ".h")
|
2020-09-24 20:42:09 +00:00
|
|
|
elif lang == "--glsl":
|
2020-09-14 20:46:40 +00:00
|
|
|
compile(skslc, input, target, ".glsl")
|
2020-09-25 17:35:58 +00:00
|
|
|
elif lang == "--metal":
|
|
|
|
compile(skslc, input, target, ".metal")
|
2020-09-14 20:46:40 +00:00
|
|
|
else:
|
2020-09-25 17:35:58 +00:00
|
|
|
sys.exit("### Expected one of: --fp --glsl --metal, got " + lang)
|