Hash :
e3af529e
Author :
Date :
2020-05-23T22:13:32
[meson] update generated headers only when the result is different This way it won't ruin incremental builds. We need a better way to declare source altering tasks https://github.com/mesonbuild/meson/issues/7156 yet this is good enough despite being not idiomatic. It is however not that smooth yet as the change may is detected on the next meson run. One of course can issue ./gen-ragel-artifacts.py manually for better experience before running meson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/env python3
import io, os, re, sys, subprocess, shutil, tempfile
os.chdir(os.path.dirname(__file__))
if len (sys.argv) < 2:
ragel_sources = [x for x in os.listdir ('.') if x.endswith ('.rl')]
else:
ragel_sources = sys.argv[2:]
ragel = shutil.which ('ragel')
if not ragel:
print ('You have to install ragel if you are going to develop HarfBuzz itself')
exit (1)
if not len (ragel_sources):
exit (77)
tempdir = tempfile.mkdtemp ()
for rl in ragel_sources:
hh = rl.replace ('.rl', '.hh')
shutil.copy (rl, tempdir)
# writing to stdout has some complication on Windows
subprocess.Popen ([ragel, '-e', '-F1', '-o', hh, rl], cwd=tempdir).wait ()
generated_path = os.path.join (tempdir, hh)
with open (generated_path, "rb") as temp_file:
generated = temp_file.read()
with open (hh, "rb") as current_file:
current = current_file.read()
# overwrite only if is changed
if generated != current:
shutil.copyfile (generated_path, hh)
shutil.rmtree(tempdir)