hal: Add halcompupdate to migrate .comp files to the new HAL API#4256
hal: Add halcompupdate to migrate .comp files to the new HAL API#4256grandixximo wants to merge 1 commit into
Conversation
3a9267a to
5865295
Compare
|
@BsAtHome If this is too ugly I'll drop it, this does most of your careful hand conversion, to alleviate the porting churn for comps out of tree, let me know how much you hate it ;-) |
|
The old hal types should never be used anywhere anymore. All places I've see they were used wrongly as variable types and that fails the smell-test miserably because they are volatile. For components (.comp files), that only declare their pins and params through halcompile means, will not see a difference (except for the _set() suffix for writing). However, those constructs that add their own pins/params need more care in the conversion. |
Out-of-tree .comp components using the legacy HAL types (float, bit, s32, u32, s64, u64, signed, unsigned) and direct pin/param assignment stop working when the HAL API break is performed (LinuxCNC#4099, LinuxCNC#4247). halcompupdate rewrites them to the new API automatically: * declaration types are converted: float->real, bit->bool, s32->si32, u32->ui32, s64->sint, u64->uint, signed->si32, unsigned->ui32 ('port' is left alone, it has no new-style replacement yet) * writes to out/io pins and to params become <name>_set(...) calls, including compound assignments, ++/--, array pins, chained assignments, *<name>_ptr dereferences and writes inside #define macros (macro parameters shadow same-named pins) * legacy C types are modernized (double/real_t -> rtapi_real, hal_bit_t -> volatile rtapi_bool, ...) * reads are unchanged and pins are never renamed, so existing HAL configurations keep working Constructs that cannot be converted safely are left unchanged with a warning for manual conversion: taking the address of a pin/param, direct use of the legacy hal_pin_*_new/hal_param_*_new creation API, postfix ++/-- whose value is used, and array indices with side effects. In-place rewriting is atomic (temp file + rename) and keeps a .bak backup created with O_EXCL|O_NOFOLLOW. halcompile now warns once per deprecated type, pointing to halcompupdate(1), at the spot previously marked for this warning. Docs: migration section in comp.adoc, new halcompupdate(1) manpage, SEE ALSO in halcompile(1). Regression test in tests/halcompile/update-api. Validated by converting all in-tree components from master: 119/124 compile (the other 5 need in-tree headers and fail identically for the already-converted versions), and the output matches the hand conversions in LinuxCNC#4247 functionally.
5865295 to
937f5be
Compare
|
Thanks for the review. Aligned the C-type conversion with that:
|
|
FWIW, I don't think we should even attempt to fix the component files automatically. The only risk-free change is to fixup pins/params to use the new types. Everything else is intrinsically a huge risk in an auto conversion that needs to consider the context it is used in. That is not something you can do automatically. You could do considerable damage. IMO, the risks outweigh the benefits. |
Partially I agree, but I don't like what the lack of an attempt says...
The tool is strictly opt-in. It does not pop up and ask you to convert like the INI converter does, and doesn't convert automatically on build, it sits there until someone runs it, and its default mode only prints a diff for review.
Types and writes are inseparable. Converting The tool already stays inside the risk-free zone you describe, it converts only the mechanical subset (type renames and direct writes. The writable namespace is exactly the declared pins/params, no aliasing, no pointers beyond |
Problem
With the new HAL types and getter/setter API (#4099, with the in-tree conversion in #4247), out-of-tree
.compcomponents that use the legacy declaration types (float,bit,s32,u32,s64,u64,signed,unsigned) and direct pin/param assignment will stop building when the API break is performed. The HAL shared memory version has already changed, so out-of-tree components must be recompiled regardless. This is the right moment to offer a painless, automatic migration path.Solution
A new tool,
halcompupdate, rewrites legacy.compfiles to the new API automatically:float->real,bit->bool,s32->si32,u32->ui32,s64->sint,u64->uint,signed->si32,unsigned->ui32(portis left alone, no new-style replacement yet)x = e->x_set(e),x += e->x_set(x + (e)),x++->x_set(x + 1), arraysx(i) = e->x_set(i, e), chaineda = b = e->a_set(b_set(e)),*x_ptr = e->x_set(e),*x_ptrreads ->(x)#definemacrosdouble/real_t->rtapi_real,hal_bit_t->rtapi_bool, etc. (thevolatilequalifier of the legacy types is dropped on purpose, it existed for direct HAL memory access and was never right for variables;--no-c-typesto skip)name(idx)) works in both APIsPin and parameter names are never renamed, because they are part of the HAL configuration interface. Existing
.halfiles keep working.Usage:
Where it hooks in
halcompilenow emits a deprecation warning once per legacy type used, pointing athalcompupdate(1). It is placed exactly at the spothalcompile.greserved for it ("when we start warning ... this is where the warning goes"). Users hit the warning at compile time and get the remedy in the same message. The now-supersededdeprmap/deprecatedplaceholders are removed. Until the in-tree conversion lands, a build emits one warning per legacy type per component, which is the intended transition signal.Safety
os.replace(), original mode preserved). Backups are created withO_EXCL|O_NOFOLLOWand a unique-name fallback, so a pre-existing.bak(or a planted symlink) is never clobbered.&x), direct use of the legacyhal_pin_*_new/hal_param_*_newcreation API, postfix++/--whose value is used (the setter yields the new value, postfix must yield the old), and array indices with side effects.Validation
halcompile: 119 compile cleanly. The other 5 (spindle,raster,mesa_pktgyro_test,homecomp,tpcomp) reference in-tree-only headers/skeletons and fail identically for the already-converted versions when built out-of-tree."32 bool integer"in reset.comp) which the tool preserves correctly.tests/halcompile/update-api.scripts/runtests tests/halcompilegives 10/10 pass.Docs
Migration section in
docs/src/hal/comp.adoc(new-type table and_set()accessor documentation), newhalcompupdate(1)manpage, and a SEE ALSO link inhalcompile(1).Dependencies
None beyond #4099 (already merged). Fully parallel to #4247: this PR provides the migration tool, the deprecation warning, and the docs, while #4247 converts the in-tree components. The two branches merge cleanly in either order (verified with
git merge-tree --write-tree).