[meson] use the recommended way to generate hb-version.h

As https://github.com/harfbuzz/harfbuzz/pull/2532
This commit is contained in:
Ebrahim Byagowi 2020-07-04 12:04:41 +04:30
parent 404ecc252c
commit a7e82e4ffd
3 changed files with 21 additions and 22 deletions

View File

@ -1,31 +1,27 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"usage: gen-hb-version.py 1.0.0 hb-version.h.in hb-version.h" "This tool is intended to be used from meson"
import os, sys import os, sys, shutil
os.chdir (os.path.dirname (__file__)) if len (sys.argv) < 5:
if len (sys.argv) < 4:
sys.exit(__doc__) sys.exit(__doc__)
version = sys.argv[1] version = sys.argv[1]
major, minor, micro = version.split (".") major, minor, micro = version.split (".")
input = sys.argv[2]
output = sys.argv[3]
with open (input, "r", encoding='utf-8') as input_file: OUTPUT = sys.argv[2]
generated = (input_file.read () CURRENT_SOURCE_DIR = sys.argv[3]
.replace ("@HB_VERSION_MAJOR@", major) INPUT = sys.argv[4]
.replace ("@HB_VERSION_MINOR@", minor)
.replace ("@HB_VERSION_MICRO@", micro)
.replace ("@HB_VERSION@", version)
.encode ())
with open (output, "rb") as current_file: with open (INPUT, "r", encoding='utf-8') as template:
current = current_file.read() with open (OUTPUT, "wb") as output:
output.write (template.read ()
.replace ("@HB_VERSION_MAJOR@", major)
.replace ("@HB_VERSION_MINOR@", minor)
.replace ("@HB_VERSION_MICRO@", micro)
.replace ("@HB_VERSION@", version)
.encode ())
# write only if is changed # copy it also to src/
if generated != current: shutil.copyfile (OUTPUT, os.path.join (CURRENT_SOURCE_DIR, os.path.basename (OUTPUT)))
with open (output, "wb") as output_file:
output_file.write (generated)

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"This tool is intended to be used from meson"
import os, os.path, sys, subprocess, shutil, tempfile import os, os.path, sys, subprocess, shutil, tempfile
ragel = shutil.which ('ragel') ragel = shutil.which ('ragel')
@ -7,7 +9,7 @@ if not ragel:
exit ('You have to install ragel if you are going to develop HarfBuzz itself') exit ('You have to install ragel if you are going to develop HarfBuzz itself')
if len (sys.argv) < 4: if len (sys.argv) < 4:
exit ('This tool is intended to be used from meson') exit (__doc__)
OUTPUT = sys.argv[1] OUTPUT = sys.argv[1]
CURRENT_SOURCE_DIR = sys.argv[2] CURRENT_SOURCE_DIR = sys.argv[2]

View File

@ -287,7 +287,8 @@ custom_target('hb-version.h',
input: 'hb-version.h.in', input: 'hb-version.h.in',
output: 'hb-version.h', output: 'hb-version.h',
command: [find_program('gen-hb-version.py'), meson.project_version(), command: [find_program('gen-hb-version.py'), meson.project_version(),
'hb-version.h.in', 'hb-version.h']) '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
)
ragel = find_program('ragel', required: false) ragel = find_program('ragel', required: false)
if not ragel.found() if not ragel.found()