summaryrefslogtreecommitdiff
path: root/tools/InterfaceGenerator
diff options
context:
space:
mode:
authordtrunov <dtrunov@luxoft.com>2015-11-13 15:31:47 +0200
committervveremeva <vveremjova@luxoft.com>2016-04-08 15:55:19 +0300
commit9b5a39e256849f2898459cd8ca1b7dc6a3ee147d (patch)
tree40b729de7c7921f5f096bc6ccd59c93ff2054dce /tools/InterfaceGenerator
parentd4d40322cfb33783d0fb0e8aad10c4a8e3f18a20 (diff)
downloadsdl_core-9b5a39e256849f2898459cd8ca1b7dc6a3ee147d.tar.gz
SDL must retrieve the current version from MOBILE_API
Changed cod generator in order to generate file with actual mobile api version Relates to APPLINK-18839
Diffstat (limited to 'tools/InterfaceGenerator')
-rwxr-xr-xtools/InterfaceGenerator/Generator.py9
-rw-r--r--tools/InterfaceGenerator/MsgVersionGenerate.py85
2 files changed, 93 insertions, 1 deletions
diff --git a/tools/InterfaceGenerator/Generator.py b/tools/InterfaceGenerator/Generator.py
index 5b5894bc00..932620c153 100755
--- a/tools/InterfaceGenerator/Generator.py
+++ b/tools/InterfaceGenerator/Generator.py
@@ -26,6 +26,7 @@ import generator.parsers.SDLRPCV2
import generator.parsers.JSONRPC
import generator.generators.SmartFactorySDLRPC
import generator.generators.SmartFactoryJSONRPC
+import MsgVersionGenerate
from generator.parsers.RPCBase import ParseError
from generator.generators.SmartFactoryBase import GenerateError
@@ -71,7 +72,6 @@ def _handle_fatal_error(error):
print
sys.exit(errno.EINVAL)
-
def main():
"""Main function of the generator that does actual work."""
@@ -101,6 +101,13 @@ Generating interface source code with following parameters:
except ParseError as error:
_handle_fatal_error(error)
+ # Parse sdl version from MOBILE_API.xml and create source file with this version
+ if src_xml_name == "MOBILE_API":
+ try:
+ MsgVersionGenerate.generate_msg_version(src_xml, output_dir)
+ except ParseError as error:
+ _handle_fatal_error(error)
+
# Generate SmartFactory source code from internal model
try:
code_generator.generate(interface,
diff --git a/tools/InterfaceGenerator/MsgVersionGenerate.py b/tools/InterfaceGenerator/MsgVersionGenerate.py
new file mode 100644
index 0000000000..7ff6c384d3
--- /dev/null
+++ b/tools/InterfaceGenerator/MsgVersionGenerate.py
@@ -0,0 +1,85 @@
+"""
+Generate file with major and minor msg_version.
+"""
+import xml.etree.ElementTree
+from string import Template
+import re
+from generator.parsers import RPCBase
+
+def generate_msg_version(file_name, path_to_storage):
+ """Parses MOBILE_API.xml in order to
+ receive major_version and minor_version
+ """
+ tree = xml.etree.ElementTree.parse(file_name)
+ root = tree.getroot()
+ if (root.tag == "interface" and "version" in root.attrib):
+ check_version_format(root.attrib["version"])
+ array = (root.attrib["version"]).split(".")
+ major_version = array[0]
+ minor_version = array[1]
+ if (major_version.isdigit() and minor_version.isdigit()):
+ data_for_storage = prepare_data_for_storage(major_version, minor_version)
+ store_data_to_file(path_to_storage, data_for_storage)
+ else:
+ raise RPCBase.ParseError("Attribute version has incorect value in MOBILE_API.xml")
+ else:
+ raise RPCBase.ParseError("Check MOBILE_API.xml file, parser can not find first element "
+ " with tag interface or atribute version")
+
+def store_data_to_file(path_to_storage, data_for_storage):
+ """Stores data with major and minor version
+ to file generated_msg_version.h
+ """
+ path_to_storage = path_to_storage + "/generated_msg_version.h"
+ fh = open(path_to_storage, 'w')
+ fh.write(data_for_storage)
+ fh.close()
+
+def check_version_format(version):
+ """Checks correctness of format of version
+ """
+ p = re.compile('\d+\\.\d+')
+ result = p.match(version)
+ if result == None or (result.end() != len(version)):
+ raise RPCBase.ParseError("Incorrect format of version please check MOBILE_API.xml. "
+ "Need format of version major_version.minor_version")
+
+def prepare_data_for_storage(major_version, minor_version):
+ """Prepares data to store to file.
+ """
+ temp = Template(
+ u'''/*Copyright (c) 2016, Ford Motor Company\n'''
+ u'''All rights reserved.\n'''
+ u'''Redistribution and use in source and binary forms, with or without\n'''
+ u'''modification, are permitted provided that the following conditions are met:\n'''
+ u'''Redistributions of source code must retain the above copyright notice, this\n'''
+ u'''list of conditions and the following disclaimer.\n'''
+ u'''Redistributions in binary form must reproduce the above copyright notice,\n'''
+ u'''this list of conditions and the following\n'''
+ u'''disclaimer in the documentation and/or other materials provided with the\n'''
+ u'''distribution.\n'''
+ u'''Neither the name of the Ford Motor Company nor the names of its contributors\n'''
+ u'''may be used to endorse or promote products derived from this software\n'''
+ u'''without specific prior written permission.\n'''
+ u'''THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n'''
+ u'''AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n'''
+ u'''IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n'''
+ u'''ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n'''
+ u'''LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n'''
+ u'''CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n'''
+ u'''SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n'''
+ u'''INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n'''
+ u'''CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n'''
+ u'''ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n'''
+ u'''POSSIBILITY OF SUCH DAMAGE.\n'''
+ u'''*/\n'''
+ u'''#ifndef GENERATED_MSG_VERSION_H\n'''
+ u'''#define GENERATED_MSG_VERSION_H\n\n'''
+ u'''namespace application_manager {\n\n'''
+ u'''const uint16_t major_version = $m_version;\n'''
+ u'''const uint16_t minor_version = $min_version;\n'''
+ u'''} // namespace application_manager\n'''
+ u'''#endif // GENERATED_MSG_VERSION_H''')
+ data_to_file = temp.substitute(m_version = major_version, min_version = minor_version)
+ return data_to_file
+