Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
minify_sksl_tests.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# Copyright 2022 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
14batchMinify = False
15
16sksl_minify = sys.argv[1]
17shared_module = sys.argv[2]
18public_module = sys.argv[3]
19input_root_dir = sys.argv[4]
20output_root_dir = sys.argv[5]
21# The last arg is a file containing a space seperated list of filenames
22input_file = sys.argv[6]
23with open(input_file, 'r') as reader:
24 all_inputs = shlex.split(reader.read())
25
26inputs = []
27for file in all_inputs:
28 if (file.endswith(".rts") or file.endswith(".rtcf") or file.endswith(".rtb") or
29 file.endswith(".mfrag") or file.endswith(".mvert")):
30 inputs.append(file)
31
32def executeWorklist(input, worklist):
33 # Invoke sksl-minify, passing in the worklist.
34 worklist.close()
35 try:
36 output = subprocess.check_output([
37 sksl_minify, worklist.name], stderr=subprocess.STDOUT).decode('utf-8', errors='ignore')
38 except subprocess.CalledProcessError as err:
39 if err.returncode != 1:
40 print("### " + input + " sksl-minify error:\n")
41 print("\n".join(err.output.decode('utf-8', errors='ignore').splitlines()))
42 sys.exit(err.returncode)
43 pass # Compile errors (exit code 1) are expected and normal in test code
44
45 # Delete the worklist file now that execution is complete.
46 os.remove(worklist.name)
47
48worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False, mode='w')
49
50# Here we loop over the inputs and convert them into a worklist file for sksl-minify.
51for input in inputs:
52 # Derive the target path from the input filename and remove the extension so it can
53 # end with .minified.sksl
54 target = input.replace(input_root_dir, output_root_dir)
55 target = os.path.splitext(target)[0]
56 target_dir = os.path.dirname(target)
57 if not os.path.isdir(target_dir):
58 os.mkdir(target_dir)
59
60 noExt, ext = os.path.splitext(input)
61 head, tail = os.path.split(noExt)
62
63 if ext == '.rts':
64 worklist.write("--shader\n")
65 elif ext == '.rtcf':
66 worklist.write("--colorfilter\n")
67 elif ext == '.rtb':
68 worklist.write("--blender\n")
69 elif ext == '.mfrag':
70 worklist.write("--meshfrag\n")
71 elif ext == '.mvert':
72 worklist.write("--meshvert\n")
73 worklist.write(target + ".minified.sksl\n")
74 worklist.write(input + "\n")
75 worklist.write(public_module + "\n")
76 worklist.write(shared_module + "\n\n")
77
78 # Compile items one at a time.
79 if not batchMinify:
80 executeWorklist(input, worklist)
81 worklist = tempfile.NamedTemporaryFile(suffix='.worklist', delete=False, mode='w')
82
83# Compile everything all in one go.
84if batchMinify:
85 executeWorklist("", worklist)
86else:
87 worklist.close()
88 os.remove(worklist.name)
void print(void *str)
Definition bridge.cpp:126
executeWorklist(input, worklist)
static DecodeResult decode(std::string path)