engine_control/source/scripts/release_number.py

44 lines
1.2 KiB
Python
Raw Normal View History

2016-08-21 11:45:36 +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_MAJOR"):
config["sw_major"] = os.environ["SW_MAJOR"]
if os.environ.has_key("SW_MINOR"):
config["sw_minor"] = os.environ["SW_MINOR"]
if os.environ.has_key("CI_BUILD_ID"):
config["build_id"] = os.environ["CI_BUILD_ID"]
return config
def generate_include(numbers):
f = open("source/application/include/version.h", "w")
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_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")
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")
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:])