blob: 5c46d2c6dcfa1ead95bdb23f6536a6ba7810a471 [file] [log] [blame]
#!/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
sksl_minify = sys.argv[1]
targetDir = sys.argv[2]
modules = sys.argv[3:]
# This dependency list isn't currently referenced, but a more advanced minifier might need to know
# about dependent modules to ensure that names are always unique.
dependencies = {
'sksl_compute': ['sksl_gpu', 'sksl_shared'],
'sksl_gpu': ['sksl_shared'],
'sksl_frag': ['sksl_gpu', 'sksl_shared'],
'sksl_vert': ['sksl_gpu', 'sksl_shared'],
'sksl_graphite_frag': ['sksl_frag', 'sksl_gpu', 'sksl_shared'],
'sksl_graphite_vert': ['sksl_vert', 'sksl_gpu', 'sksl_shared'],
'sksl_public': ['sksl_shared'],
'sksl_rt_shader': ['sksl_public', 'sksl_shared'],
'sksl_shared': [],
for module in modules:
moduleDir, moduleName = os.path.split(os.path.splitext(module)[0])
if not os.path.isdir(targetDir):
target = os.path.join(targetDir, moduleName)
# Assemble the module dependency list and call sksl-minify to recreate the module in its
# minified form.
moduleList = [module]
if moduleName not in dependencies:
print("### Error compiling " + moduleName + ": dependency list must be specified")
for dependent in dependencies[moduleName]:
moduleList.append(os.path.join(moduleDir, dependent) + ".sksl")
# Generate fully-optimized and minified module data (for release/optimize-for-size builds).
args = [sksl_minify, target + ".minified.sksl"] + moduleList
# Generate unoptimized module data (used in debug, for improved readability).
args = [sksl_minify, "--unoptimized", target + ".unoptimized.sksl"] + moduleList
except subprocess.CalledProcessError as err:
print("### Error compiling " + module + ":")