[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>
This commit is contained in:
Jonathan Swoboda
2026-02-23 13:43:10 -05:00
parent e199145f1c
commit bea70b6cd2
4 changed files with 40 additions and 24 deletions

View File

@@ -25,7 +25,9 @@ void VersionTextSensor::setup() {
if (!this->hide_timestamp_) {
size_t len = strlen(version_str);
ESPHOME_strncat_P(version_str, BUILT_STR, sizeof(version_str) - len - 1);
ESPHOME_strncat_P(version_str, ESPHOME_BUILD_TIME_STR, sizeof(version_str) - strlen(version_str) - 1);
char time_buf[esphome::Application::BUILD_TIME_STR_SIZE];
App.get_build_time_string(time_buf);
strncat(version_str, time_buf, sizeof(version_str) - strlen(version_str) - 1);
}
strncat(version_str, ")", sizeof(version_str) - strlen(version_str) - 1);

View File

@@ -375,9 +375,8 @@ 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();
char comment_buffer[ESPHOME_COMMENT_SIZE];
App.get_comment_string(comment_buffer);
root[ESPHOME_F("comment")] = comment_buffer;
auto comment = App.get_comment();
root[ESPHOME_F("comment")] = comment.c_str();
#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

View File

@@ -749,4 +749,29 @@ void Application::get_build_time_string(std::span<char, BUILD_TIME_STR_SIZE> 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';
}
std::string Application::get_comment() {
char buffer[ESPHOME_COMMENT_SIZE];
this->get_comment_string(buffer, sizeof(buffer));
return std::string(buffer);
}
uint32_t Application::get_config_hash() { return ESPHOME_CONFIG_HASH; }
uint32_t Application::get_config_version_hash() { return fnv1a_hash_extend(ESPHOME_CONFIG_HASH, ESPHOME_VERSION); }
time_t Application::get_build_time() { return ESPHOME_BUILD_TIME; }
std::string Application::get_compilation_time() {
char buf[BUILD_TIME_STR_SIZE];
this->get_build_time_string(buf);
return std::string(buf);
}
} // namespace esphome

View File

@@ -6,7 +6,6 @@
#include <span>
#include <string>
#include <vector>
#include "esphome/core/build_info_data.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/hal.h"
@@ -274,19 +273,14 @@ class Application {
return "";
}
/// Get the size of the comment buffer (including null terminator)
static size_t get_comment_size();
/// Copy the comment string into the provided buffer
/// Buffer must be ESPHOME_COMMENT_SIZE bytes (compile-time enforced)
void get_comment_string(std::span<char, ESPHOME_COMMENT_SIZE> buffer) {
ESPHOME_strncpy_P(buffer.data(), ESPHOME_COMMENT_STR, buffer.size());
buffer[buffer.size() - 1] = '\0';
}
void get_comment_string(char *buffer, size_t size);
/// Get the comment of this Application as a string
std::string get_comment() {
char buffer[ESPHOME_COMMENT_SIZE];
this->get_comment_string(buffer);
return std::string(buffer);
}
std::string get_comment();
bool is_name_add_mac_suffix_enabled() const { return this->name_add_mac_suffix_; }
@@ -294,26 +288,22 @@ class Application {
static constexpr size_t BUILD_TIME_STR_SIZE = 26;
/// Get the config hash as a 32-bit integer
constexpr uint32_t get_config_hash() { return ESPHOME_CONFIG_HASH; }
uint32_t get_config_hash();
/// Get the config hash extended with ESPHome version
constexpr uint32_t get_config_version_hash() { return fnv1a_hash_extend(ESPHOME_CONFIG_HASH, ESPHOME_VERSION); }
uint32_t get_config_version_hash();
/// Get the build time as a Unix timestamp
constexpr time_t get_build_time() { return ESPHOME_BUILD_TIME; }
time_t get_build_time();
/// Copy the build time string into the provided buffer
/// Buffer must be BUILD_TIME_STR_SIZE bytes (compile-time enforced)
/// Buffer must be BUILD_TIME_STR_SIZE bytes
void get_build_time_string(std::span<char, BUILD_TIME_STR_SIZE> buffer);
/// Get the build time as a string (deprecated, use get_build_time_string() instead)
// Remove before 2026.7.0
ESPDEPRECATED("Use get_build_time_string() instead. Removed in 2026.7.0", "2026.1.0")
std::string get_compilation_time() {
char buf[BUILD_TIME_STR_SIZE];
this->get_build_time_string(buf);
return std::string(buf);
}
std::string get_compilation_time();
/// Get the cached time in milliseconds from when the current component started its loop execution
inline uint32_t IRAM_ATTR HOT get_loop_component_start_time() const { return this->loop_component_start_time_; }