2018-04-07 01:23:03 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import codecs
|
2018-09-23 18:58:41 +02:00
|
|
|
import json
|
2018-10-14 18:52:21 +02:00
|
|
|
import logging
|
2018-04-07 01:23:03 +02:00
|
|
|
import os
|
2018-11-19 22:12:24 +01:00
|
|
|
import re
|
2018-10-14 18:52:21 +02:00
|
|
|
import shutil
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-04-18 18:43:13 +02:00
|
|
|
from esphomeyaml.config import iter_components
|
2018-11-19 22:12:24 +01:00
|
|
|
from esphomeyaml.const import ARDUINO_VERSION_ESP32_DEV, CONF_ARDUINO_VERSION, \
|
|
|
|
CONF_BOARD_FLASH_MODE, CONF_BRANCH, CONF_COMMIT, CONF_ESPHOMELIB_VERSION, CONF_ESPHOMEYAML, \
|
|
|
|
CONF_LOCAL, CONF_REPOSITORY, CONF_TAG, CONF_USE_CUSTOM_CODE
|
|
|
|
from esphomeyaml.core import CORE, EsphomeyamlError
|
2018-11-25 20:46:41 +01:00
|
|
|
from esphomeyaml.core_config import VERSION_REGEX, LIBRARY_URI_REPO, GITHUB_ARCHIVE_ZIP
|
2018-11-19 22:12:24 +01:00
|
|
|
from esphomeyaml.helpers import mkdir_p, run_system_command
|
|
|
|
from esphomeyaml.storage_json import StorageJSON, storage_path
|
|
|
|
from esphomeyaml.util import safe_print
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-10-14 18:52:21 +02:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
CPP_AUTO_GENERATE_BEGIN = u'// ========== AUTO GENERATED CODE BEGIN ==========='
|
|
|
|
CPP_AUTO_GENERATE_END = u'// =========== AUTO GENERATED CODE END ============'
|
2018-11-19 22:12:24 +01:00
|
|
|
CPP_INCLUDE_BEGIN = u'// ========== AUTO GENERATED INCLUDE BLOCK BEGIN ==========='
|
|
|
|
CPP_INCLUDE_END = u'// ========== AUTO GENERATED INCLUDE BLOCK END ==========='
|
2018-04-07 01:23:03 +02:00
|
|
|
INI_AUTO_GENERATE_BEGIN = u'; ========== AUTO GENERATED CODE BEGIN ==========='
|
|
|
|
INI_AUTO_GENERATE_END = u'; =========== AUTO GENERATED CODE END ============'
|
|
|
|
|
|
|
|
CPP_BASE_FORMAT = (u"""// Auto generated code by esphomeyaml
|
2018-11-19 22:12:24 +01:00
|
|
|
""", u""""
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
// ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
|
|
|
|
""", u"""
|
|
|
|
// ========= YOU CAN EDIT AFTER THIS LINE =========
|
|
|
|
App.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
App.loop();
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
|
|
|
|
INI_BASE_FORMAT = (u"""; Auto generated code by esphomeyaml
|
|
|
|
|
|
|
|
[common]
|
2018-04-10 17:17:46 +02:00
|
|
|
lib_deps =
|
|
|
|
build_flags =
|
|
|
|
upload_flags =
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
; ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
|
|
|
|
""", u"""
|
|
|
|
; ========= YOU CAN EDIT AFTER THIS LINE =========
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
INI_CONTENT_FORMAT = u"""[env:{env}]
|
|
|
|
platform = {platform}
|
|
|
|
board = {board}
|
|
|
|
framework = arduino
|
|
|
|
lib_deps =
|
2018-05-06 15:56:12 +02:00
|
|
|
{lib_deps}
|
2018-04-07 01:23:03 +02:00
|
|
|
${{common.lib_deps}}
|
2018-04-18 18:43:13 +02:00
|
|
|
build_flags =
|
|
|
|
{build_flags}
|
2018-04-07 01:23:03 +02:00
|
|
|
${{common.build_flags}}
|
2018-09-25 18:27:47 +02:00
|
|
|
upload_speed = {upload_speed}
|
2018-04-07 01:23:03 +02:00
|
|
|
"""
|
|
|
|
|
2018-09-25 18:27:47 +02:00
|
|
|
UPLOAD_SPEED_OVERRIDE = {
|
|
|
|
'esp210': 57600,
|
|
|
|
}
|
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def get_build_flags(key):
|
2018-04-18 18:43:13 +02:00
|
|
|
build_flags = set()
|
2018-11-19 22:12:24 +01:00
|
|
|
for _, component, conf in iter_components(CORE.config):
|
2018-04-18 18:43:13 +02:00
|
|
|
if not hasattr(component, key):
|
|
|
|
continue
|
2018-05-06 15:56:12 +02:00
|
|
|
flags = getattr(component, key)
|
|
|
|
if callable(flags):
|
|
|
|
flags = flags(conf)
|
2018-04-18 18:43:13 +02:00
|
|
|
if flags is None:
|
|
|
|
continue
|
|
|
|
if isinstance(flags, (str, unicode)):
|
|
|
|
flags = [flags]
|
|
|
|
build_flags |= set(flags)
|
|
|
|
return build_flags
|
|
|
|
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def get_include_text():
|
|
|
|
include_text = u'#include "esphomelib/application.h"\n' \
|
|
|
|
u'using namespace esphomelib;\n'
|
|
|
|
for _, component, conf in iter_components(CORE.config):
|
|
|
|
if not hasattr(component, 'includes'):
|
|
|
|
continue
|
|
|
|
includes = component.includes
|
|
|
|
if callable(includes):
|
|
|
|
includes = includes(conf)
|
|
|
|
if includes is None:
|
|
|
|
continue
|
|
|
|
if isinstance(includes, list):
|
|
|
|
includes = '\n'.join(includes)
|
|
|
|
if not includes:
|
|
|
|
continue
|
|
|
|
include_text += includes + '\n'
|
|
|
|
return include_text
|
2018-04-18 18:43:13 +02:00
|
|
|
|
2018-05-06 15:56:12 +02:00
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def update_esphomelib_repo():
|
|
|
|
if CONF_REPOSITORY not in CORE.esphomelib_version:
|
|
|
|
return
|
2018-09-23 18:58:41 +02:00
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
if CONF_BRANCH not in CORE.esphomelib_version:
|
|
|
|
# Git commit hash or tag cannot be updated
|
|
|
|
return
|
|
|
|
|
|
|
|
esphomelib_path = CORE.relative_build_path('.piolibdeps', 'esphomelib')
|
|
|
|
|
|
|
|
rc, _, _ = run_system_command('git', '-C', esphomelib_path, '--help')
|
|
|
|
if rc != 0:
|
|
|
|
# git not installed or repo not downloaded yet
|
|
|
|
return
|
|
|
|
rc, _, _ = run_system_command('git', '-C', esphomelib_path, 'diff-index', '--quiet', 'HEAD',
|
|
|
|
'--')
|
|
|
|
if rc != 0:
|
|
|
|
# local changes, cannot update
|
|
|
|
_LOGGER.warn("Local changes in esphomelib copy from git. Will not auto-update.")
|
|
|
|
return
|
|
|
|
_LOGGER.info("Updating esphomelib copy from git (%s)", esphomelib_path)
|
|
|
|
rc, stdout, _ = run_system_command('git', '-c', 'color.ui=always', '-C', esphomelib_path,
|
|
|
|
'pull', '--stat')
|
|
|
|
if rc != 0:
|
|
|
|
_LOGGER.warn("Couldn't auto-update local git copy of esphomelib.")
|
|
|
|
return
|
|
|
|
safe_print(stdout.strip())
|
|
|
|
|
|
|
|
|
|
|
|
def replace_file_content(text, pattern, repl):
|
|
|
|
content_new, count = re.subn(pattern, repl, text, flags=re.M)
|
|
|
|
return content_new, count
|
|
|
|
|
|
|
|
|
|
|
|
def migrate_src_version_0_to_1():
|
|
|
|
main_cpp = CORE.relative_build_path('src', 'main.cpp')
|
2018-11-25 21:04:47 +01:00
|
|
|
if not os.path.isfile(main_cpp):
|
|
|
|
return
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
with codecs.open(main_cpp, 'r', encoding='utf-8') as f_handle:
|
|
|
|
content = orig_content = f_handle.read()
|
|
|
|
|
|
|
|
content, count = replace_file_content(content, r'\s*delay\((?:16|20)\);', '')
|
|
|
|
if count != 0:
|
|
|
|
_LOGGER.info("Migration: Removed %s occurrence of 'delay(16);' in %s", count, main_cpp)
|
|
|
|
|
|
|
|
content, count = replace_file_content(content, r'using namespace esphomelib;', '')
|
|
|
|
if count != 0:
|
|
|
|
_LOGGER.info("Migration: Removed %s occurrence of 'using namespace esphomelib;' "
|
|
|
|
"in %s", count, main_cpp)
|
|
|
|
|
|
|
|
if CPP_INCLUDE_BEGIN not in content:
|
|
|
|
content, count = replace_file_content(content, r'#include "esphomelib/application.h"',
|
|
|
|
CPP_INCLUDE_BEGIN + u'\n' + CPP_INCLUDE_END)
|
|
|
|
if count == 0:
|
|
|
|
_LOGGER.error("Migration failed. esphomeyaml 1.10.0 needs to have a new auto-generated "
|
|
|
|
"include section in the %s file. Please remove %s and let it be "
|
|
|
|
"auto-generated again.", main_cpp, main_cpp)
|
|
|
|
_LOGGER.info("Migration: Added include section to %s", main_cpp)
|
|
|
|
|
|
|
|
if orig_content == content:
|
|
|
|
return
|
|
|
|
with codecs.open(main_cpp, 'w', encoding='utf-8') as f_handle:
|
|
|
|
f_handle.write(content)
|
|
|
|
|
|
|
|
|
|
|
|
def migrate_src_version(old, new):
|
|
|
|
if old == new:
|
|
|
|
return
|
|
|
|
if old > new:
|
|
|
|
_LOGGER.warning("The source version rolled backwards! Ignoring.")
|
|
|
|
return
|
|
|
|
|
|
|
|
if old == 0:
|
|
|
|
migrate_src_version_0_to_1()
|
|
|
|
|
|
|
|
|
2018-11-28 21:33:24 +01:00
|
|
|
def storage_should_clean(old, new): # type: (StorageJSON, StorageJSON) -> bool
|
|
|
|
if old is None:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if old.esphomelib_version != new.esphomelib_version:
|
|
|
|
return True
|
|
|
|
if old.esphomeyaml_version != new.esphomeyaml_version:
|
|
|
|
return True
|
|
|
|
if old.src_version != new.src_version:
|
|
|
|
return True
|
|
|
|
if old.arduino_version != new.arduino_version:
|
|
|
|
return True
|
|
|
|
if old.board != new.board:
|
|
|
|
return True
|
|
|
|
if old.build_path != new.build_path:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def update_storage_json():
|
|
|
|
path = storage_path()
|
|
|
|
old = StorageJSON.load(path)
|
2018-11-28 21:33:24 +01:00
|
|
|
new = StorageJSON.from_esphomeyaml_core(CORE, old)
|
2018-11-19 22:12:24 +01:00
|
|
|
if old == new:
|
|
|
|
return
|
|
|
|
|
|
|
|
old_src_version = old.src_version if old is not None else 0
|
|
|
|
migrate_src_version(old_src_version, new.src_version)
|
|
|
|
|
2018-11-28 21:33:24 +01:00
|
|
|
if storage_should_clean(old, new):
|
|
|
|
_LOGGER.info("Core config or version changed, cleaning build files...")
|
|
|
|
clean_build()
|
2018-11-19 22:12:24 +01:00
|
|
|
|
|
|
|
new.save(path)
|
|
|
|
|
|
|
|
|
|
|
|
def symlink_esphomelib_version(esphomelib_version):
|
|
|
|
lib_path = CORE.relative_build_path('lib')
|
|
|
|
dst_path = CORE.relative_build_path('lib', 'esphomelib')
|
|
|
|
if CORE.is_local_esphomelib_copy:
|
|
|
|
src_path = CORE.relative_path(esphomelib_version[CONF_LOCAL])
|
2018-09-23 18:58:41 +02:00
|
|
|
do_write = True
|
|
|
|
if os.path.islink(dst_path):
|
|
|
|
old_path = os.path.join(os.readlink(dst_path), lib_path)
|
|
|
|
if old_path != lib_path:
|
|
|
|
os.unlink(dst_path)
|
|
|
|
else:
|
|
|
|
do_write = False
|
|
|
|
if do_write:
|
|
|
|
mkdir_p(lib_path)
|
|
|
|
os.symlink(src_path, dst_path)
|
2018-11-19 22:12:24 +01:00
|
|
|
else:
|
|
|
|
# Remove symlink when changing back from local version
|
|
|
|
if os.path.islink(dst_path):
|
|
|
|
os.unlink(dst_path)
|
|
|
|
|
2018-09-23 18:58:41 +02:00
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def gather_lib_deps():
|
|
|
|
lib_deps = set()
|
|
|
|
esphomelib_version = CORE.config[CONF_ESPHOMEYAML][CONF_ESPHOMELIB_VERSION]
|
|
|
|
if CONF_REPOSITORY in esphomelib_version:
|
2018-11-25 20:46:41 +01:00
|
|
|
repo = esphomelib_version[CONF_REPOSITORY]
|
2018-11-19 22:12:24 +01:00
|
|
|
ref = next((esphomelib_version[x] for x in (CONF_COMMIT, CONF_BRANCH, CONF_TAG)
|
|
|
|
if x in esphomelib_version), None)
|
2018-11-25 20:46:41 +01:00
|
|
|
if CONF_TAG in esphomelib_version and repo == LIBRARY_URI_REPO:
|
|
|
|
this_version = GITHUB_ARCHIVE_ZIP.format(ref)
|
|
|
|
elif ref is not None:
|
|
|
|
this_version = repo + '#' + ref
|
2018-11-19 22:12:24 +01:00
|
|
|
lib_deps.add(this_version)
|
|
|
|
elif CORE.is_local_esphomelib_copy:
|
|
|
|
src_path = CORE.relative_path(esphomelib_version[CONF_LOCAL])
|
2018-09-23 18:58:41 +02:00
|
|
|
# Manually add lib_deps because platformio seems to ignore them inside libs/
|
|
|
|
library_json_path = os.path.join(src_path, 'library.json')
|
|
|
|
with codecs.open(library_json_path, 'r', encoding='utf-8') as f_handle:
|
|
|
|
library_json_text = f_handle.read()
|
|
|
|
|
|
|
|
library_json = json.loads(library_json_text)
|
|
|
|
for dep in library_json.get('dependencies', []):
|
|
|
|
if 'version' in dep and VERSION_REGEX.match(dep['version']) is not None:
|
|
|
|
lib_deps.add(dep['name'] + '@' + dep['version'])
|
|
|
|
else:
|
|
|
|
lib_deps.add(dep['version'])
|
2018-10-14 18:52:21 +02:00
|
|
|
else:
|
2018-11-19 22:12:24 +01:00
|
|
|
lib_deps.add(esphomelib_version)
|
2018-09-23 18:58:41 +02:00
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
lib_deps |= get_build_flags('LIB_DEPS')
|
|
|
|
lib_deps |= get_build_flags('lib_deps')
|
|
|
|
if CORE.is_esp32:
|
2018-05-06 15:56:12 +02:00
|
|
|
lib_deps |= {
|
2018-05-14 11:50:56 +02:00
|
|
|
'Preferences', # Preferences helper
|
2018-05-06 15:56:12 +02:00
|
|
|
}
|
2018-09-23 18:58:41 +02:00
|
|
|
# Manual fix for AsyncTCP
|
2018-11-19 22:12:24 +01:00
|
|
|
if CORE.config[CONF_ESPHOMEYAML].get(CONF_ARDUINO_VERSION) == ARDUINO_VERSION_ESP32_DEV:
|
2018-09-23 18:58:41 +02:00
|
|
|
lib_deps.add('https://github.com/me-no-dev/AsyncTCP.git#idf-update')
|
2018-05-14 11:50:56 +02:00
|
|
|
# avoid changing build flags order
|
2018-11-19 22:12:24 +01:00
|
|
|
return sorted(x for x in lib_deps if x)
|
2018-05-06 15:56:12 +02:00
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
|
|
|
|
def gather_build_flags():
|
|
|
|
build_flags = set()
|
|
|
|
if not CORE.config[CONF_ESPHOMEYAML][CONF_USE_CUSTOM_CODE]:
|
|
|
|
build_flags |= get_build_flags('build_flags')
|
|
|
|
build_flags |= get_build_flags('BUILD_FLAGS')
|
|
|
|
build_flags.add('-DESPHOMEYAML_USE')
|
|
|
|
build_flags.add("-Wno-unused-variable")
|
|
|
|
build_flags.add("-Wno-unused-but-set-variable")
|
|
|
|
build_flags |= get_build_flags('required_build_flags')
|
|
|
|
build_flags |= get_build_flags('REQUIRED_BUILD_FLAGS')
|
|
|
|
|
|
|
|
# avoid changing build flags order
|
|
|
|
return sorted(list(build_flags))
|
|
|
|
|
|
|
|
|
|
|
|
def get_ini_content():
|
|
|
|
version_specific_settings = determine_platformio_version_settings()
|
|
|
|
options = {
|
|
|
|
u'env': CORE.name,
|
|
|
|
u'platform': CORE.config[CONF_ESPHOMEYAML][CONF_ARDUINO_VERSION],
|
|
|
|
u'board': CORE.board,
|
|
|
|
u'build_flags': u'\n '.join(gather_build_flags()),
|
|
|
|
u'upload_speed': UPLOAD_SPEED_OVERRIDE.get(CORE.board, 115200),
|
|
|
|
u'lib_deps': u'\n '.join(gather_lib_deps()),
|
|
|
|
}
|
2018-05-16 19:45:33 +02:00
|
|
|
content = INI_CONTENT_FORMAT.format(**options)
|
2018-11-19 22:12:24 +01:00
|
|
|
if CONF_BOARD_FLASH_MODE in CORE.config[CONF_ESPHOMEYAML]:
|
2018-06-08 11:34:06 +02:00
|
|
|
flash_mode_key = version_specific_settings['flash_mode_key']
|
2018-11-19 22:12:24 +01:00
|
|
|
flash_mode = CORE.config[CONF_ESPHOMEYAML][CONF_BOARD_FLASH_MODE]
|
2018-06-08 11:34:06 +02:00
|
|
|
content += "{} = {}\n".format(flash_mode_key, flash_mode)
|
2018-05-16 19:45:33 +02:00
|
|
|
return content
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def find_begin_end(text, begin_s, end_s):
|
|
|
|
begin_index = text.find(begin_s)
|
|
|
|
if begin_index == -1:
|
2018-11-19 22:12:24 +01:00
|
|
|
raise EsphomeyamlError(u"Could not find auto generated code begin in file, either "
|
2018-04-07 01:23:03 +02:00
|
|
|
u"delete the main sketch file or insert the comment again.")
|
|
|
|
if text.find(begin_s, begin_index + 1) != -1:
|
2018-11-19 22:12:24 +01:00
|
|
|
raise EsphomeyamlError(u"Found multiple auto generate code begins, don't know "
|
2018-04-07 01:23:03 +02:00
|
|
|
u"which to chose, please remove one of them.")
|
|
|
|
end_index = text.find(end_s)
|
|
|
|
if end_index == -1:
|
2018-11-19 22:12:24 +01:00
|
|
|
raise EsphomeyamlError(u"Could not find auto generated code end in file, either "
|
2018-04-07 01:23:03 +02:00
|
|
|
u"delete the main sketch file or insert the comment again.")
|
|
|
|
if text.find(end_s, end_index + 1) != -1:
|
2018-11-19 22:12:24 +01:00
|
|
|
raise EsphomeyamlError(u"Found multiple auto generate code endings, don't know "
|
2018-04-07 01:23:03 +02:00
|
|
|
u"which to chose, please remove one of them.")
|
|
|
|
|
|
|
|
return text[:begin_index], text[(end_index + len(end_s)):]
|
|
|
|
|
|
|
|
|
|
|
|
def write_platformio_ini(content, path):
|
2018-11-19 22:12:24 +01:00
|
|
|
symlink_esphomelib_version(CORE.esphomelib_version)
|
|
|
|
update_esphomelib_repo()
|
|
|
|
update_storage_json()
|
|
|
|
|
2018-04-07 01:23:03 +02:00
|
|
|
if os.path.isfile(path):
|
|
|
|
try:
|
2018-04-10 17:17:46 +02:00
|
|
|
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
|
|
|
text = f_handle.read()
|
2018-04-07 01:23:03 +02:00
|
|
|
except OSError:
|
2018-11-19 22:12:24 +01:00
|
|
|
raise EsphomeyamlError(u"Could not read ini file at {}".format(path))
|
2018-04-07 01:23:03 +02:00
|
|
|
prev_file = text
|
|
|
|
content_format = find_begin_end(text, INI_AUTO_GENERATE_BEGIN, INI_AUTO_GENERATE_END)
|
|
|
|
else:
|
|
|
|
prev_file = None
|
|
|
|
content_format = INI_BASE_FORMAT
|
2018-11-23 18:57:13 +01:00
|
|
|
full_file = content_format[0] + INI_AUTO_GENERATE_BEGIN + '\n' + content
|
|
|
|
full_file += INI_AUTO_GENERATE_END + content_format[1]
|
2018-04-07 01:23:03 +02:00
|
|
|
if prev_file == full_file:
|
|
|
|
return
|
2018-04-10 17:17:46 +02:00
|
|
|
with codecs.open(path, mode='w+', encoding='utf-8') as f_handle:
|
|
|
|
f_handle.write(full_file)
|
2018-04-07 01:23:03 +02:00
|
|
|
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def write_platformio_project():
|
|
|
|
mkdir_p(CORE.build_path)
|
|
|
|
|
|
|
|
platformio_ini = CORE.relative_build_path('platformio.ini')
|
|
|
|
content = get_ini_content()
|
|
|
|
if 'esp32_ble_beacon' in CORE.config or 'esp32_ble_tracker' in CORE.config:
|
2018-06-12 21:18:04 +02:00
|
|
|
content += 'board_build.partitions = partitions.csv\n'
|
2018-11-19 22:12:24 +01:00
|
|
|
partitions_csv = CORE.relative_build_path('partitions.csv')
|
2018-06-12 21:18:04 +02:00
|
|
|
if not os.path.isfile(partitions_csv):
|
|
|
|
with open(partitions_csv, "w") as f:
|
|
|
|
f.write("nvs, data, nvs, 0x009000, 0x005000,\n")
|
|
|
|
f.write("otadata, data, ota, 0x00e000, 0x002000,\n")
|
|
|
|
f.write("app0, app, ota_0, 0x010000, 0x190000,\n")
|
|
|
|
f.write("app1, app, ota_1, 0x200000, 0x190000,\n")
|
|
|
|
f.write("eeprom, data, 0x99, 0x390000, 0x001000,\n")
|
|
|
|
f.write("spiffs, data, spiffs, 0x391000, 0x00F000\n")
|
|
|
|
write_platformio_ini(content, platformio_ini)
|
|
|
|
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def write_cpp(code_s):
|
|
|
|
path = CORE.relative_build_path('src', 'main.cpp')
|
2018-04-07 01:23:03 +02:00
|
|
|
if os.path.isfile(path):
|
|
|
|
try:
|
2018-04-10 17:17:46 +02:00
|
|
|
with codecs.open(path, 'r', encoding='utf-8') as f_handle:
|
|
|
|
text = f_handle.read()
|
2018-04-07 01:23:03 +02:00
|
|
|
except OSError:
|
2018-11-19 22:12:24 +01:00
|
|
|
raise EsphomeyamlError(u"Could not read C++ file at {}".format(path))
|
2018-04-07 01:23:03 +02:00
|
|
|
prev_file = text
|
|
|
|
code_format = find_begin_end(text, CPP_AUTO_GENERATE_BEGIN, CPP_AUTO_GENERATE_END)
|
2018-11-19 22:12:24 +01:00
|
|
|
code_format_ = find_begin_end(code_format[0], CPP_INCLUDE_BEGIN, CPP_INCLUDE_END)
|
|
|
|
code_format = (code_format_[0], code_format_[1], code_format[1])
|
2018-04-07 01:23:03 +02:00
|
|
|
else:
|
|
|
|
prev_file = None
|
|
|
|
mkdir_p(os.path.dirname(path))
|
|
|
|
code_format = CPP_BASE_FORMAT
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
include_s = get_include_text()
|
|
|
|
|
2018-11-23 18:57:13 +01:00
|
|
|
full_file = code_format[0] + CPP_INCLUDE_BEGIN + u'\n' + include_s + CPP_INCLUDE_END
|
|
|
|
full_file += code_format[1] + CPP_AUTO_GENERATE_BEGIN + u'\n' + code_s + CPP_AUTO_GENERATE_END
|
|
|
|
full_file += code_format[2]
|
2018-04-07 01:23:03 +02:00
|
|
|
if prev_file == full_file:
|
|
|
|
return
|
2018-04-10 17:17:46 +02:00
|
|
|
with codecs.open(path, 'w+', encoding='utf-8') as f_handle:
|
|
|
|
f_handle.write(full_file)
|
2018-06-08 11:34:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def determine_platformio_version_settings():
|
|
|
|
import platformio
|
|
|
|
|
|
|
|
settings = {}
|
|
|
|
|
|
|
|
if platformio.VERSION < (3, 5, 3):
|
|
|
|
settings['flash_mode_key'] = 'board_flash_mode'
|
|
|
|
else:
|
|
|
|
settings['flash_mode_key'] = 'board_build.flash_mode'
|
|
|
|
|
|
|
|
return settings
|
2018-10-14 18:52:21 +02:00
|
|
|
|
|
|
|
|
2018-11-19 22:12:24 +01:00
|
|
|
def clean_build():
|
2018-10-14 18:52:21 +02:00
|
|
|
for directory in ('.piolibdeps', '.pioenvs'):
|
2018-11-19 22:12:24 +01:00
|
|
|
dir_path = CORE.relative_build_path(directory)
|
|
|
|
if not os.path.isdir(dir_path):
|
|
|
|
continue
|
|
|
|
_LOGGER.info("Deleting %s", dir_path)
|
|
|
|
shutil.rmtree(dir_path)
|