| 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 |
|
| 8 |
import os |
| 9 |
import subprocess |
| 10 |
import sys |
| 11 |
|
| 12 |
sksl_minify = sys.argv[1] |
| 13 |
targetDir = sys.argv[2] |
| 14 |
modules = sys.argv[3:] |
| 15 |
|
| 16 |
# sksl-minify uses the dependency list to ensure that minified names are unique at global scope. |
| 17 |
dependencies = { |
| 18 |
'sksl_compute': ['sksl_gpu', 'sksl_shared'], |
| 19 |
'sksl_gpu': ['sksl_shared'], |
| 20 |
'sksl_frag': ['sksl_gpu', 'sksl_shared'], |
| 21 |
'sksl_vert': ['sksl_gpu', 'sksl_shared'], |
| 22 |
'sksl_graphite_frag': ['sksl_frag', 'sksl_gpu', 'sksl_shared'], |
| 23 |
'sksl_graphite_vert': ['sksl_vert', 'sksl_gpu', 'sksl_shared'], |
| 24 |
'sksl_public': ['sksl_shared'], |
| 25 |
'sksl_rt_shader': ['sksl_public', 'sksl_shared'], |
| 26 |
'sksl_shared': [], |
| 27 |
} |
| 28 |
|
| 29 |
for module in modules: |
| 30 |
try: |
| 31 |
moduleDir, moduleName = os.path.split(os.path.splitext(module)[0]) |
| 32 |
if not os.path.isdir(targetDir): |
| 33 |
os.mkdir(targetDir) |
| 34 |
target = os.path.join(targetDir, moduleName) |
| 35 |
|
| 36 |
# Determine the program kind based on the module name. |
| 37 |
if "_compute" in module: |
| 38 |
programKind = "--compute" |
| 39 |
elif "_vert" in module: |
| 40 |
programKind = "--vert" |
| 41 |
else: |
| 42 |
programKind = "--frag" |
| 43 |
|
| 44 |
# Assemble the module dependency list and call sksl-minify to recreate the module in its |
| 45 |
# minified form. |
| 46 |
moduleList = [module] |
| 47 |
if moduleName not in dependencies: |
| 48 |
print("### Error compiling " + moduleName + ": dependency list must be specified") |
| 49 |
exit(1) |
| 50 |
for dependent in dependencies[moduleName]: |
| 51 |
moduleList.append(os.path.join(moduleDir, dependent) + ".sksl") |
| 52 |
|
| 53 |
# Generate fully-optimized and minified module data (for release/optimize-for-size builds). |
| 54 |
destPath = target + ".minified.sksl" |
| 55 |
args = [sksl_minify, programKind, "--stringify", destPath] + moduleList |
| 56 |
subprocess.check_output(args).decode('utf-8') |
| 57 |
|
| 58 |
# Generate unoptimized module data (used in debug, for improved readability). |
| 59 |
destPath = target + ".unoptimized.sksl" |
| 60 |
args = [sksl_minify, programKind, "--unoptimized", "--stringify", destPath] + moduleList |
| 61 |
subprocess.check_output(args).decode('utf-8') |
| 62 |
|
| 63 |
except subprocess.CalledProcessError as err: |
| 64 |
print("### Error compiling " + module + ":") |
| 65 |
print(err.output) |
| 66 |
exit(1) |