Tcl Source Code

View Ticket
Login
Ticket UUID: 209fd9adce08b582db292b4f1088bb57a8400d49
Title: package files documented behaviour
Type: Bug Created on: 2024-09-29 07:32:06
Submitter: juliannoble2 Assigned to: jan.nijtmans
Subsystem: - New Builtin Commands Severity: Minor
Priority: 5 Medium Last modified: 2024-09-30 11:59:13
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: tcl9
Description:
The documentation for 'package files <package>' states:

"Lists all files forming part of package. Auto-loaded files are not included in this list, only files which were directly sourced during package initialization. The list order corresponds with the order in which the files were sourced."

What exactly is meant by Auto-loaded files? Just those put in ::auto_index related to the package - or also those when Tcl has to scan module/library paths?

On a system with no accelerators such as critcl,cryptkit or trf - and also with additional entries in ::auto_path

    #llength [package require md5;package files md5]
    1181

(md5 package attempts to load the non-present accelerators - resulting in scanning the library paths)

It is returning all the pkgIndex.tcl paths from unrelated packages

I found this behaviour somewhat useful to determine when such scans are happening (as the performance impacts can be heavy) but I'd like to know if this is intentional or not - as the files are technically sourced - but the documentation could be read to infer it shouldn't return these.

People testing on one system where 'package files <pkg>' returns a small set of relevant results may be surprised to get huge listings on another system, so if the behaviour as is, is correct - I think the issue should be highlighted in the docs.
User Comments:
juliannoble2 added on 2024-09-29 07:34:02:
I'd also note that when this happens, the documentation statement: "Lists all files forming part of a package" becomes an inaccurate description.

jan.nijtmans added on 2024-09-30 09:20:34:

Thanks for the report!

This is - indeed - not intentional. I'll think of a way how to prevent that.


jan.nijtmans added on 2024-09-30 11:59:13:

Idea how to solve this: Currently, all "pkgIndex.tcl" files are added to the list at the moment they are sourced. Whenever a "package ifneeded" is executed, we store the name of the file being executed (which is the pkgIndex.tcl file) in the "package ifneeded" data.

Then, when the "package require" command ends and the package is actually sourced, we known the version number, so we can search for the correct pkgIndex.tcl file in the "package ifneeded" data, and add it to the list.