Improv detection of build changes

This commit is contained in:
Ivan Kravets
2015-06-04 22:50:13 +03:00
parent 8c331df105
commit 36cdbb8f0c
4 changed files with 52 additions and 10 deletions

View File

@ -4,7 +4,7 @@ Release History
2.1.1 (2015-??-??)
------------------
*
* Improved detection of build changes
2.1.0 (2015-06-03)
------------------

View File

@ -63,6 +63,7 @@ DefaultEnvironment(
PIOHOME_DIR=util.get_home_dir(),
PROJECT_DIR=util.get_project_dir(),
PROJECTLIB_DIR=util.get_projectlib_dir(),
PROJECTSRC_DIR=util.get_projectsrc_dir(),
PIOENVS_DIR=util.get_pioenvs_dir(),
@ -71,7 +72,7 @@ DefaultEnvironment(
BUILD_DIR=join("$PIOENVS_DIR", "$PIOENV"),
LIBSOURCE_DIRS=[
join("$PROJECT_DIR", "lib"),
"$PROJECTLIB_DIR",
util.get_lib_dir(),
join("$PLATFORMFW_DIR", "libraries")
]

View File

@ -2,8 +2,9 @@
# See LICENSE for details.
from datetime import datetime
from os import getcwd
from os.path import getmtime, isdir, join
from hashlib import sha1
from os import getcwd, makedirs, walk
from os.path import getmtime, isdir, isfile, join
from shutil import rmtree
from time import time
@ -38,12 +39,8 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
if unknown:
raise exception.UnknownEnvNames(", ".join(unknown))
# remove ".pioenvs" if project config is modified
_pioenvs_dir = util.get_pioenvs_dir()
if (isdir(_pioenvs_dir) and
getmtime(join(util.get_project_dir(), "platformio.ini")) >
getmtime(_pioenvs_dir)):
rmtree(_pioenvs_dir)
# clean obsolete .pioenvs dir
_clean_pioenvs_dir()
results = []
for section in config.sections():
@ -176,3 +173,43 @@ def _autoinstall_libs(ctx, libids_list):
", ".join([str(i) for i in not_intalled_libs])
)):
ctx.invoke(cmd_lib_install, libid=not_intalled_libs)
def _clean_pioenvs_dir():
pioenvs_dir = util.get_pioenvs_dir()
structhash_file = join(pioenvs_dir, "structure.hash")
proj_hash = calculate_project_hash()
# if project's config is modified
if isdir(pioenvs_dir):
if (getmtime(join(util.get_project_dir(), "platformio.ini")) >
getmtime(pioenvs_dir)):
rmtree(pioenvs_dir)
# check project structure
if isdir(pioenvs_dir):
if isfile(structhash_file):
with open(structhash_file) as f:
if f.read() == proj_hash:
return
else:
rmtree(pioenvs_dir)
if not isdir(pioenvs_dir):
makedirs(pioenvs_dir)
with open(structhash_file, "w") as f:
f.write(proj_hash)
def calculate_project_hash():
structure = []
for d in (util.get_projectsrc_dir(), util.get_projectlib_dir()):
if not isdir(d):
continue
for root, _, files in walk(d):
for f in files:
path = join(root, f)
if not any([s in path for s in (".git", ".svn")]):
structure.append(path)
return sha1(",".join(sorted(structure))).hexdigest() if structure else ""

View File

@ -167,6 +167,10 @@ def get_projectsrc_dir():
)
def get_projectlib_dir():
return join(get_project_dir(), "lib")
def get_pioenvs_dir():
return _get_projconf_option_dir(
"envs_dir",