Skip to content

Commit

Permalink
Fix printing relative paths on Windows // Resolve #3542
Browse files Browse the repository at this point in the history
Fixes "ValueError" when running "clean" target if "build_dir"
points to a folder on a different logical drive
  • Loading branch information
valeros committed Jun 16, 2020
1 parent a9c13aa commit 21f3dd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ PlatformIO Core 4
* Added a new ``-e, --environment`` option to `platformio project init <https://docs.platformio.org/page/core/userguide/project/cmd_init.html#cmdoption-platformio-project-init-e>`__ command that helps to update a PlatformIO project using existing environment
* Fixed an issue with PIO Unit Testing when running multiple environments (`issue #3523 <https://github.com/platformio/platformio-core/issues/3523>`_)
* Fixed an issue with improper processing of source files added via multiple Build Middlewares (`issue #3531 <https://github.com/platformio/platformio-core/issues/3531>`_)
* Fixed an issue with ``clean`` target on Windows when project and build directories are located on different logical drives (`issue #3542 <https://github.com/platformio/platformio-core/issues/3542>`_)

4.3.4 (2020-05-23)
~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 10 additions & 3 deletions platformio/builder/tools/piotarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from SCons.Script import ARGUMENTS # pylint: disable=import-error
from SCons.Script import AlwaysBuild # pylint: disable=import-error

from platformio import fs
from platformio import compat, fs


def VerboseAction(_, act, actstr):
Expand All @@ -30,17 +30,24 @@ def VerboseAction(_, act, actstr):


def PioClean(env, clean_dir):
def _relpath(path):
if compat.WINDOWS:
prefix = os.getcwd()[:2].lower()
if ":" not in prefix or not path.lower().startswith(prefix):
return path
return os.path.relpath(path)

if not os.path.isdir(clean_dir):
print("Build environment is clean")
env.Exit(0)
clean_rel_path = os.path.relpath(clean_dir)
clean_rel_path = _relpath(clean_dir)
for root, _, files in os.walk(clean_dir):
for f in files:
dst = os.path.join(root, f)
os.remove(dst)
print(
"Removed %s"
% (dst if clean_rel_path.startswith(".") else os.path.relpath(dst))
% (dst if not clean_rel_path.startswith(".") else _relpath(dst))
)
print("Done cleaning")
fs.rmtree(clean_dir)
Expand Down

0 comments on commit 21f3dd1

Please sign in to comment.