kosmos/source/scripts/release_number.py

50 lines
1.5 KiB
Python
Raw Normal View History

2016-08-01 11:34:25 +00:00
#!/usr/bin/python2
from sys import argv, exit
from getopt import getopt
from re import match, sub
import os
def get_current_numbers():
config = {}
if os.environ.has_key("SW_KERNEL"):
config["sw_kernel"] = os.environ["SW_KERNEL"]
if os.environ.has_key("SW_MAJOR"):
config["sw_major"] = os.environ["SW_MAJOR"]
if os.environ.has_key("SW_MINOR"):
config["sw_minor"] = os.environ["SW_MINOR"]
2016-08-11 10:09:55 +00:00
if os.environ.has_key("CI_BUILD_ID"):
config["build_id"] = os.environ["CI_BUILD_ID"]
2016-08-01 11:34:25 +00:00
return config
def generate_include(numbers):
2016-08-01 11:39:10 +00:00
f = open("source/firmware/version.h", "w")
2016-08-01 11:34:25 +00:00
f.write("/* Release number include file */\n\n")
f.write("#ifndef VERSION_H\n")
f.write("#define VERSION_H\n\n")
if numbers.has_key("sw_kernel"):
f.write("#define KERNEL_VERSION\t\"" + numbers["sw_kernel"] + "\"\n")
else:
f.write("#define KERNEL_VERSION\t\"unknown\"\n")
if numbers.has_key("sw_major"):
f.write("#define MAJOR_VERSION\t\"" + numbers["sw_major"] + "\"\n")
else:
f.write("#define MAJOR_VERSION\t\"unknown\"\n")
if numbers.has_key("sw_minor"):
f.write("#define MINOR_VERSION\t\"" + numbers["sw_minor"] + "\"\n")
else:
f.write("#define MINOR_VERSION\t\"unknown\"\n")
2016-08-11 10:09:55 +00:00
if numbers.has_key("build_id"):
f.write("#define BUILD_NUMBER\t\"" + numbers["build_id"] + "\"\n")
else:
f.write("#define BUILD_NUMBER\t\"unknown\"\n")
2016-08-01 11:34:25 +00:00
f.write("\n#endif /* VERSION_H */\n")
f.close()
def main(argv):
numbers = get_current_numbers()
generate_include(numbers)
if __name__ == "__main__":
main(argv[1:])