skia2/gn/compile_sksl_tests.py
John Stiles aeae3a58e3 Add golden outputs for the Metal backend.
This CL also updates the blend tests to use sk_FragColor instead of
returning a half4, as the Metal backend assumes that a fragment
processor's `main` will return void and always synthesizes a
`return *_out;` at the end.

(context link:
https://osscs.corp.google.com/android/platform/superproject/+/master:external/skqp/src/sksl/SkSLMetalCodeGenerator.cpp;l=803;drc=842d31b14159626054e01dd32826563a8f4214bf )

BYPASS_INCLUSIVE_LANGUAGE_REASON=see http://b/168134166

Change-Id: I330a456bf25ee72d3a29c59cd624625378ae80a0
Bug: skia:10649, skia:10757, skia:10758, skia:10759, skia:10760, skia:10761, skia:10762
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319409
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2020-09-25 17:46:43 +00:00

71 lines
2.3 KiB
Python
Executable File

#!/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
skslc = sys.argv[1]
lang = sys.argv[2]
settings = sys.argv[3]
inputs = sys.argv[4:]
def makeEmptyFile(path):
try:
open(path, 'wb').close()
except OSError:
pass
def compile(skslc, input, target, extension):
target += extension
try:
subprocess.check_output([skslc, input, target, settings], stderr=subprocess.STDOUT)
return True
except subprocess.CalledProcessError as err:
with open(target, 'wb') as dst:
dst.write("### Compilation failed:\n\n")
dst.write("\n".join(err.output.splitlines()))
dst.write("\n")
return False
if settings != "--settings" and settings != "--nosettings":
sys.exit("### Expected --settings or --nosettings, got " + settings)
for input in inputs:
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)
target = os.path.join(targetDir, tail)
if settings == "--nosettings":
target += "StandaloneSettings"
if lang == "--fp":
# 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.
# Blank out the passing CPP output since it's not relevant in a failure case.
makeEmptyFile(target + ".cpp")
else:
# 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")
elif lang == "--glsl":
compile(skslc, input, target, ".glsl")
elif lang == "--metal":
compile(skslc, input, target, ".metal")
else:
sys.exit("### Expected one of: --fp --glsl --metal, got " + lang)