mbed-os/tools/export/uvision4.py

104 lines
4.6 KiB
Python
Raw Normal View History

2013-08-06 13:38:00 +00:00
"""
mbed SDK
2016-07-26 20:30:59 +00:00
Copyright (c) 2011-2016 ARM Limited
2013-08-06 13:38:00 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
2016-03-10 15:58:41 +00:00
from os.path import basename, join, dirname
from project_generator_definitions.definitions import ProGenDef
from tools.export.exporters import Exporter, ExporterTargetsProperty
from tools.targets import TARGET_MAP, TARGET_NAMES
2016-03-10 18:57:27 +00:00
# If you wish to add a new target, add it to project_generator_definitions, and then
# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
# There are 2 default mbed templates (predefined settings) uvision.uvproj and uvproj_microlib.uvproj.tmpl
class Uvision4(Exporter):
2016-03-10 15:58:41 +00:00
"""
2016-03-10 18:57:27 +00:00
Exporter class for uvision. This class uses project generator.
2016-03-10 15:58:41 +00:00
"""
# These 2 are currently for exporters backward compatiblity
NAME = 'uvision'
2016-03-10 15:58:41 +00:00
TOOLCHAIN = 'ARM'
# PROGEN_ACTIVE contains information for exporter scripts that this is using progen
PROGEN_ACTIVE = True
MBED_CONFIG_HEADER_SUPPORTED = True
@ExporterTargetsProperty
def TARGETS(cls):
if not hasattr(cls, "_targets_supported"):
cls._targets_supported = []
progendef = ProGenDef('uvision')
Exporters - progen TARGETS lazy evaluated To speed up project.py, use @property for TARGETS. When exporters are used, it would ask progen for all targets support (number of tools x number of targets), this takes a lot of time, thus lazily evaluated, and TARGETS are for backaward compatibility, not currently used by project.py but by other scripts to check if a target is supported. Profiling: ``` python tools\project.py -m K64F -i uvision -n MBED_10 -b Before the change: 1 0.000 0.000 0.010 0.010 definitions.py:113(get_tool_definition) 824 0.004 0.000 2.990 0.004 definitions.py:124(is_supported) 1 0.000 0.000 0.000 0.000 definitions.py:145(get_debugger) 1 0.002 0.002 0.044 0.044 definitions.py:15(<module>) 384 0.002 0.000 2.986 0.008 definitions.py:26(_load_record) 1 0.000 0.000 0.000 0.000 definitions.py:32(ProGenMcus) 992 0.055 0.000 1.959 0.002 definitions.py:34(__init__) 1376 0.002 0.000 0.003 0.000 definitions.py:40(get_mcus) 384 0.001 0.000 1.070 0.003 definitions.py:43(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:50(ProGenTargets) 992 0.000 0.000 0.000 0.000 definitions.py:52(__init__) 1196 0.002 0.000 0.004 0.000 definitions.py:55(get_targets) 204 0.001 0.000 1.922 0.009 definitions.py:58(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:67(get_debugger) 1 0.000 0.000 0.000 0.000 definitions.py:74(ProGenDef) 992 0.008 0.000 1.973 0.002 definitions.py:83(__init__) Days : 0 Hours : 0 Minutes : 0 Seconds : 4 Milliseconds : 723 Ticks : 47237302 TotalDays : 5.46728032407407E-05 TotalHours : 0.00131214727777778 TotalMinutes : 0.0787288366666667 TotalSeconds : 4.7237302 TotalMilliseconds : 4723.7302 After the change: 1 0.000 0.000 0.010 0.010 definitions.py:113(get_tool_definition) 2 0.000 0.000 0.025 0.012 definitions.py:124(is_supported) 1 0.000 0.000 0.000 0.000 definitions.py:145(get_debugger) 1 0.002 0.002 0.042 0.042 definitions.py:15(<module>) 3 0.000 0.000 0.035 0.012 definitions.py:26(_load_record) 1 0.000 0.000 0.000 0.000 definitions.py:32(ProGenMcus) 2 0.000 0.000 0.005 0.002 definitions.py:34(__init__) 5 0.000 0.000 0.000 0.000 definitions.py:40(get_mcus) 3 0.000 0.000 0.000 0.000 definitions.py:43(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:50(ProGenTargets) 2 0.000 0.000 0.000 0.000 definitions.py:52(__init__) 5 0.000 0.000 0.000 0.000 definitions.py:55(get_targets) 3 0.000 0.000 0.035 0.012 definitions.py:58(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:67(get_debugger) 1 0.000 0.000 0.000 0.000 definitions.py:74(ProGenDef) 2 0.000 0.000 0.005 0.003 definitions.py:83(__init__) Days : 0 Hours : 0 Minutes : 0 Seconds : 1 Milliseconds : 178 Ticks : 11780618 TotalDays : 1.3634974537037E-05 TotalHours : 0.000327239388888889 TotalMinutes : 0.0196343633333333 TotalSeconds : 1.1780618 TotalMilliseconds : 1178.0618 ```
2016-07-15 12:37:50 +00:00
for target in TARGET_NAMES:
try:
if (progendef.is_supported(str(TARGET_MAP[target])) or
progendef.is_supported(TARGET_MAP[target].progen['target'])):
cls._targets_supported.append(target)
Exporters - progen TARGETS lazy evaluated To speed up project.py, use @property for TARGETS. When exporters are used, it would ask progen for all targets support (number of tools x number of targets), this takes a lot of time, thus lazily evaluated, and TARGETS are for backaward compatibility, not currently used by project.py but by other scripts to check if a target is supported. Profiling: ``` python tools\project.py -m K64F -i uvision -n MBED_10 -b Before the change: 1 0.000 0.000 0.010 0.010 definitions.py:113(get_tool_definition) 824 0.004 0.000 2.990 0.004 definitions.py:124(is_supported) 1 0.000 0.000 0.000 0.000 definitions.py:145(get_debugger) 1 0.002 0.002 0.044 0.044 definitions.py:15(<module>) 384 0.002 0.000 2.986 0.008 definitions.py:26(_load_record) 1 0.000 0.000 0.000 0.000 definitions.py:32(ProGenMcus) 992 0.055 0.000 1.959 0.002 definitions.py:34(__init__) 1376 0.002 0.000 0.003 0.000 definitions.py:40(get_mcus) 384 0.001 0.000 1.070 0.003 definitions.py:43(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:50(ProGenTargets) 992 0.000 0.000 0.000 0.000 definitions.py:52(__init__) 1196 0.002 0.000 0.004 0.000 definitions.py:55(get_targets) 204 0.001 0.000 1.922 0.009 definitions.py:58(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:67(get_debugger) 1 0.000 0.000 0.000 0.000 definitions.py:74(ProGenDef) 992 0.008 0.000 1.973 0.002 definitions.py:83(__init__) Days : 0 Hours : 0 Minutes : 0 Seconds : 4 Milliseconds : 723 Ticks : 47237302 TotalDays : 5.46728032407407E-05 TotalHours : 0.00131214727777778 TotalMinutes : 0.0787288366666667 TotalSeconds : 4.7237302 TotalMilliseconds : 4723.7302 After the change: 1 0.000 0.000 0.010 0.010 definitions.py:113(get_tool_definition) 2 0.000 0.000 0.025 0.012 definitions.py:124(is_supported) 1 0.000 0.000 0.000 0.000 definitions.py:145(get_debugger) 1 0.002 0.002 0.042 0.042 definitions.py:15(<module>) 3 0.000 0.000 0.035 0.012 definitions.py:26(_load_record) 1 0.000 0.000 0.000 0.000 definitions.py:32(ProGenMcus) 2 0.000 0.000 0.005 0.002 definitions.py:34(__init__) 5 0.000 0.000 0.000 0.000 definitions.py:40(get_mcus) 3 0.000 0.000 0.000 0.000 definitions.py:43(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:50(ProGenTargets) 2 0.000 0.000 0.000 0.000 definitions.py:52(__init__) 5 0.000 0.000 0.000 0.000 definitions.py:55(get_targets) 3 0.000 0.000 0.035 0.012 definitions.py:58(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:67(get_debugger) 1 0.000 0.000 0.000 0.000 definitions.py:74(ProGenDef) 2 0.000 0.000 0.005 0.003 definitions.py:83(__init__) Days : 0 Hours : 0 Minutes : 0 Seconds : 1 Milliseconds : 178 Ticks : 11780618 TotalDays : 1.3634974537037E-05 TotalHours : 0.000327239388888889 TotalMinutes : 0.0196343633333333 TotalSeconds : 1.1780618 TotalMilliseconds : 1178.0618 ```
2016-07-15 12:37:50 +00:00
except AttributeError:
# target is not supported yet
continue
return cls._targets_supported
def get_toolchain(self):
return TARGET_MAP[self.target].default_toolchain
def generate(self):
2016-03-10 15:58:41 +00:00
""" Generates the project files """
project_data = self.progen_get_project_data()
tool_specific = {}
2016-03-10 18:57:27 +00:00
# Expand tool specific settings by uvision specific settings which are required
2016-03-10 15:58:41 +00:00
try:
2016-03-10 18:57:27 +00:00
if TARGET_MAP[self.target].progen['uvision']['template']:
tool_specific['uvision'] = TARGET_MAP[self.target].progen['uvision']
2016-03-10 15:58:41 +00:00
except KeyError:
# use default template
# by the mbed projects
tool_specific['uvision'] = {
2016-03-11 07:27:39 +00:00
'template': [join(dirname(__file__), 'uvision.uvproj.tmpl')],
2016-03-10 15:58:41 +00:00
}
2016-03-10 15:58:41 +00:00
project_data['tool_specific'] = {}
project_data['tool_specific'].update(tool_specific)
# get flags from toolchain and apply
project_data['misc'] = {}
# need to make this a string for progen. Only adds preprocessor when "macros" set
asm_flag_string = '--cpreproc --cpreproc_opts=-D__ASSERT_MSG,' + ",".join(
list(set(self.flags['asm_flags'])))
# asm flags only, common are not valid within uvision project, they are armcc specific
project_data['misc']['asm_flags'] = [asm_flag_string]
# cxx flags included, as uvision have them all in one tab
project_data['misc']['c_flags'] = list(set(self.flags['common_flags'] + self.flags['c_flags'] + self.flags['cxx_flags']))
# not compatible with c99 flag set in the template
project_data['misc']['c_flags'].remove("--c99")
# cpp is not required as it's implicit for cpp files
project_data['misc']['c_flags'].remove("--cpp")
# we want no-vla for only cxx, but it's also applied for C in IDE, thus we remove it
project_data['misc']['c_flags'].remove("--no_vla")
project_data['misc']['ld_flags'] = self.flags['ld_flags']
i = 0
for macro in self.symbols:
# armasm does not like floating numbers in macros, timestamp to int
if macro.startswith('MBED_BUILD_TIMESTAMP'):
timestamp = macro[len('MBED_BUILD_TIMESTAMP='):]
project_data['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp)))
# armasm does not even accept MACRO=string
if macro.startswith('MBED_USERNAME'):
project_data['macros'].pop(i)
i += 1
project_data['macros'].append('__ASSERT_MSG')
project_data['build_dir'] = project_data['build_dir'] + '\\' + 'uvision4'
self.progen_gen_file(project_data)