From 4ee4315c048d129b0fc2407f38a731cf60cb9287 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 2 Sep 2019 23:22:42 +0300 Subject: [PATCH] Fixed an issue with preprocessing of ``*.ino`` when macros were not handled // Resolve #2972 --- HISTORY.rst | 1 + platformio/builder/tools/piolib.py | 12 +++++++++--- platformio/builder/tools/piomisc.py | 12 +++++++----- platformio/builder/tools/platformio.py | 6 ++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ead20705..da29b008 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -12,6 +12,7 @@ PlatformIO Core 4.0 * Extend project environment configuration in "platformio.ini" with other sections using a new `extends `__ option (`issue #2953 `_) * Fixed an issue with project generator for `CLion IDE `__ when 2 environments were used (`issue #2824 `_) * Fixed default PIO Unified Debugger configuration for `J-Link probe `__ +* Fixed an issue with preprocessing of ``*.ino`` files when macros were not handled (`issue #2972 `_) 4.0.3 (2019-08-30) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py index 185b2985..53fca42c 100644 --- a/platformio/builder/tools/piolib.py +++ b/platformio/builder/tools/piolib.py @@ -816,15 +816,21 @@ class ProjectAsLibBuilder(LibBuilderBase): def get_search_files(self): # project files - items = LibBuilderBase.get_search_files(self) + search_files = LibBuilderBase.get_search_files(self) # test files if "__test" in COMMAND_LINE_TARGETS: - items.extend([ + search_files.extend([ join("$PROJECTTEST_DIR", item) for item in self.env.MatchSourceFiles( "$PROJECTTEST_DIR", "$PIOTEST_SRC_FILTER") ]) - return items + if "arduino" in self.env.get("PIOFRAMEWORK", []): + search_files.extend([ + join(self.src_dir, item) + for item in fs.match_src_files(self.src_dir, self.src_filter, ( + "ino", "pde")) + ]) + return search_files @property def lib_ldf_mode(self): diff --git a/platformio/builder/tools/piomisc.py b/platformio/builder/tools/piomisc.py index d7e17b0b..9eb5cb55 100644 --- a/platformio/builder/tools/piomisc.py +++ b/platformio/builder/tools/piomisc.py @@ -88,11 +88,13 @@ class InoToCPPConverter(object): tmp_path = mkstemp()[1] with open(tmp_path, "w") as fp: fp.write(contents) - self.env.Execute( - self.env.VerboseAction( - '$CXX -o "{0}" -x c++ -fpreprocessed -dD -E "{1}"'.format( - out_file, tmp_path), - "Converting " + basename(out_file[:-4]))) + env = self.env.Clone() + env.Append(CCFLAGS=["-x", "c++", "-E"]) + cmd = env["CXXCOM"]\ + .replace("$TARGET", '"%s"' % out_file)\ + .replace("$SOURCES", '"%s"' % tmp_path) + env.Execute( + env.VerboseAction(cmd, "Converting " + basename(out_file[:-4]))) atexit.register(_delete_file, tmp_path) return isfile(out_file) diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 057d39aa..1ccc271d 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -63,6 +63,10 @@ def _build_project_deps(env): # extra build flags from `platformio.ini` projenv.ProcessFlags(env.get("SRC_BUILD_FLAGS")) + if ("nobuild" not in COMMAND_LINE_TARGETS + and "arduino" in projenv.get("PIOFRAMEWORK", [])): + projenv.ConvertInoToCpp() + is_test = "__test" in COMMAND_LINE_TARGETS if is_test: projenv.BuildSources("$BUILDTEST_DIR", "$PROJECTTEST_DIR", @@ -284,8 +288,6 @@ def BuildFrameworks(env, frameworks): if f == "arduino": # Arduino IDE appends .o the end of filename Builder.match_splitext = scons_patched_match_splitext - if "nobuild" not in COMMAND_LINE_TARGETS: - env.ConvertInoToCpp() if f in board_frameworks: SConscript(env.GetFrameworkScript(f), exports="env")