2020-04-21 09:49:16 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-07-04 09:34:41 +02:00
|
|
|
"This tool is intended to be used from meson"
|
2020-05-28 12:31:15 +02:00
|
|
|
|
2020-12-23 08:31:03 +01:00
|
|
|
import os, sys, shutil, re
|
2020-04-21 09:49:16 +02:00
|
|
|
|
2020-09-07 18:11:17 +02:00
|
|
|
if len (sys.argv) < 4:
|
2020-05-28 12:31:15 +02:00
|
|
|
sys.exit(__doc__)
|
2020-04-21 09:49:16 +02:00
|
|
|
|
|
|
|
version = sys.argv[1]
|
|
|
|
major, minor, micro = version.split (".")
|
2020-05-23 19:43:32 +02:00
|
|
|
|
2020-07-04 09:34:41 +02:00
|
|
|
OUTPUT = sys.argv[2]
|
2020-09-07 18:11:17 +02:00
|
|
|
INPUT = sys.argv[3]
|
|
|
|
CURRENT_SOURCE_DIR = os.path.dirname(INPUT)
|
2020-07-04 09:34:41 +02:00
|
|
|
|
2020-12-23 08:31:03 +01:00
|
|
|
try:
|
2021-09-23 16:39:29 +02:00
|
|
|
with open (OUTPUT, "r", encoding='utf-8') as old_output:
|
2020-12-23 08:31:03 +01:00
|
|
|
for line in old_output:
|
|
|
|
old_version = re.match (r"#define HB_VERSION_STRING \"(\d.\d.\d)\"", line)
|
|
|
|
if old_version and old_version[1] == version:
|
|
|
|
sys.exit ()
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
2020-07-04 09:34:41 +02:00
|
|
|
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 ())
|
|
|
|
|
2022-03-24 21:16:41 +01:00
|
|
|
# copy it also to the source tree, but only if it has changed
|
|
|
|
baseline_filename = os.path.join (CURRENT_SOURCE_DIR, os.path.basename (OUTPUT))
|
|
|
|
with open(baseline_filename, "rb") as baseline:
|
|
|
|
with open(OUTPUT, "rb") as generated:
|
|
|
|
if baseline.read() != generated.read():
|
|
|
|
shutil.copyfile (OUTPUT, baseline_filename)
|