mirror of
https://github.com/esphome/esphome.git
synced 2026-09-23 04:58:38 +00:00
Merge branch 'dev' into lint-no-powf-core
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.
|
||||
|
||||
@@ -2442,9 +2473,6 @@ def build_base_class(
|
||||
out = f"class {base_class_name} : public {parent_class} {{\n"
|
||||
out += " public:\n"
|
||||
|
||||
# Add destructor with override
|
||||
public_content.insert(0, f"~{base_class_name}() override = default;")
|
||||
|
||||
# Base classes don't implement encode/decode/calculate_size
|
||||
# Derived classes handle these with their specific field numbers
|
||||
cpp = ""
|
||||
@@ -2452,6 +2480,8 @@ def build_base_class(
|
||||
out += indent("\n".join(public_content)) + "\n"
|
||||
out += "\n"
|
||||
out += " protected:\n"
|
||||
# Non-virtual protected destructor prevents accidental polymorphic deletion
|
||||
protected_content.insert(0, f"~{base_class_name}() = default;")
|
||||
out += indent("\n".join(protected_content))
|
||||
if protected_content:
|
||||
out += "\n"
|
||||
@@ -2567,11 +2597,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 +2759,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
|
||||
|
||||
|
||||
+1
-1
@@ -1007,7 +1007,7 @@ def main():
|
||||
continue
|
||||
run_checks(LINT_CONTENT_CHECKS, fname, fname, content)
|
||||
|
||||
run_checks(LINT_POST_CHECKS, "POST")
|
||||
run_checks(LINT_POST_CHECKS, Path("POST"))
|
||||
|
||||
for f, errs in sorted(errors.items()):
|
||||
bold = functools.partial(styled, colorama.Style.BRIGHT)
|
||||
|
||||
@@ -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