From 21f3dd11f48e3b4593a676e371429f0c415fff33 Mon Sep 17 00:00:00 2001 From: Valerii Koval Date: Tue, 16 Jun 2020 12:27:49 +0300 Subject: [PATCH] Fix printing relative paths on Windows // Resolve #3542 Fixes "ValueError" when running "clean" target if "build_dir" points to a folder on a different logical drive --- HISTORY.rst | 1 + platformio/builder/tools/piotarget.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 8b98626a..709cc9b7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -27,6 +27,7 @@ PlatformIO Core 4 * Added a new ``-e, --environment`` option to `platformio project init `__ command that helps to update a PlatformIO project using existing environment * Fixed an issue with PIO Unit Testing when running multiple environments (`issue #3523 `_) * Fixed an issue with improper processing of source files added via multiple Build Middlewares (`issue #3531 `_) +* Fixed an issue with ``clean`` target on Windows when project and build directories are located on different logical drives (`issue #3542 `_) 4.3.4 (2020-05-23) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piotarget.py b/platformio/builder/tools/piotarget.py index 7106a40d..a6dcaf3b 100644 --- a/platformio/builder/tools/piotarget.py +++ b/platformio/builder/tools/piotarget.py @@ -20,7 +20,7 @@ from SCons.Action import Action # pylint: disable=import-error 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): @@ -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)