vsc.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. Utils for VSCode
  25. """
  26. import os
  27. import json
  28. import utils
  29. import rtconfig
  30. from utils import _make_path_relative
  31. def GenerateCFiles(env):
  32. """
  33. Generate c_cpp_properties files
  34. """
  35. if not os.path.exists('.vscode'):
  36. os.mkdir('.vscode')
  37. vsc_file = open('.vscode/c_cpp_properties.json', 'w')
  38. if vsc_file:
  39. info = utils.ProjectInfo(env)
  40. cc = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
  41. cc = os.path.abspath(cc).replace('\\', '/')
  42. config_obj = {}
  43. config_obj['name'] = 'Win32'
  44. config_obj['defines'] = info['CPPDEFINES']
  45. config_obj['intelliSenseMode'] = 'clang-x64'
  46. config_obj['compilerPath'] = cc
  47. config_obj['cStandard'] = "c99"
  48. config_obj['cppStandard'] = "c++11"
  49. # format "a/b," to a/b. remove first quotation mark("),and remove end (",)
  50. includePath = []
  51. for i in info['CPPPATH']:
  52. if i[0] == '\"' and i[len(i) - 2:len(i)] == '\",':
  53. includePath.append(_make_path_relative(os.getcwd(), i[1:len(i) - 2]))
  54. else:
  55. includePath.append(_make_path_relative(os.getcwd(), i))
  56. config_obj['includePath'] = includePath
  57. json_obj = {}
  58. json_obj['configurations'] = [config_obj]
  59. vsc_file.write(json.dumps(json_obj, ensure_ascii=False, indent=4))
  60. vsc_file.close()
  61. return
  62. def GenerateVSCode(env):
  63. print('Update setting files for VSCode...')
  64. GenerateCFiles(env)
  65. print('Done!')
  66. return