diff --git a/src/gen-hb-version.py b/src/gen-hb-version.py index 222c65206..15e56b93f 100755 --- a/src/gen-hb-version.py +++ b/src/gen-hb-version.py @@ -1,31 +1,27 @@ #!/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) < 4: +if len (sys.argv) < 5: sys.exit(__doc__) version = sys.argv[1] major, minor, micro = version.split (".") -input = sys.argv[2] -output = sys.argv[3] -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 ()) +OUTPUT = sys.argv[2] +CURRENT_SOURCE_DIR = sys.argv[3] +INPUT = sys.argv[4] - with open (output, "rb") as current_file: - current = current_file.read() +with open (INPUT, "r", encoding='utf-8') as template: + 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 - if generated != current: - with open (output, "wb") as output_file: - output_file.write (generated) +# copy it also to src/ +shutil.copyfile (OUTPUT, os.path.join (CURRENT_SOURCE_DIR, os.path.basename (OUTPUT))) diff --git a/src/gen-ragel-artifacts.py b/src/gen-ragel-artifacts.py index f6dcd981d..aa370f889 100755 --- a/src/gen-ragel-artifacts.py +++ b/src/gen-ragel-artifacts.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +"This tool is intended to be used from meson" + import os, os.path, sys, subprocess, shutil, tempfile 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') if len (sys.argv) < 4: - exit ('This tool is intended to be used from meson') + exit (__doc__) OUTPUT = sys.argv[1] CURRENT_SOURCE_DIR = sys.argv[2] diff --git a/src/meson.build b/src/meson.build index 0de85a7e9..41e5fb64a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -287,7 +287,8 @@ custom_target('hb-version.h', input: 'hb-version.h.in', output: 'hb-version.h', 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) if not ragel.found()