Skip to content

Commit eb28f6b

Browse files
committed
Added --set_version to debug_version.py to print version.h with new version
1 parent e3f81f8 commit eb28f6b

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

debug_version.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def build_argparser():
1818
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
1919
parser.add_argument("--use_modified_date", action="store_true",
2020
help="use date of newest modified file instead of commit date")
21-
parser.add_argument("--update_version_h", action="store_true",
22-
help="update include/version.h with current commit information")
21+
parser.add_argument("--set_version",
22+
help="update include/version.h and create annotated tag")
2323
return parser
2424

2525
def run_command(cmd):
@@ -57,14 +57,25 @@ def load_version_macros(path):
5757
macros[name] = value
5858
return macros
5959

60+
def update_version_macros(path, macros):
61+
txt = [line.rstrip() for line in open(path)]
62+
for line in txt:
63+
m = re.match(MACRO_PATTERN, line)
64+
if m:
65+
name = m.group(1)
66+
if name not in macros:
67+
continue
68+
line = f"#define {name} {macros[name]}"
69+
print(line)
70+
return
71+
6072
def main():
6173
base = get_repo_base()
6274
if not is_fujinet_repo(base):
6375
print("Not in FujiNet firmware repo")
6476
return 0
6577

6678
args = build_argparser().parse_args()
67-
# FIXME - don't allow update_version_h unless on the actual tag?
6879

6980
version_h_path = os.path.join(base, VERSION_H)
7081
version = get_commit_version()
@@ -86,17 +97,37 @@ def main():
8697
ver_major = int(cur_macros['FN_VERSION_MAJOR'])
8798
ver_minor = int(cur_macros['FN_VERSION_MINOR'])
8899

89-
m = re.match(r"^v([0-9]+)[.]([0-9]+)[.]([0-9]+)-([0-9]+)-g(.*)", version)
90-
if m:
91-
ver_major = macros['FN_VERSION_MAJOR'] = int(m.group(1))
92-
ver_minor = macros['FN_VERSION_MINOR'] = int(m.group(2))
93-
version = f"v{m.group(1)}.{m.group(2)}-{m.group(5)}"
100+
if args.set_version:
101+
version = args.set_version
102+
m = re.match(r"^v([0-9]+)[.]([0-9]+)([.]([0-9]+))?(-rc([0-9]+))?", version)
103+
if not m:
104+
print("Unable to parse version:", version)
105+
exit(1)
106+
ver_major = int(m.group(1))
107+
ver_minor = int(m.group(2))
108+
ver_patch = 0
109+
cur_macros['FN_VERSION_MAJOR'] = ver_major
110+
cur_macros['FN_VERSION_MINOR'] = ver_minor
111+
if m.group(4):
112+
ver_patch = int(m.group(4))
113+
cur_macros['FN_VERSION_PATCH'] = ver_patch
114+
if m.group(6):
115+
ver_rc = int(m.group(6))
116+
cur_macros['FN_VERSION_RC'] = ver_rc
117+
cur_macros['FN_VERSION_DATE'] = modified
118+
94119
else:
95-
m = re.match(r"^([a-z0-9]{8})$", version)
120+
m = re.match(r"^v([0-9]+)[.]([0-9]+)[.]([0-9]+)-([0-9]+)-g(.*)", version)
96121
if m:
97-
version = f"v{ver_major}.{ver_minor}-{version}"
98-
99-
if modified:
122+
ver_major = macros['FN_VERSION_MAJOR'] = int(m.group(1))
123+
ver_minor = macros['FN_VERSION_MINOR'] = int(m.group(2))
124+
version = f"v{m.group(1)}.{m.group(2)}-{m.group(5)}"
125+
else:
126+
m = re.match(r"^([a-z0-9]{8})$", version)
127+
if m:
128+
version = f"v{ver_major}.{ver_minor}-{version}"
129+
130+
if modified and not args.set_version:
100131
version += "*"
101132
macros['FN_VERSION_FULL'] = version
102133
macros['FN_VERSION_DATE'] = datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M:%S")
@@ -118,10 +149,12 @@ def main():
118149
mdef += f"={value}"
119150
macro_defs.append(shlex.quote(mdef))
120151

121-
# FIXME - if args.update_version_h then update, don't print
122-
macro_defs = " ".join(macro_defs)
123-
print(macro_defs)
124-
#Path(version_h_path).touch()
152+
if args.set_version:
153+
update_version_macros(version_h_path, cur_macros)
154+
else:
155+
macro_defs = " ".join(macro_defs)
156+
print(macro_defs)
157+
#Path(version_h_path).touch()
125158

126159
return
127160

0 commit comments

Comments
 (0)