From 80c24a1993efbbdefd55b67dedcee58fe0d322ee Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 2 Apr 2021 15:19:18 +0300 Subject: [PATCH] Fixed an issue when "main.cpp" was generated for a new project for 8-bit development platforms // Resolve #3872 --- HISTORY.rst | 1 + .../commands/home/rpc/handlers/project.py | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8f6a20cc..46510eb3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -31,6 +31,7 @@ PlatformIO Core 5 - Ensure that a serial port is ready before running unit tests on a remote target (`issue #3742 `_) - Fixed an error "Unknown development platform" when running unit tests on a clean machine (`issue #3901 `_) + - Fixed an issue when "main.cpp" was generated for a new project for 8-bit development platforms (`issue #3872 `_) 5.1.1 (2021-03-17) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/commands/home/rpc/handlers/project.py b/platformio/commands/home/rpc/handlers/project.py index cb8eda5a..8bac4d1c 100644 --- a/platformio/commands/home/rpc/handlers/project.py +++ b/platformio/commands/home/rpc/handlers/project.py @@ -200,10 +200,10 @@ class ProjectRPC: await PIOCoreRPC.call( args, options={"cwd": project_dir, "force_subprocess": True} ) - return self._generate_project_main(project_dir, framework) + return self._generate_project_main(project_dir, board, framework) @staticmethod - def _generate_project_main(project_dir, framework): + def _generate_project_main(project_dir, board, framework): main_content = None if framework == "arduino": main_content = "\n".join( @@ -238,10 +238,25 @@ class ProjectRPC: ) if not main_content: return project_dir + + is_cpp_project = True + pm = PlatformPackageManager() + try: + board = pm.board_config(board) + platforms = board.get("platforms", board.get("platform")) + if not isinstance(platforms, list): + platforms = [platforms] + c_based_platforms = ["intel_mcs51", "ststm8"] + is_cpp_project = not (set(platforms) & set(c_based_platforms)) + except exception.PlatformioException: + pass + with fs.cd(project_dir): config = ProjectConfig() src_dir = config.get_optional_dir("src") - main_path = os.path.join(src_dir, "main.cpp") + main_path = os.path.join( + src_dir, "main.%s" % ("cpp" if is_cpp_project else "c") + ) if os.path.isfile(main_path): return project_dir if not os.path.isdir(src_dir):