forked from platformio/platformio-core
Better support for file contents writing // Issue #2796
This commit is contained in:
@@ -41,12 +41,7 @@ from SCons.Script import DefaultEnvironment # pylint: disable=import-error
|
||||
|
||||
from platformio import exception, fs, util
|
||||
from platformio.builder.tools import platformio as piotool
|
||||
from platformio.compat import (
|
||||
WINDOWS,
|
||||
get_file_contents,
|
||||
hashlib_encode_data,
|
||||
string_types,
|
||||
)
|
||||
from platformio.compat import WINDOWS, hashlib_encode_data, string_types
|
||||
from platformio.managers.lib import LibraryManager
|
||||
|
||||
|
||||
@@ -92,7 +87,7 @@ class LibBuilderFactory(object):
|
||||
fname, piotool.SRC_BUILD_EXT + piotool.SRC_HEADER_EXT
|
||||
):
|
||||
continue
|
||||
content = get_file_contents(join(root, fname))
|
||||
content = fs.get_file_contents(join(root, fname))
|
||||
if not content:
|
||||
continue
|
||||
if "Arduino.h" in content and include_re.search(content):
|
||||
@@ -1047,22 +1042,22 @@ def ConfigureProjectLibBuilder(env):
|
||||
title += " %s" % lb.version
|
||||
if vcs_info and vcs_info.get("version"):
|
||||
title += " #%s" % vcs_info.get("version")
|
||||
sys.stdout.write("%s|-- %s" % (margin, title))
|
||||
click.echo("%s|-- %s" % (margin, title), nl=False)
|
||||
if int(ARGUMENTS.get("PIOVERBOSE", 0)):
|
||||
if vcs_info:
|
||||
sys.stdout.write(" [%s]" % vcs_info.get("url"))
|
||||
sys.stdout.write(" (")
|
||||
sys.stdout.write(lb.path)
|
||||
sys.stdout.write(")")
|
||||
sys.stdout.write("\n")
|
||||
click.echo(" [%s]" % vcs_info.get("url"), nl=False)
|
||||
click.echo(" (", nl=False)
|
||||
click.echo(lb.path, nl=False)
|
||||
click.echo(")", nl=False)
|
||||
click.echo("")
|
||||
if lb.depbuilders:
|
||||
_print_deps_tree(lb, level + 1)
|
||||
|
||||
project = ProjectAsLibBuilder(env, "$PROJECT_DIR")
|
||||
ldf_mode = LibBuilderBase.lib_ldf_mode.fget(project)
|
||||
|
||||
print ("LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf")
|
||||
print (
|
||||
click.echo("LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf")
|
||||
click.echo(
|
||||
"LDF Modes: Finder ~ %s, Compatibility ~ %s"
|
||||
% (ldf_mode, project.lib_compat_mode)
|
||||
)
|
||||
@@ -1070,19 +1065,19 @@ def ConfigureProjectLibBuilder(env):
|
||||
project.install_dependencies()
|
||||
|
||||
lib_builders = env.GetLibBuilders()
|
||||
print ("Found %d compatible libraries" % len(lib_builders))
|
||||
click.echo("Found %d compatible libraries" % len(lib_builders))
|
||||
|
||||
print ("Scanning dependencies...")
|
||||
click.echo("Scanning dependencies...")
|
||||
project.search_deps_recursive()
|
||||
|
||||
if ldf_mode.startswith("chain") and project.depbuilders:
|
||||
_correct_found_libs(lib_builders)
|
||||
|
||||
if project.depbuilders:
|
||||
print ("Dependency Graph")
|
||||
click.echo("Dependency Graph")
|
||||
_print_deps_tree(project)
|
||||
else:
|
||||
print ("No dependencies")
|
||||
click.echo("No dependencies")
|
||||
|
||||
return project
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ from hashlib import md5
|
||||
from os import makedirs
|
||||
from os.path import isdir, isfile, join
|
||||
|
||||
from platformio import fs
|
||||
from platformio.compat import WINDOWS, hashlib_encode_data
|
||||
|
||||
# Windows CLI has limit with command length to 8192
|
||||
@@ -66,8 +67,7 @@ def _file_long_data(env, data):
|
||||
)
|
||||
if isfile(tmp_file):
|
||||
return tmp_file
|
||||
with open(tmp_file, "w") as fp:
|
||||
fp.write(data)
|
||||
fs.write_file_contents(tmp_file, data)
|
||||
return tmp_file
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ from SCons.Action import Action # pylint: disable=import-error
|
||||
from SCons.Script import ARGUMENTS # pylint: disable=import-error
|
||||
|
||||
from platformio import fs, util
|
||||
from platformio.compat import get_file_contents, glob_escape
|
||||
from platformio.compat import glob_escape
|
||||
from platformio.managers.core import get_core_package_dir
|
||||
from platformio.proc import exec_command
|
||||
|
||||
@@ -62,7 +62,7 @@ class InoToCPPConverter(object):
|
||||
assert nodes
|
||||
lines = []
|
||||
for node in nodes:
|
||||
contents = get_file_contents(node.get_path())
|
||||
contents = fs.get_file_contents(node.get_path())
|
||||
_lines = ['# 1 "%s"' % node.get_path().replace("\\", "/"), contents]
|
||||
if self.is_main_node(contents):
|
||||
lines = _lines + lines
|
||||
@@ -78,16 +78,14 @@ class InoToCPPConverter(object):
|
||||
def process(self, contents):
|
||||
out_file = self._main_ino + ".cpp"
|
||||
assert self._gcc_preprocess(contents, out_file)
|
||||
contents = get_file_contents(out_file)
|
||||
contents = fs.get_file_contents(out_file)
|
||||
contents = self._join_multiline_strings(contents)
|
||||
with open(out_file, "w") as fp:
|
||||
fp.write(self.append_prototypes(contents))
|
||||
fs.write_file_contents(out_file, self.append_prototypes(contents))
|
||||
return out_file
|
||||
|
||||
def _gcc_preprocess(self, contents, out_file):
|
||||
tmp_path = mkstemp()[1]
|
||||
with open(tmp_path, "w") as fp:
|
||||
fp.write(contents)
|
||||
fs.write_file_contents(tmp_path, contents)
|
||||
self.env.Execute(
|
||||
self.env.VerboseAction(
|
||||
'$CXX -o "{0}" -x c++ -fpreprocessed -dD -E "{1}"'.format(
|
||||
|
||||
Reference in New Issue
Block a user