diff --git a/HISTORY.rst b/HISTORY.rst index 9319c2a4..b5fc4dc7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -13,6 +13,7 @@ PlatformIO 4.0 * Do not shutdown PIO Home Server for "upgrade" operations (`issue #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 `_) * Ability to set "databaseFilename" for VSCode and C/C++ extension (`issue #2825 `_) * Renamed "enable_ssl" setting to `strict_ssl `__ * Fixed an issue with incorrect escaping of Windows slashes when using `PIO Unified Debugger `__ and "piped" openOCD diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 99170482..afc54473 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -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 = [] diff --git a/platformio/ide/tpls/atom/.gcc-flags.json.tpl b/platformio/ide/tpls/atom/.gcc-flags.json.tpl index 20942a7a..cbb47418 100644 --- a/platformio/ide/tpls/atom/.gcc-flags.json.tpl +++ b/platformio/ide/tpls/atom/.gcc-flags.json.tpl @@ -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 } diff --git a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl index b3d84a75..5d69c4d8 100644 --- a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl @@ -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) }}") diff --git a/platformio/ide/tpls/codeblocks/platformio.cbp.tpl b/platformio/ide/tpls/codeblocks/platformio.cbp.tpl index fc182531..ccbe4d7f 100644 --- a/platformio/ide/tpls/codeblocks/platformio.cbp.tpl +++ b/platformio/ide/tpls/codeblocks/platformio.cbp.tpl @@ -53,12 +53,12 @@ % end % for include in includes: - - % end + + % end % for file in src_files: - + % end diff --git a/platformio/ide/tpls/vim/.gcc-flags.json.tpl b/platformio/ide/tpls/vim/.gcc-flags.json.tpl index b904e1a3..b9b29fdb 100644 --- a/platformio/ide/tpls/vim/.gcc-flags.json.tpl +++ b/platformio/ide/tpls/vim/.gcc-flags.json.tpl @@ -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 } diff --git a/platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl b/platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl index 23fef0eb..7dd647fc 100644 --- a/platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl +++ b/platformio/ide/tpls/vscode/.vscode/c_cpp_properties.json.tpl @@ -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