init

Dependencies:   mbed

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 
00016 from os.path import join, exists, realpath, relpath, basename, isfile, splitext
00017 from os import makedirs, listdir
00018 import json
00019 
00020 from tools.export.makefile import Makefile, GccArm, Armc5, IAR
00021 
00022 class VSCode (Makefile ):
00023     """Generic VSCode project. Intended to be subclassed by classes that
00024     specify a type of Makefile.
00025     """
00026     def generate (self):
00027         """Generate Makefile and VSCode launch and task files
00028         """
00029         super(VSCode, self).generate()
00030         ctx = {
00031             'name': self.project_name,
00032             'elf_location': join('BUILD', self.project_name)+'.elf',
00033             'c_symbols': self.toolchain.get_symbols(),
00034             'asm_symbols': self.toolchain.get_symbols(True),
00035             'target': self.target,
00036             'include_paths': self.resources.inc_dirs,
00037             'load_exe': str(self.LOAD_EXE).lower()
00038         }
00039 
00040         if not exists(join(self.export_dir, '.vscode')):
00041             makedirs(join(self.export_dir, '.vscode'))
00042 
00043         config_files = ['launch', 'settings', 'tasks']
00044         for file in config_files:
00045             if not exists('.vscode/%s.json' % file):
00046                 self.gen_file('vscode/%s.tmpl' % file, ctx,
00047                               '.vscode/%s.json' % file)
00048             else:
00049                 print 'Keeping existing %s.json' % file
00050 
00051         # So.... I want all .h and .hpp files in self.resources.inc_dirs
00052         all_directories = []
00053 
00054         for directory in self.resources.inc_dirs:
00055             if not directory:
00056                 continue
00057 
00058             if directory == ".":
00059                 all_directories.append("${workspaceRoot}/*")
00060             else:
00061                 all_directories.append(directory.replace("./", "${workspaceRoot}/") + "/*")
00062 
00063         cpp_props = {
00064             "configurations": [
00065                 {
00066                     "name": "Windows",
00067                     "includePath": [x.replace("/", "\\") for x in all_directories],
00068                     "defines": [symbol for symbol in self.toolchain.get_symbols()]
00069                 },
00070                 {
00071                     "name": "Mac",
00072                     "includePath": all_directories,
00073                     "defines": [symbol for symbol in self.toolchain.get_symbols()]
00074                 },
00075                 {
00076                     "name": "Linux",
00077                     "includePath": all_directories,
00078                     "defines": [symbol for symbol in self.toolchain.get_symbols()]
00079                 }
00080             ]
00081         }
00082 
00083         with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile:
00084             json.dump(cpp_props, outfile, indent=4, separators=(',', ': '))
00085 
00086 
00087 class VSCodeGcc(VSCode , GccArm):
00088     LOAD_EXE = True
00089     NAME = "VSCode-GCC-ARM"
00090 
00091 class VSCodeArmc5(VSCode , Armc5):
00092     LOAD_EXE = True
00093     NAME = "VSCode-Armc5"
00094 
00095 class VSCodeIAR(VSCode , IAR):
00096     LOAD_EXE = True
00097     NAME = "VSCode-IAR"
00098 
00099