unified way how all platforms handle copy_files (#7614)

Co-authored-by: Tomasz Duda <tomaszduda23@gmai.com>
This commit is contained in:
tomaszduda23 2024-10-23 23:04:59 +02:00 committed by GitHub
parent bff0e81ed3
commit 9acc21e81a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 21 deletions

View File

@ -17,7 +17,7 @@ from esphome.const import (
PLATFORM_RP2040,
)
from esphome.core import CORE, EsphomeError, coroutine_with_priority
from esphome.helpers import copy_file_if_changed, mkdir_p, write_file
from esphome.helpers import copy_file_if_changed, mkdir_p, write_file, read_file
from .const import KEY_BOARD, KEY_PIO_FILES, KEY_RP2040, rp2040_ns
@ -230,11 +230,14 @@ def generate_pio_files() -> bool:
# Called by writer.py
def copy_files() -> bool:
def copy_files():
dir = os.path.dirname(__file__)
post_build_file = os.path.join(dir, "post_build.py.script")
copy_file_if_changed(
post_build_file,
CORE.relative_build_path("post_build.py"),
)
return generate_pio_files()
if generate_pio_files():
path = CORE.relative_src_path("esphome.h")
content = read_file(path).rstrip("\n")
write_file(path, content + '\n#include "pio_includes.h"\n')

View File

@ -1,3 +1,4 @@
import importlib
import logging
import os
from pathlib import Path
@ -299,25 +300,13 @@ def copy_src_tree():
CORE.relative_src_path("esphome", "core", "version.h"), generate_version_h()
)
if CORE.is_esp32:
from esphome.components.esp32 import copy_files
platform = "esphome.components." + CORE.target_platform
try:
module = importlib.import_module(platform)
copy_files = getattr(module, "copy_files")
copy_files()
elif CORE.is_esp8266:
from esphome.components.esp8266 import copy_files
copy_files()
elif CORE.is_rp2040:
from esphome.components.rp2040 import copy_files
(pio) = copy_files()
if pio:
write_file_if_changed(
CORE.relative_src_path("esphome.h"),
ESPHOME_H_FORMAT.format(include_s + '\n#include "pio_includes.h"'),
)
except AttributeError:
pass
def generate_defines_h():