Repository navigation
Generate through xr-syntax 0.3.0; add User Code regions to LibXR.CMake - #34
Conversation
libxr.cpp_layout is gone: the layout of the generated C++ comes from xr_syntax.format. That module holds the line-breaking rules of both generators, each behind its own entry point and on shared primitives; the three code generators call layout_statement instead of their own line breaker. Pin xr-syntax 0.3.0.
app_main.cpp, app_main.h and flash_map.hpp are built through the shared file builder, which parses the whole file once at the build boundary; app_main.h and flash_map.hpp hold no user code, so they require a clean parse. HPM and MSPM0 assemble app_main.cpp through the same helper as STM32. The generated output is unchanged: the clang-format format tests and the generator tests pass.
libxr.cmake_text is gone: LibXR.CMake is read and written with CMakeDocument and CMakeFileBuilder, so the block structure, the User Code regions and the settings are found by the CMake lexer instead of by regular expressions over whole lines. The settings keep the user's writing: LIBXR_SYSTEM is written into the existing line, LIBXR_DRIVER and the optimization levels are added after the line they belong to, and XROBOT_MODULES_DIR follows the entry source and is removed together with the line it is on. Both branches check the text they are about to write with the very same checks the next read applies, so a file the generator would refuse is never written, and the notice names the two User Code regions that a user may edit.
|
| document = document.replace_statement( | ||
| _statement_of(document, view), f"set(LIBXR_SYSTEM {system})\n" | ||
| ) |
There was a problem hiding this comment.
User-written blocks get deleted
When a valueless set(LIBXR_SYSTEM) sits inside an if, foreach, or function, _statement_of returns the entire enclosing block. This replacement deletes that block and every other command inside it. For example, a block containing set(LIBXR_SYSTEM ) and set(KEEP 1) becomes just set(LIBXR_SYSTEM None) on regeneration.
Update only the selected command, and add a test that preserves its surrounding block.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/libxr/generator_stm32_cmake.py
Line: 422-424
Comment:
**User-written blocks get deleted**
When a valueless `set(LIBXR_SYSTEM)` sits inside an `if`, `foreach`, or function, `_statement_of` returns the entire enclosing block. This replacement deletes that block and every other command inside it. For example, a block containing `set(LIBXR_SYSTEM )` and `set(KEEP 1)` becomes just `set(LIBXR_SYSTEM None)` on regeneration.
Update only the selected command, and add a test that preserves its surrounding block.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| self.assertEqual( | ||
| written, | ||
| commented.replace("set(LIBXR_DRIVER st) # driver", "set(LIBXR_DRIVER st) # driver"), | ||
| ) |
There was a problem hiding this comment.
Value-edit test changes no value
test_a_value_is_replaced_without_touching_the_rest_of_the_line adds a comment to LIBXR_DRIVER, then compares the result with an identical string. It never checks the new _set_system value edit, so it can pass even if that edit removes comments or changes spacing.
Use a different LIBXR_SYSTEM value with a trailing comment, then assert that regeneration changes the value while preserving the comment and spacing.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/test_generator_stm32_cmake.py
Line: 1053-1056
Comment:
**Value-edit test changes no value**
`test_a_value_is_replaced_without_touching_the_rest_of_the_line` adds a comment to `LIBXR_DRIVER`, then compares the result with an identical string. It never checks the new `_set_system` value edit, so it can pass even if that edit removes comments or changes spacing.
Use a different `LIBXR_SYSTEM` value with a trailing comment, then assert that regeneration changes the value while preserving the comment and spacing.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
The generator uses xr-syntax 0.3.0 for its C++ layout, for assembling generated files and for reading and writing
cmake/LibXR.CMake.cpp_layout.pyandcmake_text.pyare gone, along with every regular expression that parsed CMake.Changes
xr_syntax.format.layout_statement.app_main.cpp,app_main.handflash_map.hppare assembled byCppFileBuilder.LibXR.CMakeis read and written through the CMake frontend.Generated output
Generated files are byte-identical to libxr 6.0.1 on bsp-dev-c (default and sentry configs), bsp-dev-mc02 and bsp_stm32f103. The one exception is
cmake/LibXR.CMake, which changes as described below.cmake/LibXR.CMakegets two User Code regions, kept on regeneration:CompileOptions, beforeadd_subdirectory(LibXR), for options such asLIBXR_SHARED_BUILD;ApplicationSettings, at the end of the file.The first line now mentions the two regions. A file with the earlier first line is still taken as the current format.
Before writing, the result goes through the same check as the next read. When an existing file has parse errors or malformed, duplicate or unknown User Code markers, the row and column are reported and nothing is written.
Settings are now edited by CMake syntax instead of regular expressions. Most differences fix wrong output from 6.0.1:
SETin upper case no longer gets a second line;setno longer leaves a broken last line;Every difference is listed with its input, old output and new output in the work report and goes into the 6.0.2 release notes.
Downgrade: libxr 6.0.1 reads a file written by this version as an earlier format and migrates it again, which duplicates sections. BSPs pin the generator version in
libxr_config.yaml.Requires xr-syntax 0.3.0 on PyPI (xrobot-org/xr-syntax#3), so CI installs only after that release. All tests pass locally on Windows with Python 3.13 (628 passed).