Skip to content

Commit

Permalink
[pio] Revert: [hack] Replace long lines for windows only
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kozhevnikov committed Feb 10, 2021
1 parent 9b28455 commit bc4c295
Showing 1 changed file with 0 additions and 79 deletions.
79 changes: 0 additions & 79 deletions extra_script.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,4 @@
Import("env")

# Command line is too long workaround
from hashlib import md5
from os import makedirs
from os.path import isdir, isfile, join

from platformio.compat import WINDOWS, hashlib_encode_data

# Windows CLI has limit with command length to 8192
# Leave 2000 chars for flags and other options
MAX_LINE_LENGTH = 2000


def long_sources_hook(env, sources):
_sources = str(sources).replace("\\", "/")
if len(str(_sources)) < MAX_LINE_LENGTH:
return sources

# fix space in paths
data = []
for line in _sources.split(".o "):
line = line.strip()
if not line.endswith(".o"):
line += ".o"
data.append('"%s"' % line)

return '@"%s"' % _file_long_data(env, " ".join(data))


def long_incflags_hook(env, incflags):
_incflags = env.subst(incflags).replace("\\", "/")
if len(_incflags) < MAX_LINE_LENGTH:
return incflags

# fix space in paths
data = []
for line in _incflags.split(" -I"):
line = line.strip()
if not line.startswith("-I"):
line = "-I" + line
data.append('-I"%s"' % line[2:])

return '@"%s"' % _file_long_data(env, " ".join(data))


def _file_long_data(env, data):
build_dir = env.subst("$BUILD_DIR")
if not isdir(build_dir):
makedirs(build_dir)
tmp_file = join(
build_dir, "longcmd-%s" % md5(hashlib_encode_data(data)).hexdigest()
)
if isfile(tmp_file):
return tmp_file
with open(tmp_file, "w") as fp:
fp.write(data)
return tmp_file


def exists(_):
return True


def generate():
env.Replace(_long_sources_hook=long_sources_hook)
env.Replace(_long_incflags_hook=long_incflags_hook)
coms = {}
for key in ("ARCOM", "LINKCOM"):
coms[key] = env.get(key, "").replace(
"$SOURCES", "${_long_sources_hook(__env__, SOURCES)}"
)
for key in ("_CCCOMCOM", "ASPPCOM"):
coms[key] = env.get(key, "").replace(
"$_CPPINCFLAGS", "${_long_incflags_hook(__env__, _CPPINCFLAGS)}"
)
env.Replace(**coms)

if WINDOWS:
generate()

# Rename littlefs.bin to fs.bin
env.Replace(ESP8266_FS_IMAGE_NAME="fs")

0 comments on commit bc4c295

Please sign in to comment.