Brian Daniels / mbed-tools

Fork of mbed-tools by Morpheus

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uvision4.py Source File

uvision4.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2013 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 from os.path import basename, join, dirname
00018 from project_generator_definitions.definitions import ProGenDef
00019 
00020 from tools.export.exporters import Exporter
00021 from tools.targets import TARGET_MAP, TARGET_NAMES
00022 
00023 # If you wish to add a new target, add it to project_generator_definitions, and then
00024 # define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
00025 # There are 2 default mbed templates (predefined settings) uvision.uvproj and uvproj_microlib.uvproj.tmpl
00026 class Uvision4 (Exporter):
00027     """
00028     Exporter class for uvision. This class uses project generator.
00029     """
00030     # These 2 are currently for exporters backward compatiblity
00031     NAME = 'uVision4'
00032     TOOLCHAIN = 'ARM'
00033     # PROGEN_ACTIVE contains information for exporter scripts that this is using progen
00034     PROGEN_ACTIVE = True
00035 
00036     # backward compatibility with our scripts
00037     TARGETS = []
00038     for target in TARGET_NAMES:
00039         try:
00040             if (ProGenDef('uvision').is_supported(str(TARGET_MAP[target])) or
00041                 ProGenDef('uvision').is_supported(TARGET_MAP[target].progen['target'])):
00042                 TARGETS.append(target)
00043         except AttributeError:
00044             # target is not supported yet
00045             continue
00046 
00047 
00048     def generate (self):
00049         """ Generates the project files """
00050         project_data = self.progen_get_project_data()
00051         tool_specific = {}
00052         # Expand tool specific settings by uvision specific settings which are required
00053         try:
00054             if TARGET_MAP[self.target].progen['uvision']['template']:
00055                 tool_specific['uvision'] = TARGET_MAP[self.target].progen['uvision']
00056         except KeyError:
00057             # use default template
00058             # by the mbed projects
00059             tool_specific['uvision'] = {
00060                     'template': [join(dirname(__file__),  'uvision.uvproj.tmpl')],
00061             }
00062 
00063         project_data['tool_specific'] = {}
00064         project_data['tool_specific'].update(tool_specific)
00065         i = 0
00066         for macro in project_data['common']['macros']:
00067             # armasm does not like floating numbers in macros, timestamp to int
00068             if macro.startswith('MBED_BUILD_TIMESTAMP'):
00069                 timestamp = macro[len('MBED_BUILD_TIMESTAMP='):]
00070                 project_data['common']['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp)))
00071             # armasm does not even accept MACRO=string
00072             if macro.startswith('MBED_USERNAME'):
00073                 project_data['common']['macros'].pop(i)
00074             i += 1
00075         project_data['common']['macros'].append('__ASSERT_MSG')
00076         self.progen_gen_file('uvision', project_data)
00077