Skip to content

Commit

Permalink
Fixed an issue when "main.cpp" was generated for a new project for 8-…
Browse files Browse the repository at this point in the history
…bit development platforms // Resolve platformio#3872
  • Loading branch information
ivankravets authored and aofaof0907 committed Jul 25, 2021
1 parent 40323cf commit 0bb9f01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ PlatformIO Core 5

- Ensure that a serial port is ready before running unit tests on a remote target (`issue #3742 <https://github.com/platformio/platformio-core/issues/3742>`_)
- Fixed an error "Unknown development platform" when running unit tests on a clean machine (`issue #3901 <https://github.com/platformio/platformio-core/issues/3901>`_)
- Fixed an issue when "main.cpp" was generated for a new project for 8-bit development platforms (`issue #3872 <https://github.com/platformio/platformio-core/issues/3872>`_)

5.1.1 (2021-03-17)
~~~~~~~~~~~~~~~~~~
Expand Down
21 changes: 18 additions & 3 deletions platformio/commands/home/rpc/handlers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ async def init(self, board, framework, project_dir):
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(
Expand Down Expand Up @@ -238,10 +238,25 @@ def _generate_project_main(project_dir, framework):
)
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):
Expand Down

0 comments on commit 0bb9f01

Please sign in to comment.