2020-04-21 09:49:16 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-05-28 12:31:15 +02:00
|
|
|
"usage: gen-hb-version.py 1.0.0 hb-version.h.in hb-version.h"
|
|
|
|
|
2020-07-03 12:39:10 +02:00
|
|
|
import os, sys
|
2020-04-21 09:49:16 +02:00
|
|
|
|
2020-06-02 16:48:35 +02:00
|
|
|
os.chdir (os.path.dirname (__file__))
|
|
|
|
|
2020-04-21 09:49:16 +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 (".")
|
|
|
|
input = sys.argv[2]
|
|
|
|
output = sys.argv[3]
|
|
|
|
|
2020-05-23 19:43:32 +02:00
|
|
|
with open (input, "r", encoding='utf-8') as input_file:
|
|
|
|
generated = (input_file.read ()
|
2020-04-21 09:49:16 +02:00
|
|
|
.replace ("@HB_VERSION_MAJOR@", major)
|
|
|
|
.replace ("@HB_VERSION_MINOR@", minor)
|
|
|
|
.replace ("@HB_VERSION_MICRO@", micro)
|
|
|
|
.replace ("@HB_VERSION@", version)
|
|
|
|
.encode ())
|
2020-05-23 19:43:32 +02:00
|
|
|
|
|
|
|
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:
|
2020-06-02 16:48:35 +02:00
|
|
|
output_file.write (generated)
|