def _run_scons(self, variables, targets, jobs): args = [ get_pythonexe_path(), join(get_core_package_dir("tool-scons"), "script", "scons"), "-Q", "--warn=no-no-parallel-support", "--jobs", str(jobs), "--sconstruct", join(fs.get_source_dir(), "builder", "main.py") ] # yapf: disable args.append("PIOVERBOSE=%d" % (1 if self.verbose else 0)) # pylint: disable=protected-access args.append("ISATTY=%d" % (1 if click._compat.isatty(sys.stdout) else 0)) args += targets # encode and append variables for key, value in variables.items(): args.append("%s=%s" % (key.upper(), self.encode_scons_arg(value))) def _write_and_flush(stream, data): try: stream.write(data) stream.flush() except IOError: pass copy_pythonpath_to_osenv() result = exec_command( args, stdout=BuildAsyncPipe( line_callback=self._on_stdout_line, data_callback=lambda data: _write_and_flush(sys.stdout, data)), stderr=BuildAsyncPipe( line_callback=self._on_stderr_line, data_callback=lambda data: _write_and_flush(sys.stderr, data))) return result
def pioplus_call(args, **kwargs): if WINDOWS and sys.version_info < (2, 7, 6): raise exception.PlatformioException( "PlatformIO Core Plus v%s does not run under Python version %s.\n" "Minimum supported version is 2.7.6, please upgrade Python.\n" "Python 3 is not yet supported.\n" % (__version__, sys.version)) pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus") pythonexe_path = get_pythonexe_path() os.environ["PYTHONEXEPATH"] = pythonexe_path os.environ["PYTHONPYSITEDIR"] = get_core_package_dir("contrib-pysite") os.environ["PIOCOREPYSITEDIR"] = dirname(fs.get_source_dir() or "") if dirname(pythonexe_path) not in os.environ["PATH"].split(os.pathsep): os.environ["PATH"] = (os.pathsep).join( [dirname(pythonexe_path), os.environ["PATH"]]) copy_pythonpath_to_osenv() code = subprocess.call([pioplus_path] + args, **kwargs) # handle remote update request if code == 13: count_attr = "_update_count" try: count_value = getattr(pioplus_call, count_attr) except AttributeError: count_value = 0 setattr(pioplus_call, count_attr, 1) count_value += 1 setattr(pioplus_call, count_attr, count_value) if count_value < PIOPLUS_AUTO_UPDATES_MAX: update_core_packages() return pioplus_call(args, **kwargs) # handle reload request elif code == 14: return pioplus_call(args, **kwargs) if code != 0: raise exception.ReturnErrorCode(1) return True
def _run_scons(self, variables, targets, jobs): scons_dir = get_core_package_dir("tool-scons") script_path = (os.path.join(scons_dir, "script", "scons") if PY2 else os.path.join(scons_dir, "scons.py")) args = [ proc.get_pythonexe_path(), script_path, "-Q", "--warn=no-no-parallel-support", "--jobs", str(jobs), "--sconstruct", os.path.join(fs.get_source_dir(), "builder", "main.py"), ] args.append("PIOVERBOSE=%d" % (1 if self.verbose else 0)) # pylint: disable=protected-access args.append("ISATTY=%d" % (1 if click._compat.isatty(sys.stdout) else 0)) args += targets # encode and append variables for key, value in variables.items(): args.append("%s=%s" % (key.upper(), self.encode_scons_arg(value))) proc.copy_pythonpath_to_osenv() if targets and "menuconfig" in targets: return proc.exec_command(args, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin) if click._compat.isatty(sys.stdout): def _write_and_flush(stream, data): try: stream.write(data) stream.flush() except IOError: pass return proc.exec_command( args, stdout=proc.BuildAsyncPipe( line_callback=self._on_stdout_line, data_callback=lambda data: None if self.silent else _write_and_flush(sys.stdout, data), ), stderr=proc.BuildAsyncPipe( line_callback=self._on_stderr_line, data_callback=lambda data: _write_and_flush( sys.stderr, data), ), ) return proc.exec_command( args, stdout=proc.LineBufferedAsyncPipe( line_callback=self._on_stdout_line), stderr=proc.LineBufferedAsyncPipe( line_callback=self._on_stderr_line), )