1# 2# File : vsc.py 3# This file is part of RT-Thread RTOS 4# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License along 17# with this program; if not, write to the Free Software Foundation, Inc., 18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19# 20# Change Logs: 21# Date Author Notes 22# 2018-05-30 Bernard The first version 23 24""" 25Utils for VSCode 26""" 27 28import os 29import json 30import utils 31import rtconfig 32 33def GenerateCFiles(env): 34 """ 35 Generate c_cpp_properties files 36 """ 37 if not os.path.exists('.vscode'): 38 os.mkdir('.vscode') 39 40 vsc_file = open('.vscode/c_cpp_properties.json', 'w') 41 if vsc_file: 42 info = utils.ProjectInfo(env) 43 44 cc = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC) 45 cc = os.path.abspath(cc).replace('\\', '/') 46 47 config_obj = {} 48 config_obj['name'] = 'Win32' 49 config_obj['defines'] = info['CPPDEFINES'] 50 config_obj['intelliSenseMode'] = 'clang-x64' 51 config_obj['compilerPath'] = cc 52 config_obj['cStandard'] = "c99" 53 config_obj['cppStandard'] = "c++11" 54 55 # format "a/b," to a/b. remove first quotation mark("),and remove end (",) 56 includePath = [] 57 for i in info['CPPPATH']: 58 if i[0] == '\"' and i[len(i) - 2:len(i)] == '\",': 59 includePath.append(i[1:len(i) - 2]) 60 else: 61 includePath.append(i) 62 config_obj['includePath'] = includePath 63 64 json_obj = {} 65 json_obj['configurations'] = [config_obj] 66 67 vsc_file.write(json.dumps(json_obj, ensure_ascii=False, indent=4)) 68 vsc_file.close() 69 70 return 71 72def GenerateVSCode(env): 73 print('Update setting files for VSCode...') 74 GenerateCFiles(env) 75 print('Done!') 76 77 return 78