mirror of https://github.com/Desuuuu/klipper.git
buildcommands: Move version generation to its own class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
9f420f71a5
commit
95e4c2d617
|
@ -39,7 +39,7 @@ class HandleCallList:
|
||||||
self.call_lists.setdefault(funcname, []).append(callname)
|
self.call_lists.setdefault(funcname, []).append(callname)
|
||||||
def update_data_dictionary(self, data):
|
def update_data_dictionary(self, data):
|
||||||
pass
|
pass
|
||||||
def generate_code(self):
|
def generate_code(self, options):
|
||||||
code = []
|
code = []
|
||||||
for funcname, funcs in self.call_lists.items():
|
for funcname, funcs in self.call_lists.items():
|
||||||
func_code = [' extern void %s(void);\n %s();' % (f, f)
|
func_code = [' extern void %s(void);\n %s();' % (f, f)
|
||||||
|
@ -76,7 +76,7 @@ class HandleStaticStrings:
|
||||||
def update_data_dictionary(self, data):
|
def update_data_dictionary(self, data):
|
||||||
data['static_strings'] = { i + STATIC_STRING_MIN: s
|
data['static_strings'] = { i + STATIC_STRING_MIN: s
|
||||||
for i, s in enumerate(self.static_strings) }
|
for i, s in enumerate(self.static_strings) }
|
||||||
def generate_code(self):
|
def generate_code(self, options):
|
||||||
code = []
|
code = []
|
||||||
for i, s in enumerate(self.static_strings):
|
for i, s in enumerate(self.static_strings):
|
||||||
code.append(' if (__builtin_strcmp(str, "%s") == 0)\n'
|
code.append(' if (__builtin_strcmp(str, "%s") == 0)\n'
|
||||||
|
@ -113,7 +113,7 @@ class HandleConstants:
|
||||||
self.constants[name] = value
|
self.constants[name] = value
|
||||||
def update_data_dictionary(self, data):
|
def update_data_dictionary(self, data):
|
||||||
data['config'] = self.constants
|
data['config'] = self.constants
|
||||||
def generate_code(self):
|
def generate_code(self, options):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
Handlers.append(HandleConstants())
|
Handlers.append(HandleConstants())
|
||||||
|
@ -166,7 +166,6 @@ class HandleCommandGeneration:
|
||||||
msgid += 1
|
msgid += 1
|
||||||
self.msg_to_id[msg] = msgid
|
self.msg_to_id[msg] = msgid
|
||||||
def update_data_dictionary(self, data):
|
def update_data_dictionary(self, data):
|
||||||
self.create_message_ids()
|
|
||||||
messages = { msgid: msg for msg, msgid in self.msg_to_id.items() }
|
messages = { msgid: msg for msg, msgid in self.msg_to_id.items() }
|
||||||
data['messages'] = messages
|
data['messages'] = messages
|
||||||
commands = [self.msg_to_id[msg]
|
commands = [self.msg_to_id[msg]
|
||||||
|
@ -293,7 +292,8 @@ const uint8_t command_index_size PROGMEM = ARRAY_SIZE(command_index);
|
||||||
paramid, ', '.join(argtypes),))
|
paramid, ', '.join(argtypes),))
|
||||||
params.append('')
|
params.append('')
|
||||||
return "\n".join(params)
|
return "\n".join(params)
|
||||||
def generate_code(self):
|
def generate_code(self, options):
|
||||||
|
self.create_message_ids()
|
||||||
parsercode = self.generate_responses_code()
|
parsercode = self.generate_responses_code()
|
||||||
cmdcode = self.generate_commands_code()
|
cmdcode = self.generate_commands_code()
|
||||||
paramcode = self.generate_param_code()
|
paramcode = self.generate_param_code()
|
||||||
|
@ -306,12 +306,10 @@ Handlers.append(HandleCommandGeneration())
|
||||||
# Identify data dictionary generation
|
# Identify data dictionary generation
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def build_identify(version, toolstr):
|
def build_identify():
|
||||||
data = {}
|
data = {}
|
||||||
for h in Handlers:
|
for h in Handlers:
|
||||||
h.update_data_dictionary(data)
|
h.update_data_dictionary(data)
|
||||||
data['version'] = version
|
|
||||||
data['build_versions'] = toolstr
|
|
||||||
|
|
||||||
# Format compressed info into C code
|
# Format compressed info into C code
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
|
@ -322,9 +320,6 @@ def build_identify(version, toolstr):
|
||||||
out.append('\n ')
|
out.append('\n ')
|
||||||
out.append(" 0x%02x," % (ord(zdata[i]),))
|
out.append(" 0x%02x," % (ord(zdata[i]),))
|
||||||
fmt = """
|
fmt = """
|
||||||
// version: %s
|
|
||||||
// build_versions: %s
|
|
||||||
|
|
||||||
const uint8_t command_identify_data[] PROGMEM = {%s
|
const uint8_t command_identify_data[] PROGMEM = {%s
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -332,7 +327,7 @@ const uint8_t command_identify_data[] PROGMEM = {%s
|
||||||
const uint32_t command_identify_size PROGMEM
|
const uint32_t command_identify_size PROGMEM
|
||||||
= ARRAY_SIZE(command_identify_data);
|
= ARRAY_SIZE(command_identify_data);
|
||||||
"""
|
"""
|
||||||
return data, fmt % (version, toolstr, ''.join(out), len(zdata), len(data))
|
return data, fmt % (''.join(out), len(zdata), len(data))
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -406,6 +401,23 @@ def tool_versions(tools):
|
||||||
cleanbuild = versions[0] and versions[1] and success == len(tools)
|
cleanbuild = versions[0] and versions[1] and success == len(tools)
|
||||||
return cleanbuild, "gcc: %s binutils: %s" % (versions[0], versions[1])
|
return cleanbuild, "gcc: %s binutils: %s" % (versions[0], versions[1])
|
||||||
|
|
||||||
|
# Add version information to the data dictionary
|
||||||
|
class HandleVersions:
|
||||||
|
def __init__(self):
|
||||||
|
self.ctr_dispatch = {}
|
||||||
|
self.toolstr = self.version = ""
|
||||||
|
def update_data_dictionary(self, data):
|
||||||
|
data['version'] = self.version
|
||||||
|
data['build_versions'] = self.toolstr
|
||||||
|
def generate_code(self, options):
|
||||||
|
cleanbuild, self.toolstr = tool_versions(options.tools)
|
||||||
|
self.version = build_version(options.extra)
|
||||||
|
sys.stdout.write("Version: %s\n" % (self.version,))
|
||||||
|
return "\n// version: %s\n// build_versions: %s\n" % (
|
||||||
|
self.version, self.toolstr)
|
||||||
|
|
||||||
|
Handlers.append(HandleVersions())
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Main code
|
# Main code
|
||||||
|
@ -444,14 +456,11 @@ def main():
|
||||||
error("Unknown build time command '%s'" % cmd)
|
error("Unknown build time command '%s'" % cmd)
|
||||||
ctr_dispatch[cmd](req)
|
ctr_dispatch[cmd](req)
|
||||||
# Create identify information
|
# Create identify information
|
||||||
cleanbuild, toolstr = tool_versions(options.tools)
|
code = "".join([h.generate_code(options) for h in Handlers])
|
||||||
version = build_version(options.extra)
|
datadict, icode = build_identify()
|
||||||
sys.stdout.write("Version: %s\n" % (version,))
|
|
||||||
datadict, icode = build_identify(version, toolstr)
|
|
||||||
# Write output
|
# Write output
|
||||||
f = open(outcfile, 'wb')
|
f = open(outcfile, 'wb')
|
||||||
f.write(FILEHEADER + "".join([h.generate_code() for h in Handlers])
|
f.write(FILEHEADER + code + icode)
|
||||||
+ icode)
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Write data dictionary
|
# Write data dictionary
|
||||||
|
|
Loading…
Reference in New Issue