From ec035c25a1009cefa68601e4228ca2517e55e55e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 2 Sep 2016 18:45:19 +0300 Subject: [PATCH] Improve "clean" target // Resolve #747 --- platformio/builder/main.py | 11 ++++++++--- platformio/builder/tools/piomisc.py | 18 ++++++++++++++++-- platformio/managers/platform.py | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/platformio/builder/main.py b/platformio/builder/main.py index f78c4942..2da97908 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -94,7 +94,6 @@ DEFAULT_ENV_OPTIONS = dict( PYTHONEXE=util.get_pythonexe_path()) if not int(ARGUMENTS.get("PIOVERBOSE", 0)): - print "Verbose mode can be enabled via `-v, --verbose` option" DEFAULT_ENV_OPTIONS['ARCOMSTR'] = "Archiving $TARGET" DEFAULT_ENV_OPTIONS['LINKCOMSTR'] = "Linking $TARGET" DEFAULT_ENV_OPTIONS['RANLIBCOMSTR'] = "Indexing $TARGET" @@ -108,6 +107,12 @@ for k in commonvars.keys(): if k in env: env[k] = base64.b64decode(env[k]) +if env.GetOption('clean'): + env.PioClean(env.subst("$BUILD_DIR")) + env.Exit(0) +elif not int(ARGUMENTS.get("PIOVERBOSE", 0)): + print "Verbose mode can be enabled via `-v, --verbose` option" + # Handle custom variables from system environment for var in ("BUILD_FLAGS", "SRC_BUILD_FLAGS", "SRC_FILTER", "EXTRA_SCRIPT", "UPLOAD_PORT", "UPLOAD_FLAGS", "LIB_EXTRA_DIRS"): @@ -138,8 +143,8 @@ if env.get("EXTRA_SCRIPT"): if "envdump" in COMMAND_LINE_TARGETS: print env.Dump() - env.Exit() + env.Exit(0) if "idedata" in COMMAND_LINE_TARGETS: print json.dumps(env.DumpIDEData()) - env.Exit() + env.Exit(0) diff --git a/platformio/builder/tools/piomisc.py b/platformio/builder/tools/piomisc.py index 46ba5ab4..c38258af 100644 --- a/platformio/builder/tools/piomisc.py +++ b/platformio/builder/tools/piomisc.py @@ -18,8 +18,8 @@ import atexit import re import sys from glob import glob -from os import environ, remove -from os.path import basename, isfile, join +from os import environ, remove, walk +from os.path import basename, isdir, isfile, join, relpath from tempfile import mkstemp from SCons.Action import Action @@ -317,6 +317,19 @@ def VerboseAction(_, act, actstr): return Action(act, actstr) +def PioClean(env, clean_dir): + if not isdir(clean_dir): + print "Build environment is clean" + env.Exit(0) + for root, _, files in walk(clean_dir): + for file_ in files: + remove(join(root, file_)) + print "Removed %s" % relpath(join(root, file_)) + print "Done cleaning" + util.rmtree_(clean_dir) + env.Exit(0) + + def exists(_): return True @@ -327,4 +340,5 @@ def generate(env): env.AddMethod(GetCompilerType) env.AddMethod(GetActualLDScript) env.AddMethod(VerboseAction) + env.AddMethod(PioClean) return env diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py index 2896ceae..6baab0f4 100644 --- a/platformio/managers/platform.py +++ b/platformio/managers/platform.py @@ -279,6 +279,8 @@ class PlatformRunMixin(object): self._echo_line(line, level=3 if is_error else 2) def _echo_line(self, line, level): + if line.startswith("scons: "): + line = line[7:] assert 1 <= level <= 3 if self.silent and (level < 2 or not line): return