Implement asynchronous output for build process

This commit is contained in:
Ivan Kravets
2015-02-15 23:53:15 +02:00
parent 0f070d1b78
commit 983b629d23
4 changed files with 38 additions and 21 deletions

View File

@@ -19,6 +19,9 @@ Release History
(`issue #42 <https://github.com/ivankravets/platformio/issues/42>`_)
* Allowed to ignore some libs from *Library Dependency Finder* via
`ignore_libs <http://docs.platformio.org/en/latest/projectconf.html#ignore-libs>`_ option
* Improved `platformio run <http://docs.platformio.org/en/latest/userguide/cmd_run.html>`__
command: asynchronous output for build process, timing and detailed
information about environment configuration (`issue #74 <https://github.com/ivankravets/platformio/issues/74>`_)
* Output compiled size and static memory usage with `platformio run <http://docs.platformio.org/en/latest/userguide/cmd_run.html>`__
command (`issue #59 <https://github.com/ivankravets/platformio/issues/59>`_)
* Updated `framework-arduino` AVR & SAM to 1.6 stable version

View File

@@ -36,6 +36,7 @@ def cli(ctx, environment, target, upload_port):
getmtime(_pioenvs_dir)):
rmtree(_pioenvs_dir)
_first_processing = True
for section in config.sections():
# skip main configuration section
if section == "platformio":
@@ -54,6 +55,10 @@ def cli(ctx, environment, target, upload_port):
process_environment(ctx, envname, options, target, upload_port)
if not _first_processing:
click.echo()
_first_processing = False
def process_environment(ctx, name, options, targets, upload_port):
terminal_width, _ = click.get_terminal_size()
@@ -67,12 +72,7 @@ def process_environment(ctx, name, options, targets, upload_port):
click.secho("-" * terminal_width, bold=True)
result = _run_environment(ctx, name, options, targets, upload_port)
is_error = "Error" in result['err']
click.secho(result['out'], fg="green")
if result['err']:
click.secho(result['err'], err=True,
fg="red" if is_error else "yellow")
is_error = "error" in result['err'].lower()
summary_text = " Took %.2f seconds " % (time() - start_time)
half_line = "=" * ((terminal_width - len(summary_text) - 10) / 2)
@@ -83,7 +83,6 @@ def process_environment(ctx, name, options, targets, upload_port):
summary_text,
half_line
), err=is_error)
click.echo()
def _run_environment(ctx, name, options, targets, upload_port):

View File

@@ -27,9 +27,9 @@ class AtmelavrPlatform(BasePlatform):
}
}
def after_run(self, result):
def on_run_err(self, line): # pylint: disable=R0201
# fix STDERR "flash written" for avrdude
if "flash written" in result['err']:
result['out'] += "\n" + result['err']
result['err'] = ""
return result
if "flash written" in line:
self.on_run_out(line)
else:
BasePlatform.on_run_err(self, line)

View File

@@ -5,10 +5,11 @@ from imp import load_source
from os import listdir
from os.path import isdir, isfile, join
from platformio import exception
import click
from platformio import exception, util
from platformio.app import get_state_item, set_state_item
from platformio.pkgmanager import PackageManager
from platformio.util import exec_command, get_home_dir, get_source_dir
class PlatformFactory(object):
@@ -30,7 +31,7 @@ class PlatformFactory(object):
@classmethod
def get_platforms(cls, installed=False):
platforms = {}
for d in (get_home_dir(), get_source_dir()):
for d in (util.get_home_dir(), util.get_source_dir()):
pdir = join(d, "platforms")
if not isdir(pdir):
continue
@@ -80,7 +81,7 @@ class BasePlatform(object):
return self.__class__.__name__[:-8].lower()
def get_build_script(self):
builtin = join(get_source_dir(), "builder", "scripts", "%s.py" %
builtin = join(util.get_source_dir(), "builder", "scripts", "%s.py" %
self.get_name())
if isfile(builtin):
return builtin
@@ -214,11 +215,15 @@ class BasePlatform(object):
"PIOPACKAGE_%s=%s" % (options['alias'].upper(), name))
try:
result = exec_command([
"scons",
"-Q",
"-f", join(get_source_dir(), "builder", "main.py")
] + variables + targets)
result = util.exec_command(
[
"scons",
"-Q",
"-f", join(util.get_source_dir(), "builder", "main.py")
] + variables + targets,
stdout=util.AsyncPipe(self.on_run_out),
stderr=util.AsyncPipe(self.on_run_err)
)
except OSError:
raise exception.SConsNotInstalled()
@@ -226,3 +231,13 @@ class BasePlatform(object):
def after_run(self, result): # pylint: disable=R0201
return result
def on_run_out(self, line): # pylint: disable=R0201
fg = None
if "is up to date" in line:
fg = "green"
click.secho(line, fg=fg)
def on_run_err(self, line): # pylint: disable=R0201
click.secho(line, err=True,
fg="red" if "error" in line.lower() else "yellow")