Clone of official tools
export/vscode/__init__.py@47:21ae3e5a7128, 2021-02-04 (annotated)
- Committer:
- Anders Blomdell
- Date:
- Thu Feb 04 17:17:13 2021 +0100
- Revision:
- 47:21ae3e5a7128
- Parent:
- 43:2a7da56ebd24
Add a few normpath calls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
The Other Jimmy |
36:96847d42f010 | 1 | # mbed SDK |
The Other Jimmy |
36:96847d42f010 | 2 | # Copyright (c) 2011-2016 ARM Limited |
The Other Jimmy |
36:96847d42f010 | 3 | # |
The Other Jimmy |
36:96847d42f010 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
The Other Jimmy |
36:96847d42f010 | 5 | # you may not use this file except in compliance with the License. |
The Other Jimmy |
36:96847d42f010 | 6 | # You may obtain a copy of the License at |
The Other Jimmy |
36:96847d42f010 | 7 | # |
The Other Jimmy |
36:96847d42f010 | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
The Other Jimmy |
36:96847d42f010 | 9 | # |
The Other Jimmy |
36:96847d42f010 | 10 | # Unless required by applicable law or agreed to in writing, software |
The Other Jimmy |
36:96847d42f010 | 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
The Other Jimmy |
36:96847d42f010 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
The Other Jimmy |
36:96847d42f010 | 13 | # See the License for the specific language governing permissions and |
The Other Jimmy |
36:96847d42f010 | 14 | # limitations under the License. |
theotherjimmy |
43:2a7da56ebd24 | 15 | from __future__ import print_function, absolute_import |
theotherjimmy |
43:2a7da56ebd24 | 16 | from builtins import str |
theotherjimmy |
43:2a7da56ebd24 | 17 | |
The Other Jimmy |
36:96847d42f010 | 18 | |
The Other Jimmy |
36:96847d42f010 | 19 | from os.path import join, exists, realpath, relpath, basename, isfile, splitext |
theotherjimmy |
43:2a7da56ebd24 | 20 | from os import makedirs, listdir, remove, rmdir |
The Other Jimmy |
36:96847d42f010 | 21 | import json |
The Other Jimmy |
36:96847d42f010 | 22 | |
The Other Jimmy |
36:96847d42f010 | 23 | from tools.export.makefile import Makefile, GccArm, Armc5, IAR |
The Other Jimmy |
36:96847d42f010 | 24 | |
The Other Jimmy |
36:96847d42f010 | 25 | class VSCode(Makefile): |
The Other Jimmy |
36:96847d42f010 | 26 | """Generic VSCode project. Intended to be subclassed by classes that |
The Other Jimmy |
36:96847d42f010 | 27 | specify a type of Makefile. |
The Other Jimmy |
36:96847d42f010 | 28 | """ |
The Other Jimmy |
36:96847d42f010 | 29 | def generate(self): |
The Other Jimmy |
36:96847d42f010 | 30 | """Generate Makefile and VSCode launch and task files |
The Other Jimmy |
36:96847d42f010 | 31 | """ |
The Other Jimmy |
36:96847d42f010 | 32 | super(VSCode, self).generate() |
The Other Jimmy |
36:96847d42f010 | 33 | ctx = { |
The Other Jimmy |
36:96847d42f010 | 34 | 'name': self.project_name, |
The Other Jimmy |
36:96847d42f010 | 35 | 'elf_location': join('BUILD', self.project_name)+'.elf', |
The Other Jimmy |
36:96847d42f010 | 36 | 'c_symbols': self.toolchain.get_symbols(), |
The Other Jimmy |
36:96847d42f010 | 37 | 'asm_symbols': self.toolchain.get_symbols(True), |
The Other Jimmy |
36:96847d42f010 | 38 | 'target': self.target, |
The Other Jimmy |
36:96847d42f010 | 39 | 'include_paths': self.resources.inc_dirs, |
The Other Jimmy |
36:96847d42f010 | 40 | 'load_exe': str(self.LOAD_EXE).lower() |
The Other Jimmy |
36:96847d42f010 | 41 | } |
The Other Jimmy |
36:96847d42f010 | 42 | |
The Other Jimmy |
36:96847d42f010 | 43 | if not exists(join(self.export_dir, '.vscode')): |
The Other Jimmy |
36:96847d42f010 | 44 | makedirs(join(self.export_dir, '.vscode')) |
The Other Jimmy |
36:96847d42f010 | 45 | |
theotherjimmy |
43:2a7da56ebd24 | 46 | config_files = ['launch', 'settings', 'tasks'] |
theotherjimmy |
43:2a7da56ebd24 | 47 | for file in config_files: |
theotherjimmy |
43:2a7da56ebd24 | 48 | if not exists('.vscode/%s.json' % file): |
theotherjimmy |
43:2a7da56ebd24 | 49 | self.gen_file('vscode/%s.tmpl' % file, ctx, |
theotherjimmy |
43:2a7da56ebd24 | 50 | '.vscode/%s.json' % file) |
theotherjimmy |
43:2a7da56ebd24 | 51 | else: |
theotherjimmy |
43:2a7da56ebd24 | 52 | print('Keeping existing %s.json' % file) |
The Other Jimmy |
36:96847d42f010 | 53 | |
The Other Jimmy |
36:96847d42f010 | 54 | # So.... I want all .h and .hpp files in self.resources.inc_dirs |
The Other Jimmy |
36:96847d42f010 | 55 | all_directories = [] |
The Other Jimmy |
36:96847d42f010 | 56 | |
The Other Jimmy |
36:96847d42f010 | 57 | for directory in self.resources.inc_dirs: |
The Other Jimmy |
36:96847d42f010 | 58 | if not directory: |
The Other Jimmy |
36:96847d42f010 | 59 | continue |
The Other Jimmy |
36:96847d42f010 | 60 | |
The Other Jimmy |
36:96847d42f010 | 61 | if directory == ".": |
The Other Jimmy |
36:96847d42f010 | 62 | all_directories.append("${workspaceRoot}/*") |
The Other Jimmy |
36:96847d42f010 | 63 | else: |
The Other Jimmy |
36:96847d42f010 | 64 | all_directories.append(directory.replace("./", "${workspaceRoot}/") + "/*") |
The Other Jimmy |
36:96847d42f010 | 65 | |
The Other Jimmy |
36:96847d42f010 | 66 | cpp_props = { |
The Other Jimmy |
36:96847d42f010 | 67 | "configurations": [ |
The Other Jimmy |
36:96847d42f010 | 68 | { |
The Other Jimmy |
36:96847d42f010 | 69 | "name": "Windows", |
theotherjimmy |
40:7d3fa6b99b2b | 70 | "includePath": [x.replace("/", "\\") for x in all_directories], |
theotherjimmy |
40:7d3fa6b99b2b | 71 | "defines": [symbol for symbol in self.toolchain.get_symbols()] |
The Other Jimmy |
36:96847d42f010 | 72 | }, |
The Other Jimmy |
36:96847d42f010 | 73 | { |
The Other Jimmy |
36:96847d42f010 | 74 | "name": "Mac", |
theotherjimmy |
40:7d3fa6b99b2b | 75 | "includePath": all_directories, |
theotherjimmy |
40:7d3fa6b99b2b | 76 | "defines": [symbol for symbol in self.toolchain.get_symbols()] |
The Other Jimmy |
36:96847d42f010 | 77 | }, |
The Other Jimmy |
36:96847d42f010 | 78 | { |
The Other Jimmy |
36:96847d42f010 | 79 | "name": "Linux", |
theotherjimmy |
40:7d3fa6b99b2b | 80 | "includePath": all_directories, |
theotherjimmy |
40:7d3fa6b99b2b | 81 | "defines": [symbol for symbol in self.toolchain.get_symbols()] |
The Other Jimmy |
36:96847d42f010 | 82 | } |
The Other Jimmy |
36:96847d42f010 | 83 | ] |
The Other Jimmy |
36:96847d42f010 | 84 | } |
The Other Jimmy |
36:96847d42f010 | 85 | |
The Other Jimmy |
36:96847d42f010 | 86 | with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile: |
The Other Jimmy |
36:96847d42f010 | 87 | json.dump(cpp_props, outfile, indent=4, separators=(',', ': ')) |
The Other Jimmy |
36:96847d42f010 | 88 | |
theotherjimmy |
43:2a7da56ebd24 | 89 | @staticmethod |
theotherjimmy |
43:2a7da56ebd24 | 90 | def clean(_): |
theotherjimmy |
43:2a7da56ebd24 | 91 | for f in ['launch', 'settings', 'tasts', 'c_cpp_properties']: |
theotherjimmy |
43:2a7da56ebd24 | 92 | remove(".vscode/%s.json" % f) |
theotherjimmy |
43:2a7da56ebd24 | 93 | rmdir(".vscode") |
The Other Jimmy |
36:96847d42f010 | 94 | |
The Other Jimmy |
36:96847d42f010 | 95 | class VSCodeGcc(VSCode, GccArm): |
The Other Jimmy |
36:96847d42f010 | 96 | LOAD_EXE = True |
The Other Jimmy |
36:96847d42f010 | 97 | NAME = "VSCode-GCC-ARM" |
The Other Jimmy |
36:96847d42f010 | 98 | |
The Other Jimmy |
36:96847d42f010 | 99 | class VSCodeArmc5(VSCode, Armc5): |
The Other Jimmy |
36:96847d42f010 | 100 | LOAD_EXE = True |
The Other Jimmy |
36:96847d42f010 | 101 | NAME = "VSCode-Armc5" |
The Other Jimmy |
36:96847d42f010 | 102 | |
The Other Jimmy |
36:96847d42f010 | 103 | class VSCodeIAR(VSCode, IAR): |
The Other Jimmy |
36:96847d42f010 | 104 | LOAD_EXE = True |
The Other Jimmy |
36:96847d42f010 | 105 | NAME = "VSCode-IAR" |
The Other Jimmy |
36:96847d42f010 | 106 | |
The Other Jimmy |
36:96847d42f010 | 107 |