Skip to content

Commit ed6ded5

Browse files
committed
feat(esp_commands): Sort static commands for all targets
1 parent 753705b commit ed6ded5

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

esp_commands/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
idf_build_get_property(idf_target IDF_TARGET)
22

3-
set(srcs "esp_commands.c"
4-
"esp_dynamic_commands.c"
5-
"esp_commands_helpers.c")
3+
set(srcs "src/esp_commands.c"
4+
"src/esp_dynamic_commands.c"
5+
"src/esp_commands_helpers.c")
66

77
idf_component_register(
88
SRCS ${srcs}
99
INCLUDE_DIRS include
1010
PRIV_INCLUDE_DIRS private_include
1111
LDFRAGMENTS linker.lf
12-
)
12+
WHOLE_ARCHIVE)
1313

1414
if(${idf_target} STREQUAL "linux")
1515
# Add custom ld file

esp_commands/include/esp_commands.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
#include "esp_heap_caps.h"
1414
#include "esp_err.h"
1515

16-
#define ESP_COMMAND_STRINGIFY(name) #name
16+
#define _STRINGIFY(name) #name
1717

1818
/**
1919
* @brief Function pointer type for writing bytes.
@@ -187,21 +187,24 @@ esp_err_t esp_commands_update_config(const esp_commands_config_t *config);
187187
* @brief macro registering a command and placing it in a specific section of flash.rodata
188188
* @note see the linker.lf file for more information concerning the section characteristics
189189
*/
190-
#define ESP_COMMAND_REGISTER(cmd_name, cmd_group, cmd_help, cmd_func, cmd_func_ctx, cmd_hint_cb, cmd_glossary_cb) \
190+
#define _ESP_REPL_STRINGIFY(x) #x
191+
#define ESP_REPL_STRINGIFY(x) _ESP_REPL_STRINGIFY(x)
192+
193+
#define _ESP_COMMAND_REGISTER(cmd_name, cmd_group, cmd_help, cmd_func, cmd_func_ctx, cmd_hint_cb, cmd_glossary_cb) \
191194
static_assert((cmd_func) != NULL); \
192-
/* Alignment attribute is required when building on linux target to prevent each input section */ \
193-
/* from inheriting its alignment from the object's file default one thus preventing gaps between */ \
194-
/* commands in the section. */ \
195-
static const esp_command_t cmd_name __attribute__((used, section(".esp_commands" "." ESP_COMMAND_STRINGIFY(cmd_name)), aligned(4))) = { \
196-
.name = #cmd_name, \
197-
.group = #cmd_group, \
195+
static const esp_command_t cmd_name __attribute__((used, section(".esp_commands" "." _ESP_REPL_STRINGIFY(cmd_name)), aligned(4))) = { \
196+
.name = _ESP_REPL_STRINGIFY(cmd_name), \
197+
.group = _ESP_REPL_STRINGIFY(cmd_group), \
198198
.help = cmd_help, \
199199
.func = cmd_func, \
200200
.func_ctx = cmd_func_ctx, \
201201
.hint_cb = cmd_hint_cb, \
202202
.glossary_cb = cmd_glossary_cb \
203203
};
204204

205+
#define ESP_COMMAND_REGISTER(cmd_name, cmd_group, cmd_help, cmd_func, cmd_func_ctx, cmd_hint_cb, cmd_glossary_cb) \
206+
_ESP_COMMAND_REGISTER(cmd_name, cmd_group, cmd_help, cmd_func, cmd_func_ctx, cmd_hint_cb, cmd_glossary_cb)
207+
205208
/**
206209
* @brief Register a command
207210
*

esp_commands/linker.lf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[sections:esp_commands]
22
entries:
3-
.esp_command+
3+
.esp_commands+
44

55
[scheme:esp_commands_default]
66
entries:
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,26 +536,26 @@ static void print_arg_help(esp_commands_exec_arg_t *cmd_args, esp_command_t *it)
536536
/* First line: command name and hint
537537
* Pad all the hints to the same column
538538
*/
539-
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, "%-s", it->name);
539+
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, "%s", it->name);
540540

541541
const char *hint = NULL;
542542
if (it->hint_cb) {
543543
hint = it->hint_cb(it->func_ctx);
544544
}
545545

546546
if (hint) {
547-
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, "%s\n", it->hint_cb(it->func_ctx));
547+
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " %s\n", it->hint_cb(it->func_ctx));
548548
} else {
549-
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, "\n");
549+
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " -\n");
550550
}
551551

552552
/* Second line: print help */
553553
/* TODO: replace the simple print with a function that
554554
* replaces arg_print_formatted */
555555
if (it->help) {
556-
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " %s\n", it->help);
556+
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " %s\n", it->help);
557557
} else {
558-
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " -\n");
558+
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " -\n");
559559
}
560560

561561
/* Third line: print the glossary*/
@@ -567,7 +567,7 @@ static void print_arg_help(esp_commands_exec_arg_t *cmd_args, esp_command_t *it)
567567
if (glossary) {
568568
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " %s\n", it->glossary_cb(it->func_ctx));
569569
} else {
570-
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " -\n");
570+
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, " -\n");
571571
}
572572

573573
FDPRINTF(cmd_args->out_fd, cmd_args->write_func, "\n");

0 commit comments

Comments
 (0)