Clone of official tools
export/uvision5.py@13:ab47a20b66f0, 2016-07-14 (annotated)
- Committer:
- screamer
- Date:
- Thu Jul 14 20:21:19 2016 +0100
- Revision:
- 13:ab47a20b66f0
- Child:
- 20:835f6355470d
Apply latest tools
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 13:ab47a20b66f0 | 1 | """ |
screamer | 13:ab47a20b66f0 | 2 | mbed SDK |
screamer | 13:ab47a20b66f0 | 3 | Copyright (c) 2016 ARM Limited |
screamer | 13:ab47a20b66f0 | 4 | |
screamer | 13:ab47a20b66f0 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
screamer | 13:ab47a20b66f0 | 6 | you may not use this file except in compliance with the License. |
screamer | 13:ab47a20b66f0 | 7 | You may obtain a copy of the License at |
screamer | 13:ab47a20b66f0 | 8 | |
screamer | 13:ab47a20b66f0 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
screamer | 13:ab47a20b66f0 | 10 | |
screamer | 13:ab47a20b66f0 | 11 | Unless required by applicable law or agreed to in writing, software |
screamer | 13:ab47a20b66f0 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
screamer | 13:ab47a20b66f0 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
screamer | 13:ab47a20b66f0 | 14 | See the License for the specific language governing permissions and |
screamer | 13:ab47a20b66f0 | 15 | limitations under the License. |
screamer | 13:ab47a20b66f0 | 16 | """ |
screamer | 13:ab47a20b66f0 | 17 | from os.path import basename, join, dirname |
screamer | 13:ab47a20b66f0 | 18 | from project_generator_definitions.definitions import ProGenDef |
screamer | 13:ab47a20b66f0 | 19 | |
screamer | 13:ab47a20b66f0 | 20 | from tools.export.exporters import Exporter |
screamer | 13:ab47a20b66f0 | 21 | from tools.targets import TARGET_MAP, TARGET_NAMES |
screamer | 13:ab47a20b66f0 | 22 | from tools.settings import ARM_INC |
screamer | 13:ab47a20b66f0 | 23 | |
screamer | 13:ab47a20b66f0 | 24 | # If you wish to add a new target, add it to project_generator_definitions, and then |
screamer | 13:ab47a20b66f0 | 25 | # define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``) |
screamer | 13:ab47a20b66f0 | 26 | # There are 2 default mbed templates (predefined settings) uvision.uvproj and uvproj_microlib.uvproj.tmpl |
screamer | 13:ab47a20b66f0 | 27 | class Uvision5(Exporter): |
screamer | 13:ab47a20b66f0 | 28 | """ |
screamer | 13:ab47a20b66f0 | 29 | Exporter class for uvision5. This class uses project generator. |
screamer | 13:ab47a20b66f0 | 30 | """ |
screamer | 13:ab47a20b66f0 | 31 | # These 2 are currently for exporters backward compatiblity |
screamer | 13:ab47a20b66f0 | 32 | NAME = 'uVision5' |
screamer | 13:ab47a20b66f0 | 33 | TOOLCHAIN = 'ARM' |
screamer | 13:ab47a20b66f0 | 34 | # PROGEN_ACTIVE contains information for exporter scripts that this is using progen |
screamer | 13:ab47a20b66f0 | 35 | PROGEN_ACTIVE = True |
screamer | 13:ab47a20b66f0 | 36 | |
screamer | 13:ab47a20b66f0 | 37 | MBED_CONFIG_HEADER_SUPPORTED = True |
screamer | 13:ab47a20b66f0 | 38 | |
screamer | 13:ab47a20b66f0 | 39 | # backward compatibility with our scripts |
screamer | 13:ab47a20b66f0 | 40 | TARGETS = [] |
screamer | 13:ab47a20b66f0 | 41 | for target in TARGET_NAMES: |
screamer | 13:ab47a20b66f0 | 42 | try: |
screamer | 13:ab47a20b66f0 | 43 | if (ProGenDef('uvision5').is_supported(str(TARGET_MAP[target])) or |
screamer | 13:ab47a20b66f0 | 44 | ProGenDef('uvision5').is_supported(TARGET_MAP[target].progen['target'])): |
screamer | 13:ab47a20b66f0 | 45 | TARGETS.append(target) |
screamer | 13:ab47a20b66f0 | 46 | except AttributeError: |
screamer | 13:ab47a20b66f0 | 47 | # target is not supported yet |
screamer | 13:ab47a20b66f0 | 48 | continue |
screamer | 13:ab47a20b66f0 | 49 | |
screamer | 13:ab47a20b66f0 | 50 | def get_toolchain(self): |
screamer | 13:ab47a20b66f0 | 51 | return TARGET_MAP[self.target].default_toolchain |
screamer | 13:ab47a20b66f0 | 52 | |
screamer | 13:ab47a20b66f0 | 53 | def generate(self): |
screamer | 13:ab47a20b66f0 | 54 | """ Generates the project files """ |
screamer | 13:ab47a20b66f0 | 55 | project_data = self.progen_get_project_data() |
screamer | 13:ab47a20b66f0 | 56 | tool_specific = {} |
screamer | 13:ab47a20b66f0 | 57 | # Expand tool specific settings by uvision specific settings which are required |
screamer | 13:ab47a20b66f0 | 58 | try: |
screamer | 13:ab47a20b66f0 | 59 | if TARGET_MAP[self.target].progen['uvision5']['template']: |
screamer | 13:ab47a20b66f0 | 60 | tool_specific['uvision5'] = TARGET_MAP[self.target].progen['uvision5'] |
screamer | 13:ab47a20b66f0 | 61 | except KeyError: |
screamer | 13:ab47a20b66f0 | 62 | # use default template |
screamer | 13:ab47a20b66f0 | 63 | # by the mbed projects |
screamer | 13:ab47a20b66f0 | 64 | tool_specific['uvision5'] = { |
screamer | 13:ab47a20b66f0 | 65 | 'template': [join(dirname(__file__), 'uvision.uvproj.tmpl')], |
screamer | 13:ab47a20b66f0 | 66 | } |
screamer | 13:ab47a20b66f0 | 67 | |
screamer | 13:ab47a20b66f0 | 68 | project_data['tool_specific'] = {} |
screamer | 13:ab47a20b66f0 | 69 | project_data['tool_specific'].update(tool_specific) |
screamer | 13:ab47a20b66f0 | 70 | |
screamer | 13:ab47a20b66f0 | 71 | # get flags from toolchain and apply |
screamer | 13:ab47a20b66f0 | 72 | project_data['tool_specific']['uvision5']['misc'] = {} |
screamer | 13:ab47a20b66f0 | 73 | # asm flags only, common are not valid within uvision project, they are armcc specific |
screamer | 13:ab47a20b66f0 | 74 | project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags'])) |
screamer | 13:ab47a20b66f0 | 75 | # cxx flags included, as uvision have them all in one tab |
screamer | 13:ab47a20b66f0 | 76 | project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags'])) |
screamer | 13:ab47a20b66f0 | 77 | # ARM_INC is by default as system inclusion, not required for exported project |
screamer | 13:ab47a20b66f0 | 78 | project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"") |
screamer | 13:ab47a20b66f0 | 79 | # not compatible with c99 flag set in the template |
screamer | 13:ab47a20b66f0 | 80 | project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--c99") |
screamer | 13:ab47a20b66f0 | 81 | # cpp is not required as it's implicit for cpp files |
screamer | 13:ab47a20b66f0 | 82 | project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--cpp") |
screamer | 13:ab47a20b66f0 | 83 | # we want no-vla for only cxx, but it's also applied for C in IDE, thus we remove it |
screamer | 13:ab47a20b66f0 | 84 | project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--no_vla") |
screamer | 13:ab47a20b66f0 | 85 | project_data['tool_specific']['uvision5']['misc']['ld_flags'] = self.progen_flags['ld_flags'] |
screamer | 13:ab47a20b66f0 | 86 | |
screamer | 13:ab47a20b66f0 | 87 | i = 0 |
screamer | 13:ab47a20b66f0 | 88 | for macro in project_data['common']['macros']: |
screamer | 13:ab47a20b66f0 | 89 | # armasm does not like floating numbers in macros, timestamp to int |
screamer | 13:ab47a20b66f0 | 90 | if macro.startswith('MBED_BUILD_TIMESTAMP'): |
screamer | 13:ab47a20b66f0 | 91 | timestamp = macro[len('MBED_BUILD_TIMESTAMP='):] |
screamer | 13:ab47a20b66f0 | 92 | project_data['common']['macros'][i] = 'MBED_BUILD_TIMESTAMP=' + str(int(float(timestamp))) |
screamer | 13:ab47a20b66f0 | 93 | # armasm does not even accept MACRO=string |
screamer | 13:ab47a20b66f0 | 94 | if macro.startswith('MBED_USERNAME'): |
screamer | 13:ab47a20b66f0 | 95 | project_data['common']['macros'].pop(i) |
screamer | 13:ab47a20b66f0 | 96 | i += 1 |
screamer | 13:ab47a20b66f0 | 97 | project_data['common']['macros'].append('__ASSERT_MSG') |
screamer | 13:ab47a20b66f0 | 98 | project_data['common']['build_dir'] = project_data['common']['build_dir'] + '\\' + 'uvision5' |
screamer | 13:ab47a20b66f0 | 99 | self.progen_gen_file('uvision5', project_data) |