Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers __init__.py Source File

__init__.py

00001 # mbed SDK
00002 # Copyright (c) 2011-2016 ARM Limited
00003 #
00004 # Licensed under the Apache License, Version 2.0 (the "License");
00005 # you may not use this file except in compliance with the License.
00006 # You may obtain a copy of the License at
00007 #
00008 #     http://www.apache.org/licenses/LICENSE-2.0
00009 #
00010 # Unless required by applicable law or agreed to in writing, software
00011 # distributed under the License is distributed on an "AS IS" BASIS,
00012 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 # See the License for the specific language governing permissions and
00014 # limitations under the License.
00015 from __future__ import print_function, absolute_import
00016 from builtins import str
00017 
00018 
00019 from os.path import join, exists, realpath, relpath, basename, isfile, splitext
00020 from os import makedirs, listdir, remove, rmdir
00021 import json
00022 
00023 from tools.export.makefile import Makefile, GccArm, Armc5, IAR
00024 
00025 class VSCode (Makefile ):
00026     """Generic VSCode project. Intended to be subclassed by classes that
00027     specify a type of Makefile.
00028     """
00029     def generate (self):
00030         """Generate Makefile and VSCode launch and task files
00031         """
00032         super(VSCode, self).generate()
00033         ctx = {
00034             'name': self.project_name,
00035             'elf_location': join('BUILD', self.project_name)+'.elf',
00036             'c_symbols': self.toolchain.get_symbols(),
00037             'asm_symbols': self.toolchain.get_symbols(True),
00038             'target': self.target,
00039             'include_paths': self.resources.inc_dirs,
00040             'load_exe': str(self.LOAD_EXE).lower()
00041         }
00042 
00043         if not exists(join(self.export_dir, '.vscode')):
00044             makedirs(join(self.export_dir, '.vscode'))
00045 
00046         config_files = ['launch', 'settings', 'tasks']
00047         for file in config_files:
00048             if not exists('.vscode/%s.json' % file):
00049                 self.gen_file('vscode/%s.tmpl' % file, ctx,
00050                               '.vscode/%s.json' % file)
00051             else:
00052                 print('Keeping existing %s.json' % file)
00053 
00054         # So.... I want all .h and .hpp files in self.resources.inc_dirs
00055         all_directories = []
00056 
00057         for directory in self.resources.inc_dirs:
00058             if not directory:
00059                 continue
00060 
00061             if directory == ".":
00062                 all_directories.append("${workspaceRoot}/*")
00063             else:
00064                 all_directories.append(directory.replace("./", "${workspaceRoot}/") + "/*")
00065 
00066         cpp_props = {
00067             "configurations": [
00068                 {
00069                     "name": "Windows",
00070                     "includePath": [x.replace("/", "\\") for x in all_directories],
00071                     "defines": [symbol for symbol in self.toolchain.get_symbols()]
00072                 },
00073                 {
00074                     "name": "Mac",
00075                     "includePath": all_directories,
00076                     "defines": [symbol for symbol in self.toolchain.get_symbols()]
00077                 },
00078                 {
00079                     "name": "Linux",
00080                     "includePath": all_directories,
00081                     "defines": [symbol for symbol in self.toolchain.get_symbols()]
00082                 }
00083             ]
00084         }
00085 
00086         with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile:
00087             json.dump(cpp_props, outfile, indent=4, separators=(',', ': '))
00088 
00089     @staticmethod
00090     def clean (_):
00091         for f in ['launch', 'settings', 'tasts', 'c_cpp_properties']:
00092             remove(".vscode/%s.json" % f)
00093         rmdir(".vscode")
00094 
00095 class VSCodeGcc(VSCode , GccArm):
00096     LOAD_EXE = True
00097     NAME = "VSCode-GCC-ARM"
00098 
00099 class VSCodeArmc5(VSCode , Armc5):
00100     LOAD_EXE = True
00101     NAME = "VSCode-Armc5"
00102 
00103 class VSCodeIAR(VSCode , IAR):
00104     LOAD_EXE = True
00105     NAME = "VSCode-IAR"
00106 
00107