1#!/usr/bin/env python 2# 3# Copyright 2020 Google LLC 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8import os 9import shlex 10import subprocess 11import sys 12import tempfile 13 14batchCompile = True 15 16skslc = sys.argv[1] 17lang = sys.argv[2] 18settings = sys.argv[3] 19with open(sys.argv[4], 'r') as reader: 20 inputs = shlex.split(reader.read()) 21 22def pairwise(iterable): 23 # Iterate over an array pairwise (two elements at a time). 24 a = iter(iterable) 25 return zip(a, a) 26 27def executeWorklist(input, worklist): 28 # Invoke skslc, passing in the worklist. 29 worklist.close() 30 try: 31 output = subprocess.check_output([skslc, worklist.name], stderr=subprocess.STDOUT) 32 except subprocess.CalledProcessError as err: 33 if err.returncode != 1: 34 print("### " + input + " skslc error:\n") 35 print("\n".join(err.output.splitlines())) 36 sys.exit(err.returncode) 37 pass # Compile errors (exit code 1) are expected and normal in test code 38 39 # Delete the worklist file now that execution is complete. 40 os.remove(worklist.name) 41 42def makeEmptyFile(path): 43 try: 44 open(path, 'wb').close() 45 except OSError: 46 pass 47 48def extensionForSpirvAsm(ext): 49 return ext if (ext == '.frag' or ext == '.vert') else '.frag' 50 51if settings != "--settings" and settings != "--nosettings": 52 sys.exit("### Expected --settings or --nosettings, got " + settings) 53 54targets = [] 55worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False, mode='w') 56 57# The `inputs` array pairs off input files with their matching output directory, e.g.: 58# //skia/tests/sksl/shared/test.sksl 59# //skia/tests/sksl/shared/golden/ 60# //skia/tests/sksl/intrinsics/abs.sksl 61# //skia/tests/sksl/intrinsics/golden/ 62# ... (etc) ... 63# Here we loop over these inputs and convert them into a worklist file for skslc. 64for input, targetDir in pairwise(inputs): 65 noExt, ext = os.path.splitext(input) 66 head, tail = os.path.split(noExt) 67 if not os.path.isdir(targetDir): 68 os.mkdir(targetDir) 69 70 target = os.path.join(targetDir, tail) 71 if settings == "--nosettings": 72 target += "StandaloneSettings" 73 74 targets.append(target) 75 76 if lang == "--glsl": 77 worklist.write(input + "\n") 78 worklist.write(target + ".glsl\n") 79 worklist.write(settings + "\n\n") 80 elif lang == "--metal": 81 worklist.write(input + "\n") 82 worklist.write(target + ".metal\n") 83 worklist.write(settings + "\n\n") 84 elif lang == "--spirv": 85 worklist.write(input + "\n") 86 worklist.write(target + ".asm" + extensionForSpirvAsm(ext) + "\n") 87 worklist.write(settings + "\n\n") 88 elif lang == "--skvm": 89 worklist.write(input + "\n") 90 worklist.write(target + ".skvm\n") 91 worklist.write(settings + "\n\n") 92 elif lang == "--stage": 93 worklist.write(input + "\n") 94 worklist.write(target + ".stage\n") 95 worklist.write(settings + "\n\n") 96 else: 97 sys.exit("### Expected one of: --glsl --metal --spirv --skvm --stage --dsl, got " + lang) 98 99 # Compile items one at a time. 100 if not batchCompile: 101 executeWorklist(input, worklist) 102 worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False, mode='w') 103 104# Compile everything all in one go. 105if batchCompile: 106 executeWorklist("", worklist) 107else: 108 worklist.close() 109 os.remove(worklist.name) 110