[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.
This commit is contained in:
Ebrahim Byagowi 2020-05-23 22:13:32 +04:30
parent b32d169d22
commit e3af529e51
3 changed files with 38 additions and 15 deletions

View File

@ -10,10 +10,18 @@ major, minor, micro = version.split (".")
input = sys.argv[2]
output = sys.argv[3]
with open (output, "wb") as output_file, open (input, "r", encoding='utf-8') as input_file:
output_file.write (input_file.read ()
with open (input, "r", encoding='utf-8') as input_file:
generated = (input_file.read ()
.replace ("@HB_VERSION_MAJOR@", major)
.replace ("@HB_VERSION_MINOR@", minor)
.replace ("@HB_VERSION_MICRO@", micro)
.replace ("@HB_VERSION@", version)
.encode ())
with open (output, "rb") as current_file:
current = current_file.read()
# write only if is changed
if generated != current:
with open (output, "wb") as output_file:
output_file.write ()

View File

@ -1,11 +1,12 @@
#!/usr/bin/env python3
import io, os, re, sys, subprocess, shutil
import io, os, re, sys, subprocess, shutil, tempfile
if len (sys.argv) < 3:
os.chdir(os.path.dirname(__file__))
if len (sys.argv) < 2:
ragel_sources = [x for x in os.listdir ('.') if x.endswith ('.rl')]
else:
os.chdir(sys.argv[1])
ragel_sources = sys.argv[2:]
ragel = shutil.which ('ragel')
@ -17,6 +18,23 @@ if not ragel:
if not len (ragel_sources):
exit (77)
tempdir = tempfile.mkdtemp ()
for rl in ragel_sources:
hh = rl.replace ('.rl', '.hh')
subprocess.Popen ([ragel, '-e', '-F1', '-o', hh, rl]).wait ()
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)

View File

@ -289,16 +289,13 @@ custom_target('hb-version.h',
ragel = find_program('ragel', required: false)
if not ragel.found()
message('You have to install ragel if you are going to develop HarfBuzz itself')
warning('You have to install ragel if you are going to develop HarfBuzz itself')
else
foreach rl : hb_base_ragel_sources
hh = rl.split('.rl')[0] + '.hh'
custom_target(hh,
custom_target('ragel header files',
build_by_default: true,
depfile: rl,
output: hh,
command: [find_program('gen-ragel-artifacts.py'), meson.current_source_dir(), rl])
endforeach
input: hb_base_ragel_sources,
output: '.ragel-artifacts',
command: [find_program('gen-ragel-artifacts.py')] + hb_base_ragel_sources)
endif
custom_target('harfbuzz.cc',