From d324a6c9e68a1380ab9edacde70efebfcd032553 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Mon, 23 Feb 2026 13:43:10 -0500 Subject: [PATCH] [core] Move build_info_data.h out of application.h to fix incremental rebuilds build_info_data.h contains ESPHOME_BUILD_TIME which changes every build. Since application.h included it, changing any source file caused build_info_data.h to be rewritten (via sources_changed), which then triggered a rebuild of every file that includes application.h. Move all build_info_data.h dependent code from application.h inline methods to application.cpp, so only application.cpp recompiles when build info changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- esphome/components/web_server/web_server.cpp | 5 +++-- esphome/core/application.cpp | 15 +++++++-------- esphome/core/application.h | 11 +++++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index 909625288b..fab701d5f1 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -4,7 +4,6 @@ #include "esphome/core/progmem.h" #include "esphome/components/network/util.h" #include "esphome/core/application.h" -#include "esphome/core/build_info_data.h" #include "esphome/core/defines.h" #include "esphome/core/controller_registry.h" #include "esphome/core/entity_base.h" @@ -376,7 +375,9 @@ json::SerializationBuffer<> WebServer::get_config_json() { JsonObject root = builder.root(); root[ESPHOME_F("title")] = App.get_friendly_name().empty() ? App.get_name().c_str() : App.get_friendly_name().c_str(); - root[ESPHOME_F("comment")] = ESPHOME_COMMENT_STR; + char comment_buffer[Application::COMMENT_MAX_SIZE]; + App.get_comment_string(comment_buffer); + root[ESPHOME_F("comment")] = comment_buffer; #if defined(USE_WEBSERVER_OTA_DISABLED) || !defined(USE_WEBSERVER_OTA) root[ESPHOME_F("ota")] = false; // Note: USE_WEBSERVER_OTA_DISABLED only affects web_server, not captive_portal #else diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index 4d0a582f14..0bdfa2b586 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -215,7 +215,8 @@ void Application::loop() { void Application::process_dump_config_() { if (this->dump_config_at_ == 0) { char build_time_str[Application::BUILD_TIME_STR_SIZE]; - this->get_build_time_string(build_time_str); + ESPHOME_strncpy_P(build_time_str, ESPHOME_BUILD_TIME_STR, sizeof(build_time_str)); + build_time_str[sizeof(build_time_str) - 1] = '\0'; ESP_LOGI(TAG, "ESPHome version " ESPHOME_VERSION " compiled on %s", build_time_str); #ifdef ESPHOME_PROJECT_NAME ESP_LOGI(TAG, "Project " ESPHOME_PROJECT_NAME " version " ESPHOME_PROJECT_VERSION); @@ -749,16 +750,14 @@ void Application::get_build_time_string(std::span buf buffer[buffer.size() - 1] = '\0'; } -size_t Application::get_comment_size() { return ESPHOME_COMMENT_SIZE; } - -void Application::get_comment_string(char *buffer, size_t size) { - ESPHOME_strncpy_P(buffer, ESPHOME_COMMENT_STR, size); - buffer[size - 1] = '\0'; +void Application::get_comment_string(std::span buffer) { + ESPHOME_strncpy_P(buffer.data(), ESPHOME_COMMENT_STR, buffer.size()); + buffer[buffer.size() - 1] = '\0'; } std::string Application::get_comment() { - char buffer[ESPHOME_COMMENT_SIZE]; - this->get_comment_string(buffer, sizeof(buffer)); + char buffer[COMMENT_MAX_SIZE]; + this->get_comment_string(buffer); return std::string(buffer); } diff --git a/esphome/core/application.h b/esphome/core/application.h index 625c0a3304..56fa690cbe 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -273,11 +273,11 @@ class Application { return ""; } - /// Get the size of the comment buffer (including null terminator) - static size_t get_comment_size(); + /// Maximum size of the comment buffer (including null terminator) + static constexpr size_t COMMENT_MAX_SIZE = 256; - /// Copy the comment string into the provided buffer - void get_comment_string(char *buffer, size_t size); + /// Get the comment string (PROGMEM-safe, copies to buffer) + void get_comment_string(std::span buffer); /// Get the comment of this Application as a string std::string get_comment(); @@ -296,8 +296,7 @@ class Application { /// Get the build time as a Unix timestamp time_t get_build_time(); - /// Copy the build time string into the provided buffer - /// Buffer must be BUILD_TIME_STR_SIZE bytes + /// Get the build time string (PROGMEM-safe, copies to buffer) void get_build_time_string(std::span buffer); /// Get the build time as a string (deprecated, use get_build_time_string() instead)