|
| 1 | +""" |
| 2 | +mbed SDK |
| 3 | +Copyright (c) 2016 ARM Limited |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +""" |
| 17 | +from os.path import basename, join, dirname |
| 18 | +from project_generator_definitions.definitions import ProGenDef |
| 19 | + |
| 20 | +from workspace_tools.export.exporters import Exporter |
| 21 | +from workspace_tools.targets import TARGET_MAP, TARGET_NAMES |
| 22 | + |
| 23 | +# If you wish to add a new target, add it to project_generator_definitions, and then |
| 24 | +# define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``) |
| 25 | +# There are 2 default mbed templates (predefined settings) uvision.uvproj and uvproj_microlib.uvproj.tmpl |
| 26 | +class Uvision5(Exporter): |
| 27 | + """ |
| 28 | + Exporter class for uvision5. This class uses project generator. |
| 29 | + """ |
| 30 | + # These 2 are currently for exporters backward compatiblity |
| 31 | + NAME = 'uVision5' |
| 32 | + TOOLCHAIN = 'ARM' |
| 33 | + # PROGEN_ACTIVE contains information for exporter scripts that this is using progen |
| 34 | + PROGEN_ACTIVE = True |
| 35 | + |
| 36 | + # backward compatibility with our scripts |
| 37 | + TARGETS = [] |
| 38 | + for target in TARGET_NAMES: |
| 39 | + try: |
| 40 | + if (ProGenDef('uvision5').is_supported(str(TARGET_MAP[target])) or |
| 41 | + ProGenDef('uvision5').is_supported(TARGET_MAP[target].progen['target'])): |
| 42 | + TARGETS.append(target) |
| 43 | + except AttributeError: |
| 44 | + # target is not supported yet |
| 45 | + continue |
| 46 | + |
| 47 | + |
| 48 | + def generate(self): |
| 49 | + """ Generates the project files """ |
| 50 | + project_data = self.progen_get_project_data() |
| 51 | + tool_specific = {} |
| 52 | + # Expand tool specific settings by uvision specific settings which are required |
| 53 | + try: |
| 54 | + if TARGET_MAP[self.target].progen['uvision5']['template']: |
| 55 | + tool_specific['uvision5'] = TARGET_MAP[self.target].progen['uvision5'] |
| 56 | + except KeyError: |
| 57 | + # use default template |
| 58 | + # by the mbed projects |
| 59 | + tool_specific['uvision5'] = { |
| 60 | + 'template': [join(dirname(__file__), 'uvision.uvproj.tmpl')], |
| 61 | + } |
| 62 | + |
| 63 | + project_data['tool_specific'] = {} |
| 64 | + project_data['tool_specific'].update(tool_specific) |
| 65 | + i = 0 |
| 66 | + for macro in project_data['common']['macros']: |
| 67 | + # armasm does not like floating numbers in macros, timestamp to int |
| 68 | + if macro.startswith('MBED_BUILD_TIMESTAMP'): |
| 69 | + timestamp = macro[len('MBED_BUILD_TIMESTAMP='):] |
| 70 | + project_data['common']['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp))) |
| 71 | + # armasm does not even accept MACRO=string |
| 72 | + if macro.startswith('MBED_USERNAME'): |
| 73 | + project_data['common']['macros'].pop(i) |
| 74 | + i += 1 |
| 75 | + project_data['common']['macros'].append('__ASSERT_MSG') |
| 76 | + self.progen_gen_file('uvision5', project_data) |
| 77 | + |
0 commit comments