Automatically normalize file system paths to UNIX-style for Project Generator // Resolve #2857

This commit is contained in:
Ivan Kravets
2019-08-19 14:43:39 +03:00
parent f46e1b7a3a
commit a2830dd527
7 changed files with 30 additions and 17 deletions

View File

@ -13,6 +13,7 @@ PlatformIO 4.0
* Do not shutdown PIO Home Server for "upgrade" operations (`issue #2784 <https://github.com/platformio/platformio-core/issues/2784>`_)
* Improved computing of project check sum (structure, configuration) and avoid unnecessary rebuilding
* Improved printing of tabulated results
* Automatically normalize file system paths to UNIX-style for Project Generator (`issue #2857 <https://github.com/platformio/platformio-core/issues/2857>`_)
* Ability to set "databaseFilename" for VSCode and C/C++ extension (`issue #2825 <https://github.com/platformio/platformio-core/issues/2825>`_)
* Renamed "enable_ssl" setting to `strict_ssl <http://docs.platformio.org/page/userguide/cmd_settings.html#strict-ssl>`__
* Fixed an issue with incorrect escaping of Windows slashes when using `PIO Unified Debugger <http://docs.platformio.org/page/plus/debugging.html>`__ and "piped" openOCD

View File

@ -73,10 +73,10 @@ class ProjectGenerator(object):
"project_dir": self.project_dir,
"env_name": self.env_name,
"user_home_dir": abspath(expanduser("~")),
"platformio_path": self._fix_os_path(
"platformio_path":
sys.argv[0] if isfile(sys.argv[0])
else where_is_program("platformio")),
"env_path": self._fix_os_path(os.getenv("PATH")),
else where_is_program("platformio"),
"env_path": os.getenv("PATH"),
"env_pathsep": os.pathsep
} # yapf: disable
@ -95,11 +95,23 @@ class ProjectGenerator(object):
get_project_libdeps_dir(), self.env_name)
}) # yapf: disable
for key, value in tpl_vars.items():
if key.endswith(("_path", "_dir")):
tpl_vars[key] = self.to_unix_path(value)
for key in ("includes", "src_files", "libsource_dirs"):
if key not in tpl_vars:
continue
tpl_vars[key] = [self.to_unix_path(inc) for inc in tpl_vars[key]]
tpl_vars['to_unix_path'] = self.to_unix_path
return tpl_vars
@staticmethod
def _fix_os_path(path):
return (re.sub(r"[\\]+", '\\' * 4, path) if WINDOWS else path)
def to_unix_path(path):
if not WINDOWS or not path:
return path
return re.sub(r"[\\]+", "/", path)
def get_src_files(self):
result = []

View File

@ -1,9 +1,9 @@
% _defines = " ".join(["-D%s" % d for d in defines])
{
"execPath": "{{ cxx_path.replace("\\", "/") }}",
"execPath": "{{ cxx_path }}",
"gccDefaultCFlags": "-fsyntax-only {{! cc_flags.replace(' -MMD ', ' ').replace('"', '\\"') }} {{ !_defines.replace('"', '\\"') }}",
"gccDefaultCppFlags": "-fsyntax-only {{! cxx_flags.replace(' -MMD ', ' ').replace('"', '\\"') }} {{ !_defines.replace('"', '\\"') }}",
"gccErrorLimit": 15,
"gccIncludePaths": "{{ ','.join(includes).replace("\\", "/") }}",
"gccIncludePaths": "{{ ','.join(includes) }}",
"gccSuppressWarnings": false
}

View File

@ -17,7 +17,7 @@
% path = path.replace(user_home_dir, "$ENV{HOME}")
% end
% end
% return path.replace("\\", "/")
% return path
% end
set(PLATFORMIO_CMD "{{ _normalize_path(platformio_path) }}")

View File

@ -53,12 +53,12 @@
<Add option="-D{{define}}"/>
% end
% for include in includes:
<Add directory="{{include.replace("\\", "/")}}"/>
% end
<Add directory="{{include}}"/>
% end
</Compiler>
<Unit filename="platformio.ini" />
% for file in src_files:
<Unit filename="{{file.replace("\\", "/")}}"></Unit>
<Unit filename="{{file}}"></Unit>
% end
</Project>
</CodeBlocks_project_file>

View File

@ -1,9 +1,9 @@
% _defines = " ".join(["-D%s" % d for d in defines])
{
"execPath": "{{ cxx_path.replace("\\", "/") }}",
"execPath": "{{ cxx_path }}",
"gccDefaultCFlags": "-fsyntax-only {{! cc_flags.replace(' -MMD ', ' ').replace('"', '\\"') }} {{ !_defines.replace('"', '\\"') }}",
"gccDefaultCppFlags": "-fsyntax-only {{! cxx_flags.replace(' -MMD ', ' ').replace('"', '\\"') }} {{ !_defines.replace('"', '\\"') }}",
"gccErrorLimit": 15,
"gccIncludePaths": "{{! ','.join("'{}'".format(w.replace("\\", '/')) for w in includes)}}",
"gccIncludePaths": "{{! ','.join("'{}'".format(inc) for inc in includes)}}",
"gccSuppressWarnings": false
}

View File

@ -10,7 +10,7 @@
% systype = platform.system().lower()
%
% def _escape(text):
% return text.replace('\\\\', '/').replace('\\', '/').replace('"', '\\"')
% return to_unix_path(text).replace('"', '\\"')
% end
%
% cleaned_includes = []
@ -30,7 +30,7 @@
% end
"includePath": [
% for include in cleaned_includes:
"{{! _escape(include) }}",
"{{ include }}",
% end
""
],
@ -38,7 +38,7 @@
"limitSymbolsToIncludedHeaders": true,
"path": [
% for include in cleaned_includes:
"{{! _escape(include) }}",
"{{ include }}",
% end
""
]
@ -64,7 +64,7 @@
% if cxx_stds:
"cppStandard": "c++{{ cxx_stds[-1] }}",
% end
"compilerPath": "\"{{! _escape(cc_path) }}\" {{! _escape(cc_m_flags) }}"
"compilerPath": "\"{{cc_path}}\" {{! _escape(cc_m_flags) }}"
}
],
"version": 4