Diff

Differences From Artifact [a3240f621e]:

To Artifact [fad62aecf7]:


     1      1   proc tclInit {} {
     2         -  rename tclInit {}
            2  +	rename tclInit {}
     3      3   
     4         -  global auto_path tcl_library tcl_libPath
     5         -  global tcl_version tcl_rcFileName
            4  +	global auto_path tcl_library tcl_libPath
            5  +	global tcl_version tcl_rcFileName
     6      6     
     7         -  set noe [info nameofexecutable]
            7  +	set noe [info nameofexecutable]
     8      8   
     9         -  # Resolve symlinks
    10         -  set noe [file dirname [file normalize [file join $noe __dummy__]]]
            9  +	# Resolve symlinks
           10  +	set noe [file dirname [file normalize [file join $noe __dummy__]]]
    11     11   
    12         -  set tcl_library [file join $noe lib tcl$tcl_version]
    13         -  set tcl_libPath [list $tcl_library [file join $noe lib]]
           12  +	set tcl_library [file join $noe lib tcl$tcl_version]
           13  +	set tcl_libPath [list $tcl_library [file join $noe lib]]
    14     14   
    15         -  # get rid of a build residue
    16         -  unset -nocomplain ::tclDefaultLibrary
           15  +	# get rid of a build residue
           16  +	unset -nocomplain ::tclDefaultLibrary
    17     17   
    18         -  # the following code only gets executed once on startup
    19         -  if {[info exists tcl_rcFileName]} {
    20         -    load {} vfs
           18  +	# the following code only gets executed once on startup
           19  +	if {[info exists tcl_rcFileName]} {
           20  +		# lookup and emulate "source" of lib/vfs/{vfs*.tcl,mk4vfs.tcl}
           21  +		switch -- $::tclKitStorage {
           22  +			"mk4" {
           23  +				load {} vfs
    21     24   
    22         -    # lookup and emulate "source" of lib/vfs/{vfs*.tcl,mk4vfs.tcl}
    23         -    # must use raw MetaKit calls because VFS is not yet in place
    24         -    set d [${::tclkitMkNamespace}::select exe.dirs parent 0 name lib]
    25         -    set d [${::tclkitMkNamespace}::select exe.dirs parent $d name vfs]
           25  +				# must use raw MetaKit calls because VFS is not yet in place
           26  +				set d [mk::select exe.dirs parent 0 name lib]
           27  +				set d [mk::select exe.dirs parent $d name vfs]
    26     28       
    27         -    foreach x {vfsUtils vfslib mk4vfs} {
    28         -      set n [${::tclkitMkNamespace}::select exe.dirs!$d.files name $x.tcl]
    29         -      set s [${::tclkitMkNamespace}::get exe.dirs!$d.files!$n contents]
    30         -      catch {set s [zlib decompress $s]}
    31         -      uplevel #0 $s
    32         -    }
           29  +				foreach x {vfsUtils vfslib mk4vfs} {
           30  +					set n [mk::select exe.dirs!$d.files name $x.tcl]
           31  +					set s [mk::get exe.dirs!$d.files!$n contents]
           32  +					catch {set s [zlib decompress $s]}
           33  +					uplevel #0 $s
           34  +				}
           35  +
           36  +				# use on-the-fly decompression, if mk4vfs understands that
           37  +				set mk4vfs::zstreamed 1
           38  +
           39  +				# Set VFS handler name
           40  +				set vfsHandler [list ::vfs::mk4::handler exe]
           41  +			}
           42  +			"zip" {
           43  +				set prefix "lib/vfs"
           44  +				foreach file [list vfsUtils vfslib] {
           45  +					set fullfile "${prefix}/${file}.tcl"
           46  +
           47  +					::zip::stat $::tclKitStorage_fd $fullfile finfo
           48  +					seek $::tclKitStorage_fd $finfo(ino)
           49  +					zip::Data $::tclKitStorage_fd sb s
           50  +
           51  +					switch -- $file {
           52  +						"vfsUtils" {
           53  +							# Preserve our working "::vfs::zip" implementation
           54  +							# so we can replace it after the stub is replaced
           55  +							# from vfsUtils
           56  +							# The correct implementation will be provided by vfslib, 
           57  +							# but only if we can read it
           58  +							rename ::vfs::zip ::vfs::zip_impl
           59  +						}
           60  +					}
           61  +
           62  +					uplevel #0 $s
           63  +
           64  +					switch -- $file {
           65  +						"vfsUtils" {
           66  +							# Restore preserved "::vfs:zip" implementation
           67  +							rename ::vfs::zip {}
           68  +							rename ::vfs::zip_impl ::vfs::zip
           69  +						}
           70  +					}
           71  +				}
           72  +
           73  +				seek $::tclKitStorage_fd 0
           74  +				set vfsHandler [list ::vfs::zip::handler $::tclKitStorage_fd]
           75  +				unset ::tclKitStorage_fd
           76  +			}
           77  +		}
           78  +
           79  +		# mount the executable, i.e. make all runtime files available
           80  +		vfs::filesystem mount $noe $vfsHandler
           81  +
           82  +		# alter path to find encodings
           83  +		if {[info tclversion] eq "8.4"} {
           84  +			load {} pwb
           85  +			librarypath [info library]
           86  +		} else {
           87  +			encoding dirs [list [file join [info library] encoding]] ;# TIP 258
           88  +		}
           89  +
           90  +		# fix system encoding, if it wasn't properly set up (200207.004 bug)
           91  +		if {[encoding system] eq "identity"} {
           92  +			switch $::tcl_platform(platform) {
           93  +				windows		{ encoding system cp1252 }
           94  +				macintosh	{ encoding system macRoman }
           95  +			        default		{ encoding system iso8859-1 }
           96  +			}
           97  +		}
           98  +
           99  +		# now remount the executable with the correct encoding
          100  +		vfs::filesystem unmount [lindex [::vfs::filesystem info] 0]
          101  +
          102  +		set noe [info nameofexecutable]
          103  +
          104  +		# Resolve symlinks
          105  +		set noe [file dirname [file normalize [file join $noe __dummy__]]]
    33    106   
    34         -    # use on-the-fly decompression, if mk4vfs understands that
    35         -    switch -- $::tclkitMkNamespace {
    36         -        "mk" {
    37         -            set mk4vfs::zstreamed 1
    38         -            set vfsimpl "mk4"
    39         -        }
    40         -        "readkit" {
    41         -            set mkcl_vfs::zstreamed 1
    42         -            set vfsimpl "mkcl"
    43         -        }
    44         -    }
          107  +		set tcl_library [file join $noe lib tcl$tcl_version]
          108  +		set tcl_libPath [list $tcl_library [file join $noe lib]]
    45    109   
    46         -    # mount the executable, i.e. make all runtime files available
    47         -    vfs::filesystem mount $noe [list ::vfs::${vfsimpl}::handler exe]
    48         -
    49         -    # alter path to find encodings
    50         -    if {[info tclversion] eq "8.4"} {
    51         -      load {} pwb
    52         -      librarypath [info library]
    53         -    } else {
    54         -      encoding dirs [list [file join [info library] encoding]] ;# TIP 258
    55         -    }
          110  +		vfs::filesystem mount $noe $vfsHandler
          111  +	}
          112  +  
          113  +	# load config settings file if present
          114  +	namespace eval ::vfs { variable tclkit_version 1 }
          115  +	catch { uplevel #0 [list source [file join $noe config.tcl]] }
    56    116   
    57         -    # fix system encoding, if it wasn't properly set up (200207.004 bug)
    58         -    if {[encoding system] eq "identity"} {
    59         -      switch $::tcl_platform(platform) {
    60         -        windows		{ encoding system cp1252 }
    61         -        macintosh	{ encoding system macRoman }
    62         -        default		{ encoding system iso8859-1 }
    63         -      }
    64         -    }
    65         -
    66         -    # now remount the executable with the correct encoding
    67         -    #vfs::filesystem unmount $noe
    68         -    vfs::filesystem unmount [lindex [::vfs::filesystem info] 0]
    69         -
    70         -    set noe [info nameofexecutable]
    71         -
    72         -  	# Resolve symlinks
    73         -  	set noe [file dirname [file normalize [file join $noe __dummy__]]]
    74         -
    75         -    set tcl_library [file join $noe lib tcl$tcl_version]
    76         -    set tcl_libPath [list $tcl_library [file join $noe lib]]
    77         -    vfs::filesystem mount $noe [list ::vfs::${vfsimpl}::handler exe]
    78         -  }
          117  +	uplevel #0 [list source [file join $tcl_library init.tcl]]
    79    118     
    80         -  # load config settings file if present
    81         -  namespace eval ::vfs { variable tclkit_version 1 }
    82         -  catch { uplevel #0 [list source [file join $noe config.tcl]] }
          119  +	# reset auto_path, so that init.tcl's search outside of tclkit is cancelled
          120  +	set auto_path $tcl_libPath
    83    121   
    84         -  uplevel #0 [list source [file join $tcl_library init.tcl]]
    85         -  
    86         -# reset auto_path, so that init.tcl's search outside of tclkit is cancelled
    87         -  set auto_path $tcl_libPath
          122  +	# This loads everything needed for "clock scan" to work
          123  +	# "clock scan" is used within "vfs::zip", which may be
          124  +	# loaded before this is run causing the root VFS to break
          125  +	catch { clock scan }
    88    126   
    89         -  unset ::tclkitMkNamespace
          127  +	# Cleanup
          128  +	unset ::tclKitStorage
          129  +	unset -nocomplain ::tclKitStorage_fd
    90    130   }