Skip to content

Commit 1b02fbc

Browse files
committed
hal: Add halfileupdate to convert HAL configuration files
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. An old name whose loadrt was converted already, from a file that another INI file shares, is converted too. 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, though the type word on a newsig line is converted, and a linkpp line is reported since halcmd no longer has the command. 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, abs_s32, abs_s64, scaled_s32_sums, the mux_generic and demux_generic pins, demux sel-u32, the histobins and histobinstream inputs 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.
1 parent dc1e724 commit 1b02fbc

16 files changed

Lines changed: 1253 additions & 1 deletion

File tree

‎debian/linuxcnc.install.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ usr/bin/hal_bridge
1919
usr/bin/hal_manualtoolchange
2020
usr/bin/halcmd
2121
usr/bin/halcmd_twopass
22+
usr/bin/halfileupdate
2223
usr/bin/halmeter
2324
usr/bin/halreport
2425
usr/bin/halrmt

‎debian/linuxcnc.manpages.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ usr/share/man/man1/gs2_vfd.1
1212
usr/share/man/man1/gscreen.1
1313
usr/share/man/man1/halcmd.1
1414
usr/share/man/man1/halcmd_twopass.1
15+
usr/share/man/man1/halfileupdate.1
1516
usr/share/man/man1/hal-histogram.1
1617
usr/share/man/man1/hal_input.1
1718
usr/share/man/man1/hal_manualtoolchange.1

‎docs/po4a.cfg‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
[type: AsciiDoc_def] src/man/man1/halcmd.1.adoc $lang:build/adoc/$lang/man/man1/halcmd.1.adoc
162162
[type: AsciiDoc_def] src/man/man1/halcmd_twopass.1.adoc $lang:build/adoc/$lang/man/man1/halcmd_twopass.1.adoc
163163
[type: AsciiDoc_def] src/man/man1/halcompile.1.adoc $lang:build/adoc/$lang/man/man1/halcompile.1.adoc
164+
[type: AsciiDoc_def] src/man/man1/halfileupdate.1.adoc $lang:build/adoc/$lang/man/man1/halfileupdate.1.adoc
164165
[type: AsciiDoc_def] src/man/man1/halmeter.1.adoc $lang:build/adoc/$lang/man/man1/halmeter.1.adoc
165166
[type: AsciiDoc_def] src/man/man1/halreport.1.adoc $lang:build/adoc/$lang/man/man1/halreport.1.adoc
166167
[type: AsciiDoc_def] src/man/man1/halrmt.1.adoc $lang:build/adoc/$lang/man/man1/halrmt.1.adoc
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
= halfileupdate(1)
2+
3+
== NAME
4+
5+
halfileupdate - Update HAL configuration files after component, pin and parameter renames
6+
7+
== SYNOPSIS
8+
9+
*halfileupdate* [--in-place] [--no-backup] [--quiet] _file.hal_|_file.ini_...
10+
11+
== DESCRIPTION
12+
13+
Removing the 32-bit HAL types renames the components, pins and
14+
parameters whose name spells a type that no longer exists, for example
15+
*conv_s32_float* becomes *conv_sint_real* and *mux-gen.00.in-s32-00*
16+
becomes *mux-gen.00.in-sint-00*. A configuration using the old names
17+
fails to start. *halfileupdate* rewrites those names in HAL files,
18+
both *.hal* and haltcl *.tcl*.
19+
20+
Run it on the INI file of the configuration:
21+
22+
----
23+
halfileupdate mymachine.ini
24+
----
25+
26+
This prints a diff of what would change and writes nothing. Every HAL
27+
file the INI names is read, in the order LinuxCNC runs them, which is
28+
what makes the names resolvable: a *loadrt* in one file and the pins it
29+
creates in another is normal in a configuration, and the INI file is
30+
what ties the two together. Files named by a key of a user interface's
31+
own, such as *CUSTOM_HALFILE*, and keys outside the *[HAL]* section are
32+
picked up as well. Add *--in-place* to make the changes,
33+
keeping a *.bak* of every file it touches:
34+
35+
----
36+
halfileupdate -i mymachine.ini
37+
----
38+
39+
A single HAL file can be converted on its own, but then only the
40+
components that file loads itself can be converted; anything else is
41+
reported, with a message saying to run the INI file instead.
42+
43+
Signal names are never changed: they are yours, and no rename applies
44+
to them, though the type word on a *newsig* line is converted, since the
45+
type names changed with everything else. A *net* line keeps its signal and gets new pin names.
46+
Instance names you chose with *names=* are kept as well; only the
47+
component name on the *loadrt* line changes.
48+
49+
== WHAT YOU HAVE TO DO BY HAND
50+
51+
*halfileupdate* converts the names it can resolve and reports the rest
52+
with the file and the line, so what is left is on screen when it
53+
finishes. It does not touch:
54+
55+
* Names that are not spelled out in the file, such as a haltcl name
56+
built in a loop or a procedure (*abs-s32.$i.gain*), or a name built
57+
from an INI variable.
58+
* Comments. A comment that still names something that changed is
59+
reported.
60+
* Pin names outside HAL files: the Python *hal* module, custom user
61+
interfaces, pyvcp and qtvcp panels, and halui bindings in other
62+
sections of the INI file.
63+
64+
HAL files that come with LinuxCNC, whether written *LIB:name.tcl* or
65+
found in the HAL library, are updated with LinuxCNC and are left alone.
66+
67+
Review the diff and test the configuration before running a machine
68+
with it.
69+
70+
== OPTIONS
71+
72+
_file.hal_|_file.ini_...::
73+
The files to convert. An INI file pulls in the HAL files it names,
74+
including those behind a *HALCMD* line; a HAL file is converted on its
75+
own. In a haltcl file the Tcl form *hal setp name value* is understood
76+
as well as the plain *setp name value*.
77+
78+
*-i*, *--in-place*::
79+
Rewrite the files in place. A backup with the suffix *.bak* is kept
80+
unless *--no-backup* is given.
81+
82+
*--no-backup*::
83+
With *--in-place*, do not keep a *.bak* backup.
84+
85+
*-q*, *--quiet*::
86+
Suppress warnings and notes on stderr.
87+
88+
== EXIT STATUS
89+
90+
0 on success, 2 when a file given on the command line could not be
91+
read. Names left for you to convert do not change the exit status.
92+
93+
== SEE ALSO
94+
95+
*halcmd*(1), *halcompile*(1), *halcompupdate*(1), *haltcl*(1)

‎src/hal/utils/Submakefile‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ endif
105105
$(ECHO) Copying python script $(notdir $@)
106106
$(Q)(echo '#!$(PYTHON)'; sed '1 { /^#!/d; }' $<) > $@.tmp && chmod +x $@.tmp && mv -f $@.tmp $@
107107

108+
../bin/halfileupdate: ../bin/%: hal/utils/%.py
109+
@$(ECHO) Syntax checking python script $(notdir $@)
110+
$(Q)$(PYTHON) -m py_compile $<
111+
$(ECHO) Copying python script $(notdir $@)
112+
$(Q)(echo '#!$(PYTHON)'; sed '1 { /^#!/d; }' $<) > $@.tmp && chmod +x $@.tmp && mv -f $@.tmp $@
113+
108114
../bin/elbpcom: ../bin/%: hal/utils/%.py
109115
@$(ECHO) Syntax checking python script $(notdir $@)
110116
$(Q)$(PYTHON) -m py_compile $<
@@ -117,7 +123,7 @@ endif
117123
$(ECHO) Copying python script $(notdir $@)
118124
$(Q)(echo '#!$(PYTHON)'; sed '1 { /^#!/d; }' $<) > $@.tmp && chmod +x $@.tmp && mv -f $@.tmp $@
119125

120-
TARGETS += ../bin/halcompile ../bin/elbpcom ../bin/mesambccc
126+
TARGETS += ../bin/halcompile ../bin/halfileupdate ../bin/elbpcom ../bin/mesambccc
121127
objects/%.py: %.g
122128
@mkdir -p $(dir $@)
123129
$(Q)$(YAPPS) $< $@

0 commit comments

Comments
 (0)