Properly handle "--keep-build-dir" option in platformio ci command (#4061)

This fixes #4011 and possible "FileExists" errors when the "platformio ci"
command by safely copying sources to the build folder
This commit is contained in:
Valerii Koval authored and GitHub committed 2021-09-23 23:26:42 +03:00
1 parent fed40ef104
commit eab70fae3b
3 files changed
+70 -5

No files matched your search

+6 -5
View File
@@ -122,7 +122,7 @@ def cli( # pylint: disable=too-many-arguments, too-many-branches
fs.rmtree(build_dir)
def _copy_contents(dst_dir, contents):
def _copy_contents(dst_dir, contents): # pylint: disable=too-many-branches
items = {"dirs": set(), "files": set()}
for path in contents:
@@ -134,14 +134,15 @@ def _copy_contents(dst_dir, contents):
dst_dir_name = os.path.basename(dst_dir)
if dst_dir_name == "src" and len(items["dirs"]) == 1:
shutil.copytree(list(items["dirs"]).pop(), dst_dir, symlinks=True)
if not os.path.isdir(dst_dir):
shutil.copytree(list(items["dirs"]).pop(), dst_dir, symlinks=True)
else:
if not os.path.isdir(dst_dir):
os.makedirs(dst_dir)
for d in items["dirs"]:
shutil.copytree(
d, os.path.join(dst_dir, os.path.basename(d)), symlinks=True
)
src_dst_dir = os.path.join(dst_dir, os.path.basename(d))
if not os.path.isdir(src_dst_dir):
shutil.copytree(d, src_dst_dir, symlinks=True)
if not items["files"]:
return