From 0bc645ded7f73715dfc85b325c79310015d493dd Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Sun, 10 Mar 2024 14:08:58 +1100 Subject: [PATCH] Fix build failures on host platform caused by #6167 (#6338) * Fix build failures for logger component on host platform * Add climits header * Restore logger functionality on host * Install libsodium in ci --- .github/workflows/ci.yml | 3 +++ esphome/components/debug/debug_component.cpp | 3 +++ esphome/components/logger/__init__.py | 2 ++ esphome/components/logger/logger.cpp | 2 ++ esphome/components/logger/logger.h | 2 ++ esphome/components/logger/logger_host.cpp | 2 ++ tests/components/debug/test.host.yaml | 1 + .../build_components_base.host.yaml | 18 ++++++++++++++++++ 8 files changed, 33 insertions(+) create mode 100644 tests/components/debug/test.host.yaml create mode 100644 tests/test_build_components/build_components_base.host.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b4aafb1dc..1794aeee89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -433,6 +433,9 @@ jobs: matrix: file: ${{ fromJson(needs.list-components.outputs.matrix) }} steps: + - name: Install libsodium + run: sudo apt-get install libsodium-dev + - name: Check out code from GitHub uses: actions/checkout@v4.1.1 - name: Restore Python diff --git a/esphome/components/debug/debug_component.cpp b/esphome/components/debug/debug_component.cpp index fe66220ead..f22a8a2e5d 100644 --- a/esphome/components/debug/debug_component.cpp +++ b/esphome/components/debug/debug_component.cpp @@ -6,6 +6,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/version.h" #include +#include #ifdef USE_ESP32 @@ -49,6 +50,8 @@ static uint32_t get_free_heap() { return rp2040.getFreeHeap(); #elif defined(USE_LIBRETINY) return lt_heap_get_free(); +#elif defined(USE_HOST) + return INT_MAX; #endif } diff --git a/esphome/components/logger/__init__.py b/esphome/components/logger/__init__.py index fe887a392f..c05f3d54aa 100644 --- a/esphome/components/logger/__init__.py +++ b/esphome/components/logger/__init__.py @@ -144,6 +144,8 @@ def uart_selection(value): component = get_libretiny_component() if component in UART_SELECTION_LIBRETINY: return cv.one_of(*UART_SELECTION_LIBRETINY[component], upper=True)(value) + if CORE.is_host: + raise cv.Invalid("Uart selection not valid for host platform") raise NotImplementedError diff --git a/esphome/components/logger/logger.cpp b/esphome/components/logger/logger.cpp index a109368ea9..740b12adc1 100644 --- a/esphome/components/logger/logger.cpp +++ b/esphome/components/logger/logger.cpp @@ -146,8 +146,10 @@ const char *const LOG_LEVELS[] = {"NONE", "ERROR", "WARN", "INFO", "CONFIG", "DE void Logger::dump_config() { ESP_LOGCONFIG(TAG, "Logger:"); ESP_LOGCONFIG(TAG, " Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]); +#ifndef USE_HOST ESP_LOGCONFIG(TAG, " Log Baud Rate: %" PRIu32, this->baud_rate_); ESP_LOGCONFIG(TAG, " Hardware UART: %s", get_uart_selection_()); +#endif for (auto &it : this->log_levels_) { ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.tag.c_str(), LOG_LEVELS[it.level]); diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index d70e895985..9aabe88963 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -137,7 +137,9 @@ class Logger : public Component { va_end(arg); } +#ifndef USE_HOST const char *get_uart_selection_(); +#endif uint32_t baud_rate_; char *tx_buffer_{nullptr}; diff --git a/esphome/components/logger/logger_host.cpp b/esphome/components/logger/logger_host.cpp index 88c13bba7b..edffb1a8c3 100644 --- a/esphome/components/logger/logger_host.cpp +++ b/esphome/components/logger/logger_host.cpp @@ -16,6 +16,8 @@ void HOT Logger::write_msg_(const char *msg) { puts(msg); } +void Logger::pre_setup() { global_logger = this; } + } // namespace logger } // namespace esphome diff --git a/tests/components/debug/test.host.yaml b/tests/components/debug/test.host.yaml new file mode 100644 index 0000000000..5845beaa80 --- /dev/null +++ b/tests/components/debug/test.host.yaml @@ -0,0 +1 @@ +debug: diff --git a/tests/test_build_components/build_components_base.host.yaml b/tests/test_build_components/build_components_base.host.yaml new file mode 100644 index 0000000000..00b252da2d --- /dev/null +++ b/tests/test_build_components/build_components_base.host.yaml @@ -0,0 +1,18 @@ +esphome: + name: componenttesthost + friendly_name: $component_name + +host: + mac_address: "62:23:45:AF:B3:DD" + +logger: + level: VERY_VERBOSE + +packages: + component_under_test: !include + file: $component_test_file + vars: + component_name: $component_name + test_name: $test_name + target_platform: $target_platform + component_test_file: $component_test_file