tcl: restore #INCLUDE handling in parse_ini to fix check_config.tcl after 2f57090#3938
Open
is-primary-dev wants to merge 1 commit intoLinuxCNC:masterfrom
Open
tcl: restore #INCLUDE handling in parse_ini to fix check_config.tcl after 2f57090#3938is-primary-dev wants to merge 1 commit intoLinuxCNC:masterfrom
is-primary-dev wants to merge 1 commit intoLinuxCNC:masterfrom
Conversation
Upstream commit 2f57090 ("ini: Implement a new ini-file parser and adapt the code to use it") added native #INCLUDE support to the new C++ parser in src/emc/ini/inifile.cc and removed the 53-line handle_includes() shell preprocessor from scripts/linuxcnc.in, because the new parser made the preprocessor redundant for the main launcher flow. However, lib/hallib/check_config.tcl uses the pure-Tcl parse_ini proc in tcl/linuxcnc.tcl, which has no #INCLUDE support. It relied on the shell preprocessor expanding the file before parse_ini ever saw it. Removing the preprocessor broke check_config.tcl for any INI file using #INCLUDE directives — including the shipped sim demo at configs/sim/axis/ini_with_includes/includes_demo.ini, which fails on current upstream master with: $ tclsh8.6 lib/hallib/check_config.tcl \ configs/sim/axis/ini_with_includes/includes_demo.ini check_config: Missing [KINS]KINEMATICS= Missing [KINS]JOINTS= check_config validation failed Extend parse_ini to recognize '#INCLUDE <filename>' lines and parse the referenced file recursively, resolving relative filenames against the including file's directory. This matches the semantics of inifile.cc's IniFileContent::parseLine() #INCLUDE handling. Errors during recursive parse (missing file, unreadable, etc.) are logged to stderr and the outer parse continues — matching the C parser's non-fatal behavior on bad includes so that mandatory-items checks can still see whatever was loaded up to the point of failure. The recursive call uses `uplevel 1` so the included file's sections land in the same scope as the top-level file's sections. For existing callers (check_config.tcl from file scope, twopass.tcl::tp::pass1 from a proc), this preserves the historical single-file upvar 1 semantics at every recursion depth — the recursive call runs as if it had been made directly from the original caller, so upvar 1 inside the recursive parse_ini walks back to the same frame as the top-level call. After this change, check_config.tcl accepts includes_demo.ini cleanly (the file has two intentional error-demo directives at the end which now surface as stderr warnings but no longer abort the check).
Contributor
|
The TCL ini-parser should be replaced and code should be rewritten in python to use the python ini-file interface that uses the new C++ ini-file parser. The TCL version has more problems like not performing proper string parsing and lacks type checks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Upstream commit 2f57090 ("ini: Implement a new ini-file parser and adapt the code to use it") added native
#INCLUDEsupport to the new C++ parser insrc/emc/ini/inifile.ccand removed the 53-linehandle_includes()shell preprocessor fromscripts/linuxcnc.in, because the new parser handles#INCLUDEnatively for the main launcher flow.However,
lib/hallib/check_config.tcl(called fromscripts/linuxcncduring startup to validate the INI) uses the pure-Tclparse_iniproc intcl/linuxcnc.tcl, which has no#INCLUDEsupport. It relied on the shell preprocessor expanding the file beforeparse_iniever saw it. After 2f57090, any INI file using#INCLUDEdirectives failscheck_config.tcl's mandatory-items pre-flight check.Observable symptom
On current upstream master, the shipped sim demo fails validation:
includes_demo.ini's master file has no[KINS]section — all sections come from.incfiles via#INCLUDEdirectives that the pure-Tcl parser ignores.Fix
Extend
parse_iniintcl/linuxcnc.tcl.into recognize#INCLUDE <filename>lines, resolve relative filenames against the including file's directory, and parse the referenced file recursively. Matches the semantics ofIniFileContent::parseLine()'s#INCLUDEhandling ininifile.cc. Errors during recursive parse (missing file, unreadable) are logged to stderr and the outer parse continues, matching the C parser's non-fatal behavior on bad includes.Also switches the section-variable
upvarfrom frame 1 (caller) to frame #0 (absolute global), so variables land in the global scope regardless of recursion depth. Behavior-preserving for existing callers (check_config.tcl,twopass.tcl::tp::pass1); only matters for the new recursive calls.Testing
Verified on upstream master with the same repro above — after the patch, the demo validates cleanly (only the two intentional error-demo directives at the end of
includes_demo.inisurface as stderr warnings, matching the#INCLUDE nosuchfileerror example the demo was designed to show).