Move default build path to .esphome directory (#2586)

This commit is contained in:
Otto Winter 2021-10-23 12:38:57 +02:00 committed by GitHub
parent d85b7a6bd0
commit 1a6a063e04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 75 deletions

View file

@ -165,7 +165,7 @@ def preload_core_config(config, result):
CORE.data[KEY_CORE] = {} CORE.data[KEY_CORE] = {}
if CONF_BUILD_PATH not in conf: if CONF_BUILD_PATH not in conf:
conf[CONF_BUILD_PATH] = CORE.name conf[CONF_BUILD_PATH] = f".esphome/build/{CORE.name}"
CORE.build_path = CORE.relative_config_path(conf[CONF_BUILD_PATH]) CORE.build_path = CORE.relative_config_path(conf[CONF_BUILD_PATH])
has_oldstyle = CONF_PLATFORM in conf has_oldstyle = CONF_PLATFORM in conf

View file

@ -125,7 +125,7 @@ def _run_idedata(config):
def _load_idedata(config): def _load_idedata(config):
platformio_ini = Path(CORE.relative_build_path("platformio.ini")) platformio_ini = Path(CORE.relative_build_path("platformio.ini"))
temp_idedata = Path(CORE.relative_internal_path(CORE.name, "idedata.json")) temp_idedata = Path(CORE.relative_internal_path("idedata", f"{CORE.name}.json"))
changed = False changed = False
if not platformio_ini.is_file() or not temp_idedata.is_file(): if not platformio_ini.is_file() or not temp_idedata.is_file():

View file

@ -38,10 +38,8 @@ CPP_BASE_FORMAT = (
"""" """"
void setup() { void setup() {
// ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
""", """,
""" """
// ========= YOU CAN EDIT AFTER THIS LINE =========
App.setup(); App.setup();
} }
@ -59,10 +57,8 @@ lib_deps =
build_flags = build_flags =
upload_flags = upload_flags =
; ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
""", """,
""" """
; ========= YOU CAN EDIT AFTER THIS LINE =========
""", """,
) )
@ -102,61 +98,6 @@ def replace_file_content(text, pattern, repl):
return content_new, count return content_new, count
def migrate_src_version_0_to_1():
main_cpp = CORE.relative_build_path("src", "main.cpp")
if not os.path.isfile(main_cpp):
return
content = read_file(main_cpp)
if CPP_INCLUDE_BEGIN in content:
return
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"',
f"{CPP_INCLUDE_BEGIN}\n{CPP_INCLUDE_END}",
)
if count == 0:
_LOGGER.error(
"Migration failed. ESPHome 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)
write_file_if_changed(main_cpp, 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()
def storage_should_clean(old, new): # type: (StorageJSON, StorageJSON) -> bool def storage_should_clean(old, new): # type: (StorageJSON, StorageJSON) -> bool
if old is None: if old is None:
return True return True
@ -175,9 +116,6 @@ def update_storage_json():
if old == new: if old == new:
return return
old_src_version = old.src_version if old is not None else 0
migrate_src_version(old_src_version, new.src_version)
if storage_should_clean(old, new): if storage_should_clean(old, new):
_LOGGER.info("Core config or version changed, cleaning build files...") _LOGGER.info("Core config or version changed, cleaning build files...")
clean_build() clean_build()
@ -277,12 +215,12 @@ VERSION_H_TARGET = "esphome/core/version.h"
ESPHOME_README_TXT = """ ESPHOME_README_TXT = """
THIS DIRECTORY IS AUTO-GENERATED, DO NOT MODIFY THIS DIRECTORY IS AUTO-GENERATED, DO NOT MODIFY
ESPHome automatically populates the esphome/ directory, and any ESPHome automatically populates the build directory, and any
changes to this directory will be removed the next time esphome is changes to this directory will be removed the next time esphome is
run. run.
For modifying esphome's core files, please use a development esphome install For modifying esphome's core files, please use a development esphome install,
or use the custom_components folder. the custom_components folder or the external_components feature.
""" """
@ -339,9 +277,7 @@ def copy_src_tree():
write_file_if_changed( write_file_if_changed(
CORE.relative_src_path("esphome", "core", "defines.h"), generate_defines_h() CORE.relative_src_path("esphome", "core", "defines.h"), generate_defines_h()
) )
write_file_if_changed( write_file_if_changed(CORE.relative_build_path("README.txt"), ESPHOME_README_TXT)
CORE.relative_src_path("esphome", "README.txt"), ESPHOME_README_TXT
)
write_file_if_changed( write_file_if_changed(
CORE.relative_src_path("esphome.h"), ESPHOME_H_FORMAT.format(include_s) CORE.relative_src_path("esphome.h"), ESPHOME_H_FORMAT.format(include_s)
) )
@ -413,11 +349,6 @@ GITIGNORE_CONTENT = """# Gitignore settings for ESPHome
# This is an example and may include too much for your use-case. # This is an example and may include too much for your use-case.
# You can modify this file to suit your needs. # You can modify this file to suit your needs.
/.esphome/ /.esphome/
**/.pioenvs/
**/.piolibdeps/
**/lib/
**/src/
**/platformio.ini
/secrets.yaml /secrets.yaml
""" """