Artifacts Associated With Ticket a998df01f3256f79
Ticket change [60644de46c] (rid 202338) by apnadkarni on 2022-07-04 17:08:12:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
If the `platform` package is required within a `pkgIndex.tcl` file for a package X, a circular dependency error is generated on `package require X`. The errors are: ``` error reading package index file d:/tcl/xx/p/pkgIndex.tcl: circular package dependency: attempt to provide platform 1.0.18 requires platform error reading package index file d:/tcl/xx/p/pkgIndex.tcl: circular package dependency: attempt to provide platform 1.0.18 requires platform error reading package index file d:/tcl/xx/p/pkgIndex.tcl: circular package dependency: attempt to provide platform 1.0.18 requires platform . . ``` This does not happen with 8.6. It also does not seem to happen if other packages are required within the `pkgIndex.tcl` e.g. the registry package or if the `platform` package is loaded beforehand. A sample testpkg is attached.
- foundin initialized to: "8.7"
- is_private initialized to: "0"
- login: "apnadkarni"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "apnadkarni"
- subsystem initialized to: "39. Package Manager"
- title initialized to:
Attempt to load platform package in a pkgIndex.tcl generates circular dependency error
- type initialized to: "Bug"
Add attachment "pkgIndex.tcl" [8e5a09675e] (rid 202340) by apnadkarni on 2022-07-04 17:08:49.
Add attachment "testpkg.tcl" [9438f87fad] (rid 202342) by apnadkarni on 2022-07-04 17:09:16.
Ticket change [829a8a54b0] (rid 202343) by apnadkarni on 2022-07-04 17:24:55:
- icomment:
The errorInfo from the above: ``` % set errorInfo circular package dependency: attempt to provide platform 1.0.18 requires platform while executing "package require platform" (file "d:/tcl/xx/p/pkgIndex.tcl" line 1) invoked from within "::source -nopkg d:/tcl/xx/p/pkgIndex.tcl" ("uplevel" body line 1) invoked from within "uplevel 1 [list ::source -nopkg $filename]" (procedure "::tcl::Pkg::source" line 5) invoked from within "::tcl::Pkg::source $file" ``` - login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [b815a1e33e] (rid 202344) by jan.nijtmans on 2022-07-04 19:09:05:
- assignee changed to: "jan.nijtmans"
- icomment:
Well - first - if 'testpkg' needs 'platform', `the correct` way to do this is as follows: <pre> ########## pkgIndex.tcl ######## package ifneeded testpkg 0.1 [list source [file join $dir testpkg.tcl]] ########## testpkg.tcl ######## package require platform; # <-- should be here, not in pkgIndex.tcl proc testproc {} {puts "testpkg loaded"} package provide testpkg 0.1 </pre> The pkgIndex system is complex. If a package is not found when doing a "package require", more file paths are searched for a 'pkgIndex' file. Therefore, a 'pkgIndex' file should only contain commands which have no side-effects, it should NEVER do another 'package require' directly or a 'load'. 'pkgIndex' files should hardly do anything more than 'package ifneeded'. The reason Tcl 8.7 discovers this and 8.6 doesn't is [https://core.tcl-lang.org/tips/doc/trunk/tip/459.md|TIP #459]. Tcl 8.7 keeps track, which files are sourced in which package initialization, so 'package files' can report it. Maybe the error-message could be better ..... Does this explanation make it a little bit more clear? - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Invalid"
- status changed to: "Pending"
Ticket change [0ced46e609] (rid 202345) by apnadkarni on 2022-07-05 02:37:51:
- icomment:
I understand why this is happening but that does not mean it's not a bug. * I don't think it is documented anywhere that pkgIndex.tcl cannot contain a package required or that it should not do a load. * In fact this has been working code for all releases up to this point. If 8.7 changes this, it is no longer 8.6 compatible in my view. * TIP 459 does not mention this additional *new* restriction on pkgIndex.tcl files at all. Given the above, I'm not sure why you say the *correct* way is to move it to testpkg.tcl. I would say it's a workaround for a bug! As to why not move it into the testpkg.tcl file, the reason is that there may not be a testpkg.tcl file at all, only a binary. The example I gave was just for illustration. The actual pkgIndex.tcl file would look something like this (pseudo-code, no existence checks etc) ``` package require platform package ifneeded testpkg 0.1 [list load [file join $dir [platform::identify] mybinaryextension.[info sharedlibextension]] ``` This permits a multi-platform install/distribution. You are now saying pkgIndex.tcl should not do a load either. Now in 8.7, an extra unnecessary .tcl file is needed where none was needed before. This is a step back but more important, binary extensions as above will no longer load in 8.7. Not just that, they actually break the package loading for all packages. Re-opening as I do not consider this as an invalid ticket or user error. /Ashok
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- resolution changed to: "None"
- status changed to: "Open"
- icomment:
Ticket change [6d60de932f] (rid 202346) by jan.nijtmans on 2022-07-05 06:20:39:
- icomment:
In stead of this: <pre> package require platform package ifneeded testpkg 0.1 [list load [file join $dir [platform::identify] mybinaryextension.[info sharedlibextension]] </pre> You should do: <pre> package require platform package ifneeded testpkg 0.1 "package require platform \ [list load [file join $dir [platform::identify] mybinaryextension.[info sharedlibextension]]" </pre> Then the "package require platform" is executed when testpkg is required. The problem with your approach is that the following could happen: <pre> $ tclsh8.7 $ package files platform; # empty result, since "platform" is not loaded yet $ package require Thread % package files platform; # "platform" is - unexpectedly - loaded now /usr/local/lib/tcl8/8.4/platform-1.0.18.tm </pre> (whether this happens or not depends on the order the "pkgIndex.tcl" files are found) So, a "package require Thread" results in pkgIndex.tcl files being sourced (in order to see where "Thread" is. This has a side-effect that the "platform" package is loaded, but it is not needed by "Thread" at all. It should be documented that a "pkgIndex.tcl" file should not contain another "package require" nor "package load", unless it's within a "package ifneeded". - login: "jan.nijtmans"
- mimetype: "text/x-markdown"
- resolution changed to: "Invalid"
- status changed to: "Pending"
- icomment:
Ticket change [ba96498830] (rid 202347) by jan.nijtmans on 2022-07-05 06:42:22:
- icomment:
Of course, a ';' is missing, and "platform::identity" should be delayed: <pre> package require platform package ifneeded testpkg 0.1 "package require platform; \ load \[file join [list $dir] \[platform::identify\] mybinaryextension.[info sharedlibextension]\]" </pre> I wouldn't use "platform::identify", since "platform::identify" contains the OS version as well: Do you really want separate directories for MacOS 10.4, up to 12.4? Maybe "platform::generic" is better. Or $tcl_platform(os) (but that wouldn't distingish processor) or $tcl_platform(os)/$tcl_platform(machine) - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [4b03914640] (rid 202348) by dkf on 2022-07-05 09:01:44:
- icomment:
I'd construct the <code>pkgIndex.tcl</code> like this: <pre> package ifneeded testpkg 0.1 [list apply {{dir} { package require platform set plat [platform::identify] set ext [info sharedlibextension] uplevel 1 [list load [file join $dir $plat mybinaryextension.$ext]] }} $dir] </pre> The <code>uplevel 1</code> wrapper is, of course, hyper-correctness that only a few C packages would ever need. You could probably get away with: <pre> package ifneeded testpkg 0.1 [list apply {{dir} { package require platform set plat [platform::identify] set ext [info sharedlibextension] load [file join $dir $plat mybinaryextension.$ext] }} $dir] </pre> As you can see, this gives you local variables and simple substitution rules without needing an extra command. (It's only a problem if you want to support 8.4 and before, but that's out of all support now...) - login: "dkf"
- mimetype: "text/html"
- icomment:
Ticket change [3a9dd0f117] (rid 202349) by jan.nijtmans on 2022-07-05 09:11:00:
- icomment:
> I'd construct the pkgIndex.tcl like this: Seconded
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [9aa33280e9] (rid 202350) by apnadkarni on 2022-07-05 09:43:27:
- icomment:
I'll close this with one last comment. I know the workarounds possible using apply etc. I already do this in some cases, see for example [https://github.com/apnadkarni/tcl-cffi/blob/main/pkgIndex.tcl.in](cffi). My beef is with the breaking of valid (as in nothing banned this) 8.6 pkgIndex.tcl scripts that took the simpler approach.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [0f445b253e] (rid 202351) by apnadkarni on 2022-07-05 09:43:39:
- closedate changed to: "2459765.90532347"
- closer changed to: "apnadkarni"
- login: "apnadkarni"
- mimetype: "text/plain"
- status changed to: "Closed"