forked from platformio/platformio-core
Implement asynchronous output for build process
This commit is contained in:
1 parent
0f070d1b78
commit
983b629d23
4 files changed
+38
-21
No files matched your search
@@ -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)
|
||||
@@ -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")
|
||||
Reference in new issue
Block a user