mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 04:28:43 +00:00
Merge remote-tracking branch 'upstream/dev' into pack-entity-strings
# Conflicts: # esphome/components/rp2040/core.cpp
This commit is contained in:
@@ -1913,6 +1913,37 @@ def build_type_usage_map(
|
||||
)
|
||||
|
||||
|
||||
def get_varint64_ifdef(
|
||||
file_desc: descriptor.FileDescriptorProto,
|
||||
message_ifdef_map: dict[str, str | None],
|
||||
) -> tuple[bool, str | None]:
|
||||
"""Check if 64-bit varint fields exist and get their common ifdef guard.
|
||||
|
||||
Returns:
|
||||
(has_varint64, ifdef_guard) - has_varint64 is True if any fields exist,
|
||||
ifdef_guard is the common guard or None if unconditional.
|
||||
"""
|
||||
varint64_types = {
|
||||
FieldDescriptorProto.TYPE_INT64,
|
||||
FieldDescriptorProto.TYPE_UINT64,
|
||||
FieldDescriptorProto.TYPE_SINT64,
|
||||
}
|
||||
ifdefs: set[str | None] = {
|
||||
message_ifdef_map.get(msg.name)
|
||||
for msg in file_desc.message_type
|
||||
if not msg.options.deprecated
|
||||
for field in msg.field
|
||||
if not field.options.deprecated and field.type in varint64_types
|
||||
}
|
||||
if not ifdefs:
|
||||
return False, None
|
||||
if None in ifdefs:
|
||||
# At least one 64-bit varint field is unconditional, so the guard must be unconditional.
|
||||
return True, None
|
||||
ifdefs.discard(None)
|
||||
return True, ifdefs.pop() if len(ifdefs) == 1 else None
|
||||
|
||||
|
||||
def build_enum_type(desc, enum_ifdef_map) -> tuple[str, str, str]:
|
||||
"""Builds the enum type.
|
||||
|
||||
@@ -2567,11 +2598,38 @@ def main() -> None:
|
||||
|
||||
file = d.file[0]
|
||||
|
||||
# Build dynamic ifdef mappings early so we can emit USE_API_VARINT64 before includes
|
||||
enum_ifdef_map, message_ifdef_map, message_source_map, used_messages = (
|
||||
build_type_usage_map(file)
|
||||
)
|
||||
|
||||
# Find the ifdef guard for 64-bit varint fields (int64/uint64/sint64).
|
||||
# Generated into api_pb2_defines.h so proto.h can include it, ensuring
|
||||
# consistent ProtoVarInt layout across all translation units.
|
||||
has_varint64, varint64_guard = get_varint64_ifdef(file, message_ifdef_map)
|
||||
|
||||
# Generate api_pb2_defines.h — included by proto.h to ensure all translation
|
||||
# units see USE_API_VARINT64 consistently (avoids ODR violations in ProtoVarInt).
|
||||
defines_content = FILE_HEADER
|
||||
defines_content += "#pragma once\n\n"
|
||||
defines_content += '#include "esphome/core/defines.h"\n'
|
||||
if has_varint64:
|
||||
lines = [
|
||||
"#ifndef USE_API_VARINT64",
|
||||
"#define USE_API_VARINT64",
|
||||
"#endif",
|
||||
]
|
||||
defines_content += "\n".join(wrap_with_ifdef(lines, varint64_guard))
|
||||
defines_content += "\n"
|
||||
defines_content += "\nnamespace esphome::api {} // namespace esphome::api\n"
|
||||
|
||||
with open(root / "api_pb2_defines.h", "w", encoding="utf-8") as f:
|
||||
f.write(defines_content)
|
||||
|
||||
content = FILE_HEADER
|
||||
content += """\
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/string_ref.h"
|
||||
|
||||
#include "proto.h"
|
||||
@@ -2702,11 +2760,6 @@ static void dump_bytes_field(DumpBuffer &out, const char *field_name, const uint
|
||||
|
||||
content += "namespace enums {\n\n"
|
||||
|
||||
# Build dynamic ifdef mappings for both enums and messages
|
||||
enum_ifdef_map, message_ifdef_map, message_source_map, used_messages = (
|
||||
build_type_usage_map(file)
|
||||
)
|
||||
|
||||
# Simple grouping of enums by ifdef
|
||||
current_ifdef = None
|
||||
|
||||
|
||||
@@ -841,6 +841,39 @@ def lint_no_scanf(fname, match):
|
||||
)
|
||||
|
||||
|
||||
LOG_MULTILINE_RE = re.compile(r"ESP_LOG\w+\s*\(.*?;", re.DOTALL)
|
||||
LOG_BAD_CONTINUATION_RE = re.compile(r'\\n(?:[^ \\"\r\n\t]|"\s*\n\s*"[^ \\])')
|
||||
LOG_PERCENT_S_CONTINUATION_RE = re.compile(r'\\n(?:%s|"\s*\n\s*"%s)')
|
||||
|
||||
|
||||
@lint_content_check(include=cpp_include)
|
||||
def lint_log_multiline_continuation(fname, content):
|
||||
errs = []
|
||||
for log_match in LOG_MULTILINE_RE.finditer(content):
|
||||
log_text = log_match.group(0)
|
||||
for bad_match in LOG_BAD_CONTINUATION_RE.finditer(log_text):
|
||||
# %s may expand to a whitespace prefix at runtime, skip those
|
||||
if LOG_PERCENT_S_CONTINUATION_RE.match(log_text, bad_match.start()):
|
||||
continue
|
||||
# Calculate line number from position in full content
|
||||
abs_pos = log_match.start() + bad_match.start()
|
||||
lineno = content.count("\n", 0, abs_pos) + 1
|
||||
col = abs_pos - content.rfind("\n", 0, abs_pos)
|
||||
errs.append(
|
||||
(
|
||||
lineno,
|
||||
col,
|
||||
"Multi-line log message has a continuation line that does "
|
||||
"not start with a space. The log viewer uses leading "
|
||||
"whitespace to detect continuation lines and re-add the "
|
||||
f"log tag prefix (e.g. {highlight('[C][component:042]:')}).\n"
|
||||
"Either start the continuation with a space/indent, or "
|
||||
"split into separate ESP_LOG* calls.",
|
||||
)
|
||||
)
|
||||
return errs
|
||||
|
||||
|
||||
@lint_content_find_check(
|
||||
"ESP_LOG",
|
||||
include=["*.h", "*.tcc"],
|
||||
|
||||
@@ -66,6 +66,7 @@ def create_test_config(config_name: str, includes: list[str]) -> dict:
|
||||
],
|
||||
"build_flags": [
|
||||
"-Og", # optimize for debug
|
||||
"-DUSE_TIME_TIMEZONE", # enable timezone code paths for testing
|
||||
],
|
||||
"debug_build_flags": [ # only for debug builds
|
||||
"-g3", # max debug info
|
||||
@@ -97,8 +98,12 @@ def run_tests(selected_components: list[str]) -> int:
|
||||
|
||||
components = sorted(components)
|
||||
|
||||
# Obtain possible dependencies for the requested components:
|
||||
components_with_dependencies = sorted(get_all_dependencies(set(components)))
|
||||
# Obtain possible dependencies for the requested components.
|
||||
# Always include 'time' because USE_TIME_TIMEZONE is defined as a build flag,
|
||||
# which causes core/time.h to include components/time/posix_tz.h.
|
||||
components_with_dependencies = sorted(
|
||||
get_all_dependencies(set(components) | {"time"})
|
||||
)
|
||||
|
||||
# Build a list of include folders, one folder per component containing tests.
|
||||
# A special replacement main.cpp is located in /tests/components/main.cpp
|
||||
|
||||
Reference in New Issue
Block a user