skia2/gn/dehydrate_sksl.py

29 lines
755 B
Python
Raw Normal View History

#!/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]
Reland "Untangle dependency cycle in sksl dehydration" Explanation: The sksl standalone compiler is used to convert the raw (text) SkSL pre-includes into a "dehydrated" binary format. It also (previously) depended on those files, as they were #included and used, unless a special #define was changed. This created a dependency cycle that we hid from GN (by lying about the outputs of the dehydrate step). As a result, builds would never reach steady-state, because the compiler would be rebuilt (due to the newer dehydrated files), and then the dehydrated files would be rebuilt (due to the newer compiler). This CL changes the logic so that the standalone compiler always uses the textual pre-includes, and no longer depends on the dehydrated binary files. Thus, to make any kind of change to the dehydrated files (whether due to pre-include changes, or the encoding format itself), you just need skia_compile_processors enabled. The dependencies are now honestly communicated to GN, and we reach steady state after one build. The NOTE above is because GN/ninja cache the dependencies of each target, and will still think that the SkSLCompiler.obj linked into the standalone compiler depends on the dehydrated files, at least until one successful build, when it will realize that's no longer true. Reland notes: The bots originally rejected this CL, because SkSLCompiler was hard-coded to load the text files from a relative path that assumed the executable was in "<skia_checkout>/out/<some_dir>". That's not true for bots, and it was fragile, even for users. Now, we use GN to directly generate sksl_fp.sksl, and copy all of the other pre-includes to the root out dir (working directory when running skslc). This means we no longer need to generate the sksl_fp.sksl file into the src tree, and the compiler can more safely assume that the files will be in the working directory. Bug: skia:10571 Change-Id: Id7837a9aba7ee0c3f7fa82eb84f7761e24b9c705 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308896 Reviewed-by: Mike Klein <mtklein@google.com> Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2020-08-08 12:17:18 +00:00
targetDir = sys.argv[2]
Revert "Untangle dependency cycle in sksl dehydration" This reverts commit a1ed0dc9f81255351eefe999975408f7afb32cfd. Reason for revert: Bots will need some guidance to ingest this CL Original change's description: > Untangle dependency cycle in sksl dehydration > > NOTE: If you have any out directories with skia_compile_processors > enabled, you will likely need to run `gn clean <dir>` > > Explanation: The sksl standalone compiler is used to convert the raw > (text) SkSL pre-includes into a "dehydrated" binary format. It also > (previously) depended on those files, as they were #included and used, > unless a special #define was changed. This created a dependency cycle > that we hid from GN (by lying about the outputs of the dehydrate step). > As a result, builds would never reach steady-state, because the compiler > would be rebuilt (due to the newer dehydrated files), and then the > dehydrated files would be rebuilt (due to the newer compiler). > > This CL changes the logic so that the standalone compiler always uses > the textual pre-includes, and no longer depends on the dehydrated binary > files. Thus, to make any kind of change to the dehydrated files (whether > due to pre-include changes, or the encoding format itself), you just > need skia_compile_processors enabled. The dependencies are now honestly > communicated to GN, and we reach steady state after one build. > > The NOTE above is because GN/ninja cache the dependencies of each > target, and will still think that the SkSLCompiler.obj linked into the > standalone compiler depends on the dehydrated files, at least until one > successful build, when it will realize that's no longer true. > > Bug: skia:10571 > Change-Id: I246360cec387b17d017805ed42ab6424329e32e7 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308760 > Reviewed-by: Mike Klein <mtklein@google.com> > Reviewed-by: John Stiles <johnstiles@google.com> > Commit-Queue: Brian Osman <brianosman@google.com> TBR=mtklein@google.com,brianosman@google.com,ethannicholas@google.com,johnstiles@google.com Change-Id: Id0f3f6e18474f7531b8531cfa481031c26b88d51 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:10571 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308802 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2020-08-07 21:28:12 +00:00
includes = sys.argv[3:]
for inc in includes:
print("Recompiling " + inc + "...")
try:
noExt, _ = os.path.splitext(inc)
head, tail = os.path.split(noExt)
if not os.path.isdir(targetDir):
os.mkdir(targetDir)
target = os.path.join(targetDir, tail)
subprocess.check_output([skslc, inc, target + ".dehydrated.sksl"])
except subprocess.CalledProcessError as err:
print("### Error compiling " + inc + ":")
print(err.output)
exit(1)