mirror of
https://github.com/platformio/platformio-core.git
synced 2025-10-04 09:30:55 +02:00
Implement asynchronous output for build process
This commit is contained in:
@@ -19,6 +19,9 @@ Release History
|
|||||||
(`issue #42 <https://github.com/ivankravets/platformio/issues/42>`_)
|
(`issue #42 <https://github.com/ivankravets/platformio/issues/42>`_)
|
||||||
* Allowed to ignore some libs from *Library Dependency Finder* via
|
* Allowed to ignore some libs from *Library Dependency Finder* via
|
||||||
`ignore_libs <http://docs.platformio.org/en/latest/projectconf.html#ignore-libs>`_ option
|
`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>`__
|
* 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>`_)
|
command (`issue #59 <https://github.com/ivankravets/platformio/issues/59>`_)
|
||||||
* Updated `framework-arduino` AVR & SAM to 1.6 stable version
|
* Updated `framework-arduino` AVR & SAM to 1.6 stable version
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ def cli(ctx, environment, target, upload_port):
|
|||||||
getmtime(_pioenvs_dir)):
|
getmtime(_pioenvs_dir)):
|
||||||
rmtree(_pioenvs_dir)
|
rmtree(_pioenvs_dir)
|
||||||
|
|
||||||
|
_first_processing = True
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
# skip main configuration section
|
# skip main configuration section
|
||||||
if section == "platformio":
|
if section == "platformio":
|
||||||
@@ -54,6 +55,10 @@ def cli(ctx, environment, target, upload_port):
|
|||||||
|
|
||||||
process_environment(ctx, envname, options, 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):
|
def process_environment(ctx, name, options, targets, upload_port):
|
||||||
terminal_width, _ = click.get_terminal_size()
|
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)
|
click.secho("-" * terminal_width, bold=True)
|
||||||
|
|
||||||
result = _run_environment(ctx, name, options, targets, upload_port)
|
result = _run_environment(ctx, name, options, targets, upload_port)
|
||||||
is_error = "Error" in result['err']
|
is_error = "error" in result['err'].lower()
|
||||||
|
|
||||||
click.secho(result['out'], fg="green")
|
|
||||||
if result['err']:
|
|
||||||
click.secho(result['err'], err=True,
|
|
||||||
fg="red" if is_error else "yellow")
|
|
||||||
|
|
||||||
summary_text = " Took %.2f seconds " % (time() - start_time)
|
summary_text = " Took %.2f seconds " % (time() - start_time)
|
||||||
half_line = "=" * ((terminal_width - len(summary_text) - 10) / 2)
|
half_line = "=" * ((terminal_width - len(summary_text) - 10) / 2)
|
||||||
@@ -83,7 +83,6 @@ def process_environment(ctx, name, options, targets, upload_port):
|
|||||||
summary_text,
|
summary_text,
|
||||||
half_line
|
half_line
|
||||||
), err=is_error)
|
), err=is_error)
|
||||||
click.echo()
|
|
||||||
|
|
||||||
|
|
||||||
def _run_environment(ctx, name, options, targets, upload_port):
|
def _run_environment(ctx, name, options, targets, upload_port):
|
||||||
|
|||||||
@@ -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
|
# fix STDERR "flash written" for avrdude
|
||||||
if "flash written" in result['err']:
|
if "flash written" in line:
|
||||||
result['out'] += "\n" + result['err']
|
self.on_run_out(line)
|
||||||
result['err'] = ""
|
else:
|
||||||
return result
|
BasePlatform.on_run_err(self, line)
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ from imp import load_source
|
|||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isdir, isfile, join
|
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.app import get_state_item, set_state_item
|
||||||
from platformio.pkgmanager import PackageManager
|
from platformio.pkgmanager import PackageManager
|
||||||
from platformio.util import exec_command, get_home_dir, get_source_dir
|
|
||||||
|
|
||||||
|
|
||||||
class PlatformFactory(object):
|
class PlatformFactory(object):
|
||||||
@@ -30,7 +31,7 @@ class PlatformFactory(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_platforms(cls, installed=False):
|
def get_platforms(cls, installed=False):
|
||||||
platforms = {}
|
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")
|
pdir = join(d, "platforms")
|
||||||
if not isdir(pdir):
|
if not isdir(pdir):
|
||||||
continue
|
continue
|
||||||
@@ -80,7 +81,7 @@ class BasePlatform(object):
|
|||||||
return self.__class__.__name__[:-8].lower()
|
return self.__class__.__name__[:-8].lower()
|
||||||
|
|
||||||
def get_build_script(self):
|
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())
|
self.get_name())
|
||||||
if isfile(builtin):
|
if isfile(builtin):
|
||||||
return builtin
|
return builtin
|
||||||
@@ -214,11 +215,15 @@ class BasePlatform(object):
|
|||||||
"PIOPACKAGE_%s=%s" % (options['alias'].upper(), name))
|
"PIOPACKAGE_%s=%s" % (options['alias'].upper(), name))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = exec_command([
|
result = util.exec_command(
|
||||||
"scons",
|
[
|
||||||
"-Q",
|
"scons",
|
||||||
"-f", join(get_source_dir(), "builder", "main.py")
|
"-Q",
|
||||||
] + variables + targets)
|
"-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:
|
except OSError:
|
||||||
raise exception.SConsNotInstalled()
|
raise exception.SConsNotInstalled()
|
||||||
|
|
||||||
@@ -226,3 +231,13 @@ class BasePlatform(object):
|
|||||||
|
|
||||||
def after_run(self, result): # pylint: disable=R0201
|
def after_run(self, result): # pylint: disable=R0201
|
||||||
return result
|
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user