Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions platformio/project/integration/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def get_supported_ides(cls):
]
)

def get_project_files_basename(self):
basename = os.path.basename(os.path.abspath(self.project_dir))
return basename or os.path.basename(os.getcwd())
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_project_files_basename() can return an empty string when project_dir is a filesystem root (e.g. / or C:\\). In that case generate() will replace platformio with "" and produce broken filenames like .vcxproj / .creator. Consider ensuring a non-empty fallback (e.g., legacy "platformio" or "project") when the computed basename is falsy, instead of falling back to os.getcwd() (which will also be root under fs.cd(project_dir)).

Suggested change
return basename or os.path.basename(os.getcwd())
# Ensure a non-empty fallback when project_dir (and possibly CWD) is a
# filesystem root, where os.path.basename(...) returns an empty string.
# Use a stable default name instead of deriving it from the CWD.
return basename or "platformio"

Copilot uses AI. Check for mistakes.

@staticmethod
def filter_includes(includes_map, ignore_scopes=None, to_unix_path=True):
ignore_scopes = ignore_scopes or []
Expand All @@ -85,6 +89,7 @@ def _load_tplvars(self):
"project_name": self.config.get(
"platformio", "name", os.path.basename(self.project_dir)
),
"project_files_basename": self.get_project_files_basename(),
"project_dir": self.project_dir,
"forced_env_name": self.forced_env_name,
"default_debug_env_name": get_default_debug_env(self.config),
Expand Down Expand Up @@ -161,6 +166,10 @@ def generate(self):
if not os.path.isdir(dst_dir):
os.makedirs(dst_dir)
file_name = os.path.basename(tpl_path)[:-4]
if file_name == "platformio" or file_name.startswith("platformio."):
file_name = file_name.replace(
"platformio", self.get_project_files_basename(), 1
)
contents = self._render_tpl(tpl_path, tpl_vars)
self._merge_contents(os.path.join(dst_dir, file_name), contents)

Expand Down
Loading