Skip to content

hal: Add halfileupdate to convert HAL configuration files - #4499

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:halfileupdate
Open

hal: Add halfileupdate to convert HAL configuration files#4499
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:halfileupdate

Conversation

@grandixximo

@grandixximo grandixximo commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@BsAtHome This is the .hal side of what we discussed in #4256, as a separate binary: halfileupdate.

It should be safe because it does not match strings. It reads the loadrt lines, works out which instances exist, and converts only names that resolve to one of those instances. count=, names= (the instance name is the user's, only the loadrt line changes) and components whose HAL prefix is not the module name, mux-gen and friends, all fall out of that instead of being special cases. Anything that does not resolve is left alone and reported.

Given an INI file it walks the [HAL] files in the order LinuxCNC runs them and follows source, which is the part that matters in practice: in stock configs the loadrt and the pins that use it are regularly in different files, sim_vmc.hal loads conv_float_s32 count=3 and toolchange_gray.hal uses conv-float-s32.2.in. It also picks up HAL files behind a GUI's own key such as CUSTOM_HALFILE, and rewrites HALCMD lines in the INI itself. On a single .hal file it converts what that file loads and says to run the INI for the rest.

Signals, aliases and comments are never rewritten, though a comment still naming something that changed is reported. Names built with a substitution or in a haltcl loop are reported rather than guessed at. Library files are skipped. Diff by default, -i keeps a .bak.

Per your last comment: no table in hal_lib, no hooks on the halcmd error paths, no CI mode. The renames are plain tables in the tool, taken from your wip_hal-types-and-isolation branch: the eleven conv_* converters, the mux_generic and demux_generic pins, demux sel-u32 and the reset pins. The four converters whose two sides collapse to one type, conv_s32_s64 and friends, are gone with no replacement there, so their uses are reported instead of rewritten. I left abs_s32, scaled_s32_sums and the tristate pair alone since you have not renamed them; if that changes the tables get regenerated.

I have not written a removal release into it, since 2.12 or 3.0 is not settled; it needs remembering at some point.

Testing: all 326 stock config INI files dry-run clean, 65 lines changed, no false positives. The test asserts that the old names are gone and that the replacements are consistent, not how they are spelled, so regenerating the tables will not invalidate it.

@grandixximo
grandixximo force-pushed the halfileupdate branch 2 times, most recently from a157f56 to d8e1890 Compare September 4, 2026 07:29
Removing the 32-bit HAL types renames components, pins and parameters
whose name spells a type that is gone (conv_s32_float -> conv_sint_real,
mux-gen.00.in-s32-00 -> mux-gen.00.in-sint-00), so a configuration using
those names fails to start.  halfileupdate rewrites them.

A name is rewritten only when it resolves to an instance of a component
that a loadrt in the files being read created, which covers count= and
names= instances and components whose HAL prefix is not the module name
without guessing; a name that does not resolve is left alone and
reported.  Given an INI file, the HAL files it names are converted in
the order LinuxCNC runs them, which is what makes a configuration
convertible: its loadrt and its pin uses are regularly in different
files.  Keys of a user interface's own and keys outside [HAL] count,
an INI value continued with a backslash is one command, and in haltcl
the Tcl form 'hal setp name value' is understood as well.  Signal names,
aliases, comments and names built with a substitution are never
rewritten.  By default a diff is printed and nothing is written;
--in-place rewrites atomically and keeps a .bak.

The renames are tables in the tool itself, following the 64-bit only
work: the eleven conv_* converters, the mux_generic and demux_generic
pins, demux sel-u32 and the reset pins.  They are regenerated if that
set changes.  No part of HAL knows the old names, and both the tool and
its tables are a migration aid for one release transition, not a
permanent part of HAL.  The test therefore checks that the old names are
gone and that what replaces them is consistent everywhere, not how any
one name is spelled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant