diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-04-15 15:54:16 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-04-16 11:25:55 +0200 |
commit | bb5c88b852f4483a4bf411389e8807d7c43ea344 (patch) | |
tree | 7ceb4667b24bd284c8929c140c5b03690b29f1a4 /build-aux | |
parent | 05159e1a17e9d9a8812c59d00213df615164fd7f (diff) | |
download | libqmi-bb5c88b852f4483a4bf411389e8807d7c43ea344.tar.gz |
libqmi-glib: allow selecting 'collections' of messages to build
The build now allows selecting a specific collection of messages to
build using the '--enable-collection=[NAME]' option.
The default setup will allow three different collections:
* minimal: with just a very few features, enough to e.g. use
qmi-network and get the device connected.
* basic: with all features required by both qmi-firmware-update and
the third-party ModemManager daemon.
* full: with all supported messages.
Users building their own systems can patch libqmi by adding a new
custom collection file under e.g. /data/qmi-collection-vendor.json,
and will then be able to configure using --enable-collection=vendor.
Diffstat (limited to 'build-aux')
-rw-r--r-- | build-aux/qmi-codegen/Client.py | 258 | ||||
-rw-r--r-- | build-aux/qmi-codegen/Message.py | 5 | ||||
-rw-r--r-- | build-aux/qmi-codegen/MessageList.py | 168 | ||||
-rwxr-xr-x | build-aux/qmi-codegen/qmi-codegen | 12 |
4 files changed, 258 insertions, 185 deletions
diff --git a/build-aux/qmi-codegen/Client.py b/build-aux/qmi-codegen/Client.py index 8948d5be..379b9d67 100644 --- a/build-aux/qmi-codegen/Client.py +++ b/build-aux/qmi-codegen/Client.py @@ -51,17 +51,21 @@ class Client: raise ValueError('Missing Service field') """ + Emits the symbol specifying if the service is supported + """ + def __emit_supported(self, f, supported): + translations = { 'service' : self.service.upper() } + template = '\n' + if supported: + template += '#define HAVE_QMI_SERVICE_${service}\n' + else: + template += '/* HAVE_QMI_SERVICE_${service} */\n' + f.write(string.Template(template).substitute(translations)) + + """ Emits the generic GObject class implementation """ def __emit_class(self, hfile, cfile, message_list): - - # Check if we'll have indications - has_indications = False - for message in message_list.list: - if message.type == 'Indication': - has_indications = True - break - translations = { 'underscore' : utils.build_underscore_name(self.name), 'no_prefix_underscore_upper' : utils.build_underscore_name(self.name[4:]).upper(), 'camelcase' : utils.build_camelcase_name(self.name), @@ -121,16 +125,15 @@ class Client: template += ( 'G_DEFINE_TYPE (${camelcase}, ${underscore}, QMI_TYPE_CLIENT)\n') - if has_indications: + if len(message_list.indication_list) > 0: template += ( '\n' 'enum {\n') - for message in message_list.list: - if message.type == 'Indication': - translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) - inner_template = ( - ' SIGNAL_${signal_id},\n') - template += string.Template(inner_template).substitute(translations) + for message in message_list.indication_list: + translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) + inner_template = ( + ' SIGNAL_${signal_id},\n') + template += string.Template(inner_template).substitute(translations) template += ( ' SIGNAL_LAST\n' '};\n' @@ -145,45 +148,44 @@ class Client: '{\n' ' switch (qmi_message_get_message_id (message)) {\n') - for message in message_list.list: - if message.type == 'Indication': - translations['enum_name'] = message.id_enum_name - translations['message_fullname_underscore'] = utils.build_underscore_name(message.fullname) - translations['message_name'] = message.name - translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) - inner_template = '' - if message.output is not None and message.output.fields is not None: - # At least one field in the indication - translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname) - translations['output_underscore'] = utils.build_underscore_name(message.output.fullname) - translations['output_underscore'] = utils.build_underscore_name(message.output.fullname) - inner_template += ( - ' case ${enum_name}: {\n' - ' ${output_camelcase} *output;\n' - ' GError *error = NULL;\n' - '\n' - ' /* Parse indication */\n' - ' output = __${message_fullname_underscore}_indication_parse (message, &error);\n' - ' if (!output) {\n' - ' g_warning ("Couldn\'t parse \'${message_name}\' indication: %s",\n' - ' error ? error->message : "Unknown error");\n' - ' if (error)\n' - ' g_error_free (error);\n' - ' } else {\n' - ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, output);\n' - ' ${output_underscore}_unref (output);\n' - ' }\n' - ' break;\n' - ' }\n') - else: - # No output field in the indication - inner_template += ( - ' case ${enum_name}: {\n' - ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, NULL);\n' - ' break;\n' - ' }\n') + for message in message_list.indication_list: + translations['enum_name'] = message.id_enum_name + translations['message_fullname_underscore'] = utils.build_underscore_name(message.fullname) + translations['message_name'] = message.name + translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) + inner_template = '' + if message.output is not None and message.output.fields is not None: + # At least one field in the indication + translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname) + translations['output_underscore'] = utils.build_underscore_name(message.output.fullname) + translations['output_underscore'] = utils.build_underscore_name(message.output.fullname) + inner_template += ( + ' case ${enum_name}: {\n' + ' ${output_camelcase} *output;\n' + ' GError *error = NULL;\n' + '\n' + ' /* Parse indication */\n' + ' output = __${message_fullname_underscore}_indication_parse (message, &error);\n' + ' if (!output) {\n' + ' g_warning ("Couldn\'t parse \'${message_name}\' indication: %s",\n' + ' error ? error->message : "Unknown error");\n' + ' if (error)\n' + ' g_error_free (error);\n' + ' } else {\n' + ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, output);\n' + ' ${output_underscore}_unref (output);\n' + ' }\n' + ' break;\n' + ' }\n') + else: + # No output field in the indication + inner_template += ( + ' case ${enum_name}: {\n' + ' g_signal_emit (self, signals[SIGNAL_${signal_id}], 0, NULL);\n' + ' break;\n' + ' }\n') - template += string.Template(inner_template).substitute(translations) + template += string.Template(inner_template).substitute(translations) template += ( ' default:\n' @@ -203,64 +205,63 @@ class Client: '\n' ' client_class->process_indication = process_indication;\n') - for message in message_list.list: - if message.type == 'Indication': - translations['signal_name'] = utils.build_dashed_name(message.name) - translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) - translations['message_name'] = message.name - translations['since'] = message.since - inner_template = '' - if message.output is not None and message.output.fields is not None: - # At least one field in the indication - translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname) - translations['bundle_type'] = 'QMI_TYPE_' + utils.remove_prefix(utils.build_underscore_uppercase_name(message.output.fullname), 'QMI_') - translations['service'] = self.service.upper() - translations['message_name_dashed'] = message.name.replace(' ', '-') - inner_template += ( - '\n' - ' /**\n' - ' * ${camelcase}::${signal_name}:\n' - ' * @object: A #${camelcase}.\n' - ' * @output: A #${output_camelcase}.\n' - ' *\n' - ' * The ::${signal_name} signal gets emitted when a \'<link linkend=\"libqmi-glib-${service}-${message_name_dashed}-indication.top_of_page\">${message_name}</link>\' indication is received.\n' - ' *\n' - ' * Since: ${since}\n' - ' */\n' - ' signals[SIGNAL_${signal_id}] =\n' - ' g_signal_new ("${signal_name}",\n' - ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' - ' G_SIGNAL_RUN_LAST,\n' - ' 0,\n' - ' NULL,\n' - ' NULL,\n' - ' NULL,\n' - ' G_TYPE_NONE,\n' - ' 1,\n' - ' ${bundle_type});\n') - else: - # No output field in the indication - inner_template += ( - '\n' - ' /**\n' - ' * ${camelcase}::${signal_name}:\n' - ' * @object: A #${camelcase}.\n' - ' *\n' - ' * The ::${signal_name} signal gets emitted when a \'${message_name}\' indication is received.\n' - ' *\n' - ' * Since: ${since}\n' - ' */\n' - ' signals[SIGNAL_${signal_id}] =\n' - ' g_signal_new ("${signal_name}",\n' - ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' - ' G_SIGNAL_RUN_LAST,\n' - ' 0,\n' - ' NULL,\n' - ' NULL,\n' - ' NULL,\n' - ' G_TYPE_NONE,\n' - ' 0);\n') - template += string.Template(inner_template).substitute(translations) + for message in message_list.indication_list: + translations['signal_name'] = utils.build_dashed_name(message.name) + translations['signal_id'] = utils.build_underscore_uppercase_name(message.name) + translations['message_name'] = message.name + translations['since'] = message.since + inner_template = '' + if message.output is not None and message.output.fields is not None: + # At least one field in the indication + translations['output_camelcase'] = utils.build_camelcase_name(message.output.fullname) + translations['bundle_type'] = 'QMI_TYPE_' + utils.remove_prefix(utils.build_underscore_uppercase_name(message.output.fullname), 'QMI_') + translations['service'] = self.service.upper() + translations['message_name_dashed'] = message.name.replace(' ', '-') + inner_template += ( + '\n' + ' /**\n' + ' * ${camelcase}::${signal_name}:\n' + ' * @object: A #${camelcase}.\n' + ' * @output: A #${output_camelcase}.\n' + ' *\n' + ' * The ::${signal_name} signal gets emitted when a \'<link linkend=\"libqmi-glib-${service}-${message_name_dashed}-indication.top_of_page\">${message_name}</link>\' indication is received.\n' + ' *\n' + ' * Since: ${since}\n' + ' */\n' + ' signals[SIGNAL_${signal_id}] =\n' + ' g_signal_new ("${signal_name}",\n' + ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' + ' G_SIGNAL_RUN_LAST,\n' + ' 0,\n' + ' NULL,\n' + ' NULL,\n' + ' NULL,\n' + ' G_TYPE_NONE,\n' + ' 1,\n' + ' ${bundle_type});\n') + else: + # No output field in the indication + inner_template += ( + '\n' + ' /**\n' + ' * ${camelcase}::${signal_name}:\n' + ' * @object: A #${camelcase}.\n' + ' *\n' + ' * The ::${signal_name} signal gets emitted when a \'${message_name}\' indication is received.\n' + ' *\n' + ' * Since: ${since}\n' + ' */\n' + ' signals[SIGNAL_${signal_id}] =\n' + ' g_signal_new ("${signal_name}",\n' + ' G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)),\n' + ' G_SIGNAL_RUN_LAST,\n' + ' 0,\n' + ' NULL,\n' + ' NULL,\n' + ' NULL,\n' + ' G_TYPE_NONE,\n' + ' 0);\n') + template += string.Template(inner_template).substitute(translations) template += ( '}\n' @@ -278,11 +279,7 @@ class Client: 'service_uppercase' : self.service.upper(), 'service_camelcase' : string.capwords(self.service) } - for message in message_list.list: - - if message.type == 'Indication': - continue - + for message in message_list.request_list: if message.static: continue @@ -375,6 +372,8 @@ class Client: if message.abort: template += ( '\n' + '#if defined HAVE_QMI_MESSAGE_${service_uppercase}_ABORT\n' + '\n' 'static QmiMessage *\n' '__${message_fullname_underscore}_abortable_build_request (\n' ' QmiDevice *self,\n' @@ -415,7 +414,10 @@ class Client: ' abort_response,\n' ' error);\n' ' return !!output;\n' - '}\n') + '}\n' + '\n' + '#endif /* HAVE_QMI_MESSAGE_${service_uppercase}_ABORT */\n' + '\n') template += ( '\n' @@ -530,10 +532,17 @@ class Client: if message.abort: template += ( + '#if defined HAVE_QMI_MESSAGE_${service_uppercase}_ABORT\n' ' (QmiDeviceCommandAbortableBuildRequestFn) __${message_fullname_underscore}_abortable_build_request,\n' ' (QmiDeviceCommandAbortableParseResponseFn) __${message_fullname_underscore}_abortable_parse_response,\n' ' g_object_ref (self),\n' - ' g_object_unref,\n') + ' g_object_unref,\n' + '#else\n' + ' NULL,\n' + ' NULL,\n' + ' NULL,\n' + ' NULL,\n' + '#endif\n') template += ( ' cancellable,\n' @@ -550,6 +559,13 @@ class Client: Emit the service-specific client implementation """ def emit(self, hfile, cfile, message_list): + # Do nothing if no supported messages + if len(message_list.indication_list) == 0 and len(message_list.request_list) == 0: + self.__emit_supported(hfile, False) + return + + self.__emit_supported(hfile, True) + # First, emit common class code utils.add_separator(hfile, 'CLIENT', self.name); utils.add_separator(cfile, 'CLIENT', self.name); @@ -560,7 +576,11 @@ class Client: """ Emit the sections """ - def emit_sections(self, sfile): + def emit_sections(self, sfile, message_list): + # Do nothing if no supported messages + if len(message_list.indication_list) == 0 and len(message_list.request_list) == 0: + return + translations = { 'underscore' : utils.build_underscore_name(self.name), 'no_prefix_underscore_upper' : utils.build_underscore_name(self.name[4:]).upper(), 'camelcase' : utils.build_camelcase_name (self.name), diff --git a/build-aux/qmi-codegen/Message.py b/build-aux/qmi-codegen/Message.py index 792bf9b6..e4c93cee 100644 --- a/build-aux/qmi-codegen/Message.py +++ b/build-aux/qmi-codegen/Message.py @@ -68,6 +68,9 @@ class Message: # Create the ID enumeration name self.id_enum_name = utils.build_underscore_name(self.fullname).upper() + # Create the build symbol name + self.build_symbol = 'HAVE_' + self.id_enum_name + # Build output container. # Every defined message will have its own output container, which # will generate a new Output type and public getters for each output @@ -419,6 +422,7 @@ class Message: 'camelcase' : utils.build_camelcase_name (self.fullname), 'service' : utils.build_underscore_name (self.service), 'name_underscore' : utils.build_underscore_name (self.name), + 'build_symbol' : self.build_symbol, 'fullname' : self.service + ' ' + self.name, 'type' : 'response' if self.type == 'Message' else 'indication' } @@ -453,6 +457,7 @@ class Message: '${public_types}' '${public_methods}' '<SUBSECTION Private>\n' + '${build_symbol}\n' '${private}' '<SUBSECTION Standard>\n' '${standard}' diff --git a/build-aux/qmi-codegen/MessageList.py b/build-aux/qmi-codegen/MessageList.py index 632b2880..81f480b9 100644 --- a/build-aux/qmi-codegen/MessageList.py +++ b/build-aux/qmi-codegen/MessageList.py @@ -32,8 +32,10 @@ class MessageList: """ Constructor """ - def __init__(self, objects_dictionary, common_objects_dictionary): - self.list = [] + def __init__(self, collection, objects_dictionary, common_objects_dictionary): + self.request_list = [] + self.indication_list = [] + self.unsupported_list = [] self.message_id_enum_name = None self.indication_id_enum_name = None self.service = None @@ -44,7 +46,13 @@ class MessageList: if object_dictionary['type'] == 'Message' or \ object_dictionary['type'] == 'Indication': message = Message(object_dictionary, common_objects_dictionary) - self.list.append(message) + if collection is None or message.id_enum_name in collection: + if message.type == 'Message': + self.request_list.append(message) + else: + self.indication_list.append(message) + else: + self.unsupported_list.append(message) elif object_dictionary['type'] == 'Message-ID-Enum': self.message_id_enum_name = object_dictionary['name'] elif object_dictionary['type'] == 'Indication-ID-Enum': @@ -61,26 +69,48 @@ class MessageList: raise ValueError('Missing Service field') + def __emit_message_build_symbols(self, f): + template = '' + for message in self.request_list: + translations = { 'build_symbol' : message.build_symbol } + message_template = '#define ${build_symbol}\n' + template += string.Template(message_template).substitute(translations) + for message in self.indication_list: + translations = { 'build_symbol' : message.build_symbol } + message_template = '#define ${build_symbol}\n' + template += string.Template(message_template).substitute(translations) + if len(self.unsupported_list) > 0: + template += ( + '\n' + '/* messages unsupported in collection */\n') + for message in self.unsupported_list: + translations = { 'build_symbol' : message.build_symbol } + message_template = '/* ${build_symbol} */\n' + template += string.Template(message_template).substitute(translations) + f.write(string.Template(template).substitute(translations)) + """ Emit the enumeration of the messages found in the specific service """ - def emit_message_ids_enum(self, f): + def __emit_message_ids_enum(self, f): + # do nothing if nothing in the supported messages list + if len(self.request_list) == 0: + return translations = { 'enum_type' : utils.build_camelcase_name (self.message_id_enum_name) } template = ( '\n' 'typedef enum {\n') - for message in self.list: - if message.type == 'Message': - translations['enum_name'] = message.id_enum_name - translations['enum_value'] = message.id - if message.vendor is None: - enum_template = ( - ' ${enum_name} = ${enum_value},\n') - else: - translations['vendor'] = message.vendor - enum_template = ( - ' ${enum_name} = ${enum_value}, /* vendor ${vendor} */\n') - template += string.Template(enum_template).substitute(translations) + for message in self.request_list: + translations['enum_name'] = message.id_enum_name + translations['enum_value'] = message.id + if message.vendor is None: + enum_template = ( + ' ${enum_name} = ${enum_value},\n') + else: + translations['vendor'] = message.vendor + enum_template = ( + ' ${enum_name} = ${enum_value}, /* vendor ${vendor} */\n') + template += string.Template(enum_template).substitute(translations) template += ( '} ${enum_type};\n' @@ -90,18 +120,20 @@ class MessageList: """ Emit the enumeration of the indications found in the specific service """ - def emit_indication_ids_enum(self, f): + def __emit_indication_ids_enum(self, f): + # do nothing if nothing in the supported indications list + if len(self.indication_list) == 0: + return translations = { 'enum_type' : utils.build_camelcase_name (self.indication_id_enum_name) } template = ( '\n' 'typedef enum {\n') - for message in self.list: - if message.type == 'Indication': - translations['enum_name'] = message.id_enum_name - translations['enum_value'] = message.id - enum_template = ( - ' ${enum_name} = ${enum_value},\n') - template += string.Template(enum_template).substitute(translations) + for message in self.indication_list: + translations['enum_name'] = message.id_enum_name + translations['enum_value'] = message.id + enum_template = ( + ' ${enum_name} = ${enum_value},\n') + template += string.Template(enum_template).substitute(translations) template += ( '} ${enum_type};\n' @@ -141,14 +173,13 @@ class MessageList: ' if (qmi_message_is_indication (self)) {\n' ' switch (qmi_message_get_message_id (self)) {\n') - for message in self.list: - if message.type == 'Indication': - translations['enum_name'] = message.id_enum_name - translations['message_underscore'] = utils.build_underscore_name (message.name) - inner_template = ( - ' case ${enum_name}:\n' - ' return indication_${message_underscore}_get_printable (self, line_prefix);\n') - template += string.Template(inner_template).substitute(translations) + for message in self.indication_list: + translations['enum_name'] = message.id_enum_name + translations['message_underscore'] = utils.build_underscore_name (message.name) + inner_template = ( + ' case ${enum_name}:\n' + ' return indication_${message_underscore}_get_printable (self, line_prefix);\n') + template += string.Template(inner_template).substitute(translations) template += ( ' default:\n' @@ -161,8 +192,8 @@ class MessageList: ' if (vendor_id == QMI_MESSAGE_VENDOR_GENERIC) {\n' ' switch (qmi_message_get_message_id (self)) {\n') - for message in self.list: - if message.type == 'Message' and message.vendor is None: + for message in self.request_list: + if message.vendor is None: translations['enum_name'] = message.id_enum_name translations['message_underscore'] = utils.build_underscore_name (message.name) inner_template = ( @@ -176,8 +207,8 @@ class MessageList: ' }\n' ' } else {\n') - for message in self.list: - if message.type == 'Message' and message.vendor is not None: + for message in self.request_list: + if message.vendor is not None: translations['enum_name'] = message.id_enum_name translations['message_underscore'] = utils.build_underscore_name (message.name) translations['message_vendor'] = message.vendor @@ -198,10 +229,9 @@ class MessageList: Emit the method responsible for checking whether a given message is abortable """ def __emit_is_abortable(self, hfile, cfile): - # do nothing if no abortable messages in service - for message in self.list: - if message.type == 'Message' and message.abort: + for message in self.request_list: + if message.abort: break else: return @@ -234,15 +264,13 @@ class MessageList: ' if (vendor_id == QMI_MESSAGE_VENDOR_GENERIC) {\n' ' switch (qmi_message_get_message_id (self)) {\n') - for message in self.list: - if message.type == 'Message' and message.vendor is None: - # Only add if it's abortable - if message.abort: - translations['enum_name'] = message.id_enum_name - inner_template = ( - ' case ${enum_name}:\n' - ' return TRUE;\n') - template += string.Template(inner_template).substitute(translations) + for message in self.request_list: + if message.vendor is None and message.abort: + translations['enum_name'] = message.id_enum_name + inner_template = ( + ' case ${enum_name}:\n' + ' return TRUE;\n') + template += string.Template(inner_template).substitute(translations) template += ( ' default:\n' @@ -250,17 +278,15 @@ class MessageList: ' }\n' ' } else {\n') - for message in self.list: - if message.type == 'Message' and message.vendor is not None: - # Only add if it's abortable - if message.abort: - translations['enum_name'] = message.id_enum_name - translations['message_vendor'] = message.vendor - inner_template = ( - ' if (vendor_id == ${message_vendor} && (qmi_message_get_message_id (self) == ${enum_name})) {\n' - ' return TRUE;\n' - ' }\n') - template += string.Template(inner_template).substitute(translations) + for message in self.request_list: + if message.vendor is not None and message.abort: + translations['enum_name'] = message.id_enum_name + translations['message_vendor'] = message.vendor + inner_template = ( + ' if (vendor_id == ${message_vendor} && (qmi_message_get_message_id (self) == ${enum_name})) {\n' + ' return TRUE;\n' + ' }\n') + template += string.Template(inner_template).substitute(translations) template += ( ' return FALSE;\n' @@ -273,13 +299,22 @@ class MessageList: Emit the message list handling implementation """ def emit(self, hfile, cfile): - # First, emit the message/indication IDs enum - self.emit_message_ids_enum(cfile) + # Always write build symbols, even for unsupported messages + self.__emit_message_build_symbols(hfile) + + # Do nothing else if nothing in the supported lists + if len(self.indication_list) == 0 and len(self.request_list) == 0: + return + + # Emit the message/indication IDs enum and the build symbols + self.__emit_message_ids_enum(cfile) if self.indication_id_enum_name is not None: - self.emit_indication_ids_enum(cfile) + self.__emit_indication_ids_enum(cfile) # Then, emit all message handlers - for message in self.list: + for message in self.indication_list: + message.emit(hfile, cfile) + for message in self.request_list: message.emit(hfile, cfile) # First, emit common class code @@ -292,6 +327,11 @@ class MessageList: Emit the sections """ def emit_sections(self, sfile): + # do nothing if nothing in the supported lists + if len(self.indication_list) == 0 and len(self.request_list) == 0: + return # Emit all message sections - for message in self.list: + for message in self.indication_list: + message.emit_sections(sfile) + for message in self.request_list: message.emit_sections(sfile) diff --git a/build-aux/qmi-codegen/qmi-codegen b/build-aux/qmi-codegen/qmi-codegen index 91c7db81..8de61e2f 100755 --- a/build-aux/qmi-codegen/qmi-codegen +++ b/build-aux/qmi-codegen/qmi-codegen @@ -37,6 +37,8 @@ def codegen_main(): help='Generate C code in OUTFILES.[ch]') arg_parser.add_option('', '--include', metavar='JSONFILE', action='append', help='Additional common types in a JSON-formatted database') + arg_parser.add_option('', '--collection', metavar='[JSONFILE]', + help='Collection of messages to be included in the build') (opts, args) = arg_parser.parse_args(); if opts.input == None: @@ -51,6 +53,12 @@ def codegen_main(): output_file_h = open(opts.output + ".h", 'w') output_file_sections = open(opts.output + ".sections", 'w') + # If a collection given, load it + collection_list_json = None + if opts.collection != None: + collection_contents = utils.read_json_file(opts.collection) + collection_list_json = json.loads(collection_contents) + # Load all common types common_object_list_json = [] opts.include.append(opts.input) @@ -66,7 +74,7 @@ def codegen_main(): # Build message list object_list_json = json.loads(database_file_contents) - message_list = MessageList(object_list_json, common_object_list_json) + message_list = MessageList(collection_list_json, object_list_json, common_object_list_json) # Add common stuff to the output files utils.add_copyright(output_file_c); @@ -82,7 +90,7 @@ def codegen_main(): client.emit(output_file_h, output_file_c, message_list) # Emit sections - client.emit_sections(output_file_sections) + client.emit_sections(output_file_sections, message_list) message_list.emit_sections(output_file_sections) utils.add_header_stop(output_file_h, os.path.basename(opts.output)) |