As described in https://github.com/mesonbuild/meson/issues/7156#issuecomment-629622827pull/2535/head
parent
5c07c291c7
commit
785a9a8f8a
3 changed files with 66 additions and 68 deletions
@ -1,40 +1,23 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import os, 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:] |
||||
import os, os.path, sys, subprocess, shutil, tempfile |
||||
|
||||
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 () |
||||
exit ('You have to install ragel if you are going to develop HarfBuzz itself') |
||||
|
||||
generated_path = os.path.join (tempdir, hh) |
||||
with open (generated_path, "rb") as temp_file: |
||||
generated = temp_file.read() |
||||
if len (sys.argv) < 4: |
||||
exit ('This tool is intended to be used from meson') |
||||
|
||||
with open (hh, "rb") as current_file: |
||||
current = current_file.read() |
||||
OUTPUT = sys.argv[1] |
||||
CURRENT_SOURCE_DIR = sys.argv[2] |
||||
INPUT = sys.argv[3] |
||||
|
||||
# overwrite only if is changed |
||||
if generated != current: |
||||
shutil.copyfile (generated_path, hh) |
||||
outdir = os.path.dirname (OUTPUT) |
||||
shutil.copy (INPUT, outdir) |
||||
rl = os.path.basename (INPUT) |
||||
hh = rl.replace ('.rl', '.hh') |
||||
subprocess.Popen ([ragel, '-e', '-F1', '-o', hh, rl], cwd=outdir).wait () |
||||
|
||||
shutil.rmtree (tempdir) |
||||
# copy it also to src/ |
||||
shutil.copyfile (os.path.join (outdir, hh), os.path.join (CURRENT_SOURCE_DIR, hh)) |
||||
|
Loading…
Reference in new issue