Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / src / gen-hb-version.py
1 #!/usr/bin/env python3
2
3 "usage: gen-hb-version.py 1.0.0 hb-version.h.in hb-version.h"
4
5 import os, re, sys
6
7 os.chdir (os.path.dirname (__file__))
8
9 if len (sys.argv) < 4:
10         sys.exit(__doc__)
11
12 version = sys.argv[1]
13 major, minor, micro = version.split (".")
14 input = sys.argv[2]
15 output = sys.argv[3]
16
17 with open (input, "r", encoding='utf-8') as input_file:
18         generated = (input_file.read ()
19                 .replace ("@HB_VERSION_MAJOR@", major)
20                 .replace ("@HB_VERSION_MINOR@", minor)
21                 .replace ("@HB_VERSION_MICRO@", micro)
22                 .replace ("@HB_VERSION@", version)
23                 .encode ())
24
25         with open (output, "rb") as current_file:
26                 current = current_file.read()
27
28         # write only if is changed
29         if generated != current:
30                 with open (output, "wb") as output_file:
31                         output_file.write (generated)