Improve VSCode template structure (#3385)

* Switch to click argument parser

* Typo fix

* Tidy up VSCode template

Co-authored-by: Ivan Kravets <me@ikravets.com>
This commit is contained in:
Valerii Koval
2020-02-17 12:19:00 +02:00
committed by GitHub
parent b8c9eee8af
commit 154be7fa81

View File

@ -1,11 +1,8 @@
{
"configurations": [
{
"name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
},
{
% import os % import os
% import platform % import platform
% import re
%
% import click
% %
% systype = platform.system().lower() % systype = platform.system().lower()
% %
@ -17,6 +14,33 @@
% return " " in flag and systype == "windows" % return " " in flag and systype == "windows"
% end % end
% %
% def split_args(args_string):
% return click.parser.split_arg_string(to_unix_path(args_string))
% end
%
% def filter_args(args, allowed, ignore=None):
% if not allowed:
% return []
% end
%
% ignore = ignore or []
% result = []
% i = 0
% length = len(args)
% while(i < length):
% if any(args[i].startswith(f) for f in allowed) and not any(
% args[i].startswith(f) for f in ignore):
% result.append(args[i])
% if i + 1 < length and not args[i + 1].startswith("-"):
% i += 1
% result.append(args[i])
% end
% end
% i += 1
% end
% return result
% end
%
% def _find_abs_path(inc, inc_paths): % def _find_abs_path(inc, inc_paths):
% for path in inc_paths: % for path in inc_paths:
% if os.path.isfile(os.path.join(path, inc)): % if os.path.isfile(os.path.join(path, inc)):
@ -28,45 +52,16 @@
% %
% def _find_forced_includes(flags, inc_paths): % def _find_forced_includes(flags, inc_paths):
% result = [] % result = []
% i = 0 % for f in flags:
% length = len(flags) % inc = ""
% while(i < length): % if f.startswith("-include") and f.split("-include")[1].strip():
% if flags[i].startswith("-include"): % inc = f.split("-include")[1].strip()
% i = i + 1 % elif not f.startswith("-"):
% if i < length and not flags[i].startswith("-"): % inc = f
% inc = flags[i] % end
% if not os.path.isabs(inc): % if inc:
% inc = _find_abs_path(inc, inc_paths) % result.append(_find_abs_path(inc, inc_paths))
% end
% result.append(to_unix_path(inc))
% end
% end % end
% i = i + 1
% end
% return result
% end
%
% def _split_flags(flags):
% result = []
% i = 0
% flags = flags.strip()
% while i < len(flags):
% current_arg = []
% while i < len(flags) and flags[i] != " ":
% if flags[i] == '"':
% quotes_idx = flags.find('"', i + 1)
% current_arg.extend(flags[i + 1:quotes_idx])
% i = quotes_idx + 1
% else:
% current_arg.append(flags[i])
% i = i + 1
% end
% end
% arg = "".join(current_arg)
% if arg.strip():
% result.append(arg.strip())
% end
% i = i + 1
% end % end
% return result % return result
% end % end
@ -79,6 +74,19 @@
% end % end
% end % end
% %
% STD_RE = re.compile(r"\-std=[a-z\+]+(\d+)")
% cc_stds = STD_RE.findall(cc_flags)
% cxx_stds = STD_RE.findall(cxx_flags)
% cc_m_flags = split_args(cc_flags)
% forced_includes = _find_forced_includes(
% filter_args(cc_m_flags, ["-include"]), cleaned_includes)
%
{
"configurations": [
{
"name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
},
{
% if systype == "windows": % if systype == "windows":
"name": "Win32", "name": "Win32",
% elif systype == "darwin": % elif systype == "darwin":
@ -109,13 +117,6 @@
"" ""
], ],
"intelliSenseMode": "clang-x64", "intelliSenseMode": "clang-x64",
% import re
% STD_RE = re.compile(r"\-std=[a-z\+]+(\d+)")
% cc_stds = STD_RE.findall(cc_flags)
% cxx_stds = STD_RE.findall(cxx_flags)
% cc_m_flags = _split_flags(cc_flags)
% forced_includes = _find_forced_includes(cc_m_flags, cleaned_includes)
%
% if cc_stds: % if cc_stds:
"cStandard": "c{{ cc_stds[-1] }}", "cStandard": "c{{ cc_stds[-1] }}",
% end % end
@ -134,8 +135,7 @@
"compilerArgs": [ "compilerArgs": [
% for flag in [ % for flag in [
% '"%s"' % _escape(f) if _escape_required(f) else f % '"%s"' % _escape(f) if _escape_required(f) else f
% for f in cc_m_flags % for f in filter_args(cc_m_flags, ["-m", "-i", "@"], ["-include"])
% if f.startswith(("-m", "-i", "@")) and not f.startswith("-include")
% ]: % ]:
"{{ flag }}", "{{ flag }}",
% end % end